Flow
What It Does
- Customer clicks “Buy” → your server creates a checkout
- Customer is redirected to the AgentaOS checkout page
- Customer pays with their crypto wallet
- AgentaOS sends a webhook → you fulfill the order
- Customer is redirected back to your success page
Prerequisites
Full Code
Key Points
Don't fulfill on the success page
Don't fulfill on the success page
The
successUrl redirect is best-effort. The customer might close their browser before reaching it. Always fulfill orders via the webhook, that’s server-to-server and reliable.Use express.raw() for webhooks
Use express.raw() for webhooks
Webhook signature verification needs the raw request body. If you parse JSON first (
express.json()), the signature won’t match because JSON.stringify doesn’t preserve formatting.Polling as a fallback
Polling as a fallback
If your webhook endpoint is down, you can poll
checkouts.retrieve() as a backup. Check the session status periodically until it’s completed or expired.Idempotent webhook handling
Idempotent webhook handling
Webhooks may be delivered more than once. Use
event.data.sessionId to check if you’ve already processed the payment before fulfilling again.