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

# Testing

> Exercise a staging payment from HTTP 402 through capture to a CONFIRMED batch entry.

Test on staging (Base Sepolia, chain id `84532`). You need an onboarded borrower with an `ACTIVE` agent grant, and a merchant that is `ACTIVE` in the registry with a facilitator credential.

> [!NOTE]
>
> Staging does not skip merchant KYB, and it does not issue `sk_test_` keys. Ask SohoPay for a staging merchant if you do not have one.

## Merchant loop

**1. Return 402**

Serve a credit-scheme requirement for `eip155:84532` and the staging USDC asset in [Environment setup](/environment-setup.md).

**2. Let an agent pay**

The agent calls `prepare_x402_payment`, signs the voucher, and retries with `PAYMENT-SIGNATURE`. Use one idempotency key for that `orderRef`.

**3. Capture**

`POST /api/v1/facilitator/capture` with `x402Version: 2`. Save `receipt.paymentId`.

**4. Poll**

`GET /api/v1/facilitator/settle/status/by-payment/:paymentId` every 2 seconds. You should see `CREATED`, then `SUBMITTED`, then `CONFIRMED`. Fulfill only on `CONFIRMED`.

The batch flushes about every 60 seconds, so `CREATED` can last that long.

**5. Check the chain**

Open the batch `txHash` on [Sepolia Basescan](https://sepolia.basescan.org). The merchant transfer is USDC from `SohoSettlementV2`, net of the fee. It is not an ERC-3009 pull from the agent.

## Cases worth forcing

* Replay capture with the same `Idempotency-Key` and body. You get the same receipt and `replayed: true`.
* Send a V1 payment intent. Capture refuses it (`X402_AGENT_VOUCHER_REQUIRED`).
* Call prepare before the workload key is registered. You get `X402_AGENT_KEY_NOT_REGISTERED`. Register the key and retry the same order and key.
* Let a voucher intent expire, then retry the same order and the same key (`X402_INTENT_EXPIRED`).

## Next steps

> [card] [Errors](/guides/error-handling.md)
>
> Which failures to retry.

> [card] [Payment flow](/guides/payment-flow.md)
>
> The agent half of the same test.
