The two calls you need
Create a checkout session, then redirect
Server-side, call
POST /checkout/sessions and send the buyer to the url
in the response. Put your own order/cart id in metadata.1. Create a checkout session
| Field | Required | Notes |
|---|---|---|
productId | Yes | A Pocketsflow product owned by your account. |
successUrl | No | Absolute http(s) URL the buyer returns to after paying. |
cancelUrl | No | Absolute http(s) URL if they abandon checkout. |
customerEmail | No | Attached to the resulting order. |
discountCode | No | A discount code to pre-apply. |
metadata | No | Arbitrary key/values, echoed back on the order + webhooks. |
{ "id": "cs_…", "url": "https://yourstore.pocketsflow.com/checkout?…" }.
2. Verify and handle the webhook
Every webhook is an HTTPPOST signed with HMAC-SHA256 over the raw body, keyed
with your endpoint’s signing secret. Verify it before trusting the payload.
Best practices
- Verify against the raw body. Don’t re-serialize the JSON before hashing.
- Be idempotent. A webhook may be re-sent; processing the same event twice must be safe (check whether the order is already paid first).
- Acknowledge fast. Return
2xxquickly and do heavy work asynchronously. - Reconcile. Treat the webhook as the source of truth; if one is missed, use
GET /ordersand match on yourmetadataid. - Keep secrets server-side. API keys and signing secrets must never reach the browser.