Flow
Why Decoupled?
Session creation is instant (DB-only, no external calls). The order is created separately when the user commits to a payment method. This means:- Payment method doesn’t need to be known at session creation
- A hosted checkout page can let users choose how to pay
- Session creation never fails due to external API errors
Session Status Lifecycle
| Status | When |
|---|---|
open | Created, waiting for order/payment |
processing | Payment received, order executing |
complete | Order executed successfully |
expired | TTL expired, payment failed, or manually expired |
API
POST /checkout-sessions — Create Session
Creates a lightweight session. No order, no external API calls.
POST /orders — Create Order with Session Linking
Pass checkoutSessionId in the standard order creation request to link the order to a session.
- Session must exist (
400if not found) - Session must be
open(400if expired/processing/complete) - Session must not already have an order (
409 Conflict)
GET /checkout-sessions/:id — Retrieve Session
Returns current session state. Status is synced from the underlying order on each retrieval.
| Query Param | Description |
|---|---|
include=order | Embed the full order object with transactions |
POST /checkout-sessions/:id/expire — Manually Expire
Only works on sessions with status open.
Redirect URL Templates
Use template variables insuccess_url and cancel_url:
| Variable | Replaced with |
|---|---|
{SESSION_ID} | The checkout session UUID |
{ORDER_ID} | Same value (alias) |
?sessionId=<uuid> is appended automatically.
SDK Integration
Service Methods
React Hooks
useCreateCheckoutSession
Mutation hook for creating sessions.
useCheckoutSession
Query hook with auto-polling. Stops polling when status reaches complete or expired.
Component checkoutSession Prop
The <AnySpend>, <AnySpendCustom>, and <AnySpendCustomExactIn> components accept an optional checkoutSession prop:
checkoutSession prop is set, the component automatically creates a session before creating the order, and uses the session’s success_url for redirects. Without the prop, existing flows are unchanged.
HypeDuel