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.
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
- Verify the signature over the exact raw request body before parsing or trusting the event.
- Compare the event’s order and payment identifiers to your own pending order.
- Use an idempotency key and persist the event before returning success.
- Return a retryable error when processing fails; do not silently mark the order paid.
- Keep a reconciliation path for delayed, duplicated, or missed notifications.
6. Test the failure paths, not only the happy path
- Correct asset, network, recipient, and exact amount.
- Wrong token, wrong chain, wrong recipient, underpayment, and late payment.
- Duplicate transaction event and duplicate webhook delivery.
- Webhook signature mismatch, provider timeout, and delayed confirmation.
- Buyer closes the tab after paying and later returns to check order status.
Production handoff checklist
- Documented supported network, asset, recipient, minimum amount, and settlement rule.
- Server-side paid/pending state with an audit trail linked to the order.
- Signed event verification and idempotent fulfillment.
- Staging walkthrough, failure-path results, and a short operator runbook.
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 briefRelated: PayGate source and Python/TypeScript SDK · downloadable checkout checklist.