Looking for the React checkout component? See Checkout. This page covers the REST API for server-driven flows.
Base URL
All checkout session endpoints live on the AnySpend service:Flow
Create a session on your server
POST https://api.anyspend.com/checkout-sessions returns { id, status: "open" }User picks a payment method
POST https://api.anyspend.com/orders with checkoutSessionId returns { id, globalAddress, oneClickBuyUrl }Why decouple sessions from orders?
- The payment method doesn’t need to be known at session creation.
- A hosted checkout page can let users choose how to pay.
- Session creation is a local DB write, so it never fails due to third-party API errors.
Session status lifecycle
| Status | Meaning |
|---|---|
open | Created, waiting for order/payment |
processing | Payment received, order executing |
complete | Order executed successfully |
expired | TTL expired, payment failed, or manually expired |
API reference
Create session
Create order linked to a session
checkoutSessionId in the standard order body 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)
Retrieve session
| Query param | Description |
|---|---|
include=order | Embed the full order object with transactions |
Expire a session
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 prop
The<AnySpend>, <AnySpendCustom>, and <AnySpendCustomExactIn> components accept an optional checkoutSession prop:
checkoutSession is set, the component creates a session before the order, and uses the session’s success_url for redirects. Without the prop, existing flows work the same as before.
HypeDuel