# 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'
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mogami.gitbook.io/mogami/java-client-sdk/getting-started-x402-v1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
