> ## Documentation Index
> Fetch the complete documentation index at: https://ifdocdemo.lumivescence.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Test a payment

> Confirm the 402 challenge, then pay your own sandbox endpoint with the CLI or with a buyer example.

Test the whole payment path of Step 1, Payments, in the sandbox. Then continue to Step 2. The examples use `http://localhost:3000/api/widgets` as the protected endpoint.

## Step 1: Confirm the challenge

Start your server. Call the paid endpoint without a payment.

<CodeGroup>
  ```bash x402 theme={null}
  curl -i http://localhost:3000/api/widgets
  # HTTP/1.1 402 Payment Required
  # PAYMENT-REQUIRED: <base64 JSON>
  ```

  ```bash MPP theme={null}
  curl -i http://localhost:3000/api/widgets
  # HTTP/1.1 402 Payment Required
  # WWW-Authenticate: Payment id="…", realm="…", method="inflow", intent="charge", request="…"
  ```
</CodeGroup>

An endpoint without a price must return `200`.

```bash theme={null}
curl -i http://localhost:3000/free
```

| Result | Meaning |
| - | - |
| `402` with the correct header | The middleware works. |
| `200` on a paid endpoint | The middleware did not run for this endpoint. |
| An error at server start | Check the key, the environment, and the account type. See [Errors](/reference/errors). |

## Step 2: Read the challenge with the CLI

The CLI reads the challenge. It does not pay.

<CodeGroup>
  ```bash x402 theme={null}
  inflow x402 inspect http://localhost:3000/api/widgets
  ```

  ```bash MPP theme={null}
  inflow mpp inspect http://localhost:3000/api/widgets
  ```
</CodeGroup>

Confirm the price, the currency, and the payment options. To read a raw header, use `inflow x402 decode` or `inflow mpp decode`.

## Step 3: Pay with the CLI

The CLI uses `production` by default. Your server runs in the sandbox, so add `--sandbox` to each command.

<Steps>
  <Step title="Install the CLI and unlock the vault">
    See [Install the CLI](/agents/install-the-cli). Run `inflow vault unlock` yourself, in your own terminal.
  </Step>

  <Step title="Log in to the sandbox">
    ```bash theme={null}
    inflow auth login --sandbox --client-name "seller-test" --interval 5
    ```

    Open the verification URL in your browser. Approve the login.
  </Step>

  <Step title="Check the sandbox balance">
    ```bash theme={null}
    inflow balances list --sandbox
    ```
  </Step>

  <Step title="Pay the endpoint">
    <CodeGroup>
      ```bash x402 theme={null}
      inflow x402 pay http://localhost:3000/api/widgets --sandbox --interval 5
      ```

      ```bash MPP theme={null}
      inflow mpp pay http://localhost:3000/api/widgets --sandbox --interval 5
      ```
    </CodeGroup>

    Approve the payment when the CLI asks. The result contains the response body from your endpoint.
  </Step>
</Steps>

To use an API key instead, set `INFLOW_API_KEY` to a sandbox key. Keep `--sandbox` on each command. See [Authenticate](/agents/authenticate#log-in-with-an-api-key).

## Step 4: Pay with a buyer example

Run a buyer example from the [inflow-node](https://github.com/inflowpayai/inflow-node) repository. The MPP buyer example works only with the sandbox. It accepts a key from a sandbox Developer account or a sandbox Seller account.

<Tabs>
  <Tab title="MPP">
    Start `mpp-seller-express` or `mpp-seller-hono`, or your own MPP server. Then run the buyer in a second terminal.

    ```bash theme={null}
    cd examples/mpp-buyer-fetch
    cp .env.example .env
    # fill in INFLOW_API_KEY from https://sandbox.inflowpay.ai
    pnpm install
    pnpm start
    ```

    The default target is `http://localhost:3000/api/widgets`. To change it, set `TARGET_URL` in `.env`.

    A successful payment prints this output.

    ```text theme={null}
    GET http://localhost:3000/api/widgets
      status: 200
      body: {"widgets":[1,2,3]}
      paid via inflow: 86f75793-abeb-4fe6-9a46-61901be77070
    ```

    `mpp-buyer-fetch` replaces the global `fetch` with a payment-aware wrapper. For the explicit path, read `mpp-buyer-manual`.
  </Tab>

  <Tab title="x402">
    Start your x402 server. Then run the buyer from the `examples` folder.

    ```bash theme={null}
    cd examples/x402-buyer-fetch
    INFLOW_API_KEY=$INFLOW_API_KEY TARGET_URL=http://localhost:3000/api/widgets pnpm start
    ```

    Other x402 buyer examples are `x402-buyer-axios`, `x402-buyer-x402-evm`, and `x402-buyer-x402-svm`.
  </Tab>
</Tabs>

## Step 5: Check the result

* The pay command returns status `200` and the real body from your endpoint.
* The payment appears in the sandbox dashboard.
* The amount matches your price.

## Troubleshooting

<AccordionGroup>
  <Accordion title="The CLI reports an authentication error in the sandbox">
    Tokens stay in the environment that issued them. Log in again with `--sandbox`.
  </Accordion>

  <Accordion title="The pay command finds no option it can pay">
    Run `inflow mpp supported --sandbox` or `inflow x402 supported --sandbox`. Compare the result with the `inspect` output from step 2.
  </Accordion>

  <Accordion title="Every request returns 402, even after payment">
    The buyer and the server use different protocols. An MPP buyer cannot pay an x402 endpoint. Run `inflow inspect` on the endpoint first.
  </Accordion>
</AccordionGroup>

For server errors such as `403 SELLER_ACCOUNT_REQUIRED`, see [Errors](/reference/errors).

## Next step

<Card title="Step 2: Enable agent enrollment" icon="id-card" href="/sellers/enable-enrollment">
  Let agents enroll with your service and get credentials.
</Card>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.