# Getting started x402 V1

Here is a [sample code](https://github.com/mogami-tech/x402-examples/blob/1.1.2/src/test/java/tech/mogami/spring/example/IntegrationTest.java#L31) showing how to make a payment:

```java
// 1️⃣  Issue the initial request. The server responds with HTTP 402 + JSON body.
MvcResult result = mockMvc.perform(get("/weather"))
        .andExpect(status().isPaymentRequired())
        .andReturn();

// 1️⃣  Parse the JSON body into a PaymentRequired object.
var paymentRequired = X402PaymentHelper.getPaymentRequiredFromBody(
        result.getResponse().getContentAsString())
    .orElseThrow(() -> new IllegalStateException("Payment requirements not found"));

// 2️⃣  Create an *unsigned* PaymentPayload from the first accepted option.
var unsignedPayload = X402PaymentHelper.getPayloadFromPaymentRequirements(
        null,                               // signature will be added later
        TEST_CLIENT_WALLET_ADDRESS_1,       // payer's EOA address (0x…)
        paymentRequired.accepts().getFirst());

// 3️⃣  Sign the payload with the private key (EIP‑712 compliant).
var signedPayload = X402PaymentHelper.getSignedPayload(
        Credentials.create(TEST_CLIENT_WALLET_ADDRESS_1_PRIVATE_KEY),
        paymentRequired.accepts().getFirst(),
        unsignedPayload);

// 4️⃣  Encode the signed payload → Base64 → X‑Payment header & retry.
mockMvc.perform(get("/weather")
                .header(X402_X_PAYMENT_HEADER,
                        X402PaymentHelper.getPayloadHeader(signedPayload)))
       .andExpect(status().isOk());
```

To use our Java client SDK in your Maven project, add:

<pre class="language-xml"><code class="lang-xml"><strong>&#x3C;dependency>
</strong>        &#x3C;groupId>tech.mogami.spring&#x3C;/groupId>
        &#x3C;artifactId>mogami-x402-java-client&#x3C;/artifactId>
        &#x3C;version>1.1.2&#x3C;/version>
&#x3C;/dependency>
</code></pre>

or, in your Gradle project, add:

```groovy
dependencies {
    implementation 'tech.mogami.spring:mogami-x402-java-client:1.1.2'
}
```
