Engineering guide · USDC / USDT · x402

Stablecoin checkout: verify payment before you fulfill

A checkout is complete only when your backend has verified the right asset, network, amount, and recipient. A success redirect or a transaction hash supplied by the browser is not proof of settlement.

What this guide covers

Order creation, server-side payment verification, idempotent fulfillment, webhook handling, and the failure cases worth testing before launch.

1. Create the order on your server

Give each checkout a server-generated order ID, expected amount, asset, network, recipient, and expiry. Keep the price and destination authoritative on the server; never trust a browser to choose what counts as paid.

2. Treat the browser as a status display

The buyer may return to your site before a transfer is final, close the tab after paying, or replay a callback. The browser can show “waiting for confirmation,” but it must not grant access on its own.

3. Verify the settlement against the order

Use a trusted payment processor or your own chain verifier to match the transfer to the stored order. Check the chain, token contract or mint, recipient, amount after decimal conversion, and the confirmation or settlement rule for that network. Reject wrong-token, wrong-network, underpaid, expired, and already-consumed payments.

For x402, follow the selected facilitator and network’s settlement flow. Do not treat a syntactically valid payment header as proof that settlement succeeded.

4. Make fulfillment idempotent

Persist a unique payment or order key before delivering the product. If a webhook is retried or your worker restarts, the same verified payment should not create a second subscription, shipment, or account credit.

payment = verify_against_order(order, settlement_event)
if payment.verified and not fulfillment_exists(payment.unique_id):
    record_verified_payment(payment)
    enqueue_fulfillment(order.id, idempotency_key=payment.unique_id)

This is illustrative pseudocode. The verifier and database transaction must match your chosen chain, provider, and application.

5. Handle webhooks as at-least-once delivery

6. Test the failure paths, not only the happy path

Production handoff checklist

Need this wired into an existing product?

Fixed scope: one Python or Node app, one checkout flow, one network, and one payment asset. Async delivery in five business days, with a written handoff.

$1,000 USDC or USDT · $500 kickoff deposit

Review scope and send a written brief

Related: PayGate source and Python/TypeScript SDK · downloadable checkout checklist.