API Reference

The CX Pay API is organized around REST. Predictable resource-oriented URLs, JSON-encoded request and response bodies, and standard HTTP response codes.

Two environments live behind the same base URL. The API key you sign with determines whether the request runs in test or live mode — keys prefixed ak_test_ target the sandbox, ak_live_ target production.

Every request must be signed with HMAC-SHA256. Unsigned requests are rejected. Bulk operations are not supported — one object per request.

BASE URL
https://api.cxpay.net
JUST GETTING STARTED?
Read the 10-minute quickstart for the full integration walkthrough, or jump to Authentication.
THE 30-SECOND VERSION
  1. POST /v1/checkout-sessions — get a hosted checkout URL.
  2. Redirect your customer to that URL. They pay on our page.
  3. We POST payment_intent.succeeded to your webhook. Fulfill the order.

Was this section helpful?

How it works

Every payment moves through three objects: Checkout Session, Payment Intent, and Charge. You create the first. The other two are derived.

The Checkout Session wraps a hosted payment page. The Payment Intent tracks the lifecycle (created → processing → succeeded / failed). The Charge is the actual money movement and is rarely something you need to read directly.

Rule of thumb: check payment_intent.status to know if you got paid. Ignore Charges unless you're debugging a specific failure.

Object hierarchy

Checkout Session · cs_…
owns
Payment Intent · pi_…
owns
Charge · ch_…

Payment Intent status

The states you'll see, and what they mean for your integration:

PAYMENT FLOW
Your Server
CX Pay
Customer
POST /v1/checkout-sessions
{ id, url, payment_intent }
Redirect to session.url
Sees hosted checkout
Enters card details
3DS challenge (if needed)
Charge created
PI → succeeded
webhook: payment_intent.succeeded
Fulfill the order
PAYMENT INTENT STATUS
succeeded
Money capturedDone. Fulfill the order.
processing
Payment in flightSubmitted to the network, waiting for its result. There is no fixed time limit: it does not expire and cannot be canceled. Wait for the webhook or retrieve the PaymentIntent. With no result after about 24 hours, it moves to uncertain.
uncertain
UncertainThe result is not known yet. No webhook is sent for this status, so retrieve the PaymentIntent. Do not charge again. If it resolves, you get payment_intent.succeeded or payment_intent.payment_failed.
requires_review
Needs reviewAutomated recovery ran out and the result is still unknown. No webhook is sent and the status does not change on its own. Keep the order pending and contact support.
requires_action
3DS challengeCustomer is completing 3DS on our hosted page. No action from you.
requires_payment_method
Awaiting cardCustomer hasn't completed checkout yet.
requires_capture
Auth heldManual capture flow. Capture when ready.
canceled
CanceledCustomer canceled or session expired before payment.
expired
Session expiredCreate a new session if the customer wants to retry.

Was this section helpful?

Authentication

Every request is signed with HMAC-SHA256. The signature proves you hold the secret, and the body hash — recomputed and verified server-side against the received body — proves the request body hasn't been tampered with.

Required headers

X-Key-Idstring
Your API key id, prefixed ak_test_ or ak_live_.
X-Timestampstring
ISO-8601 UTC timestamp. Must be within 5 minutes of server time.
X-Noncestring
A unique string per request. UUIDs work. Each nonce can only be used once.
X-Body-Hashstring
SHA-256 of the request body, hex-encoded. For requests without a body, the SHA-256 of the empty string. The server recomputes this from the received body and rejects the request if it doesn't match.
X-Signaturestring
Base64-encoded HMAC-SHA256 of the canonical string, keyed with your decoded secret.

Canonical string

Six values, joined by newlines:

{METHOD}
{PATH}
{SORTED_QUERY}
{TIMESTAMP}
{NONCE}
{BODY_HASH}
METHOD
Uppercase: POST, GET.
PATH
Leading /, no trailing slash.
SORTED_QUERY
Query params sorted by key (ASCII) and joined as k=v&k=v. Empty string if none.
BODY_HASH
SHA-256 hex of the request body. Use SHA-256 of the empty string when there is no body.

Compute the signature

signature = base64( hmac_sha256( base64_decode(secret), canonical ) )

Your secret is base64-encoded at issue. Decode it once, then use the raw bytes as the HMAC key. Don't decode it twice; don't HMAC over the encoded form.

SIGN A REQUEST
1# Headers required on every request:
2# X-Key-Id — your key id (ak_test_... / ak_test_...)
3# X-Timestamp — ISO-8601 UTC timestamp
4# X-Nonce — unique string per request
5# X-Body-Hash — sha256(body) hex
6# X-Signature — base64( hmac_sha256(secret, canonical) )
7
8curl https://api.cxpay.net/v1/checkout-sessions \
9 -H "X-Key-Id: ak_test_..." \
10 -H "X-Timestamp: 2026-04-07T18:30:00.000Z" \
11 -H "X-Nonce: 550e8400-e29b-41d4-a716-446655440000" \
12 -H "X-Body-Hash: a3f2b8c1..." \
13 -H "X-Signature: <base64-hmac>" \
14 -H "Content-Type: application/json" \
15 -d '{"mode":"payment","amount":5000,"currency":"USD"}'
TestPOST /v1/checkout-sessions
REPLAY PROTECTION
Timestamps must be within 5 minutes of server time. Nonces can only be used once. This rejects replayed requests even if the signature is valid.

Was this section helpful?

Identity

GET /v1/me returns the identity behind the API key you signed with — your merchantOrgId, the keyId used, and your effective entitlements. It takes no body.

It's the quickest way to confirm your HMAC signing is correct: if /v1/me returns 200, your credentials and signature are valid. A 403 means the signature, timestamp, or nonce is off — start debugging there before any other endpoint.

Response

merchantOrgIdstring
The merchant organization the key belongs to.
keyIdstring
The API key id used for this request.
entitlementsobject
Your effective entitlements (plan plus any overrides), keyed by product.
GET /v1/me
cURL
1curl https://api.cxpay.net/v1/me \
2 -H "X-Key-Id: ak_test_..." \
3 -H "X-Timestamp: 2026-04-07T18:30:00.000Z" \
4 -H "X-Nonce: 550e8400-e29b-41d4-a716-446655440000" \
5 -H "X-Body-Hash: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" \
6 -H "X-Signature: <base64-hmac>"
TestGET /v1/me
RESPONSE
JSON
1{
2 "merchantOrgId": "morg_01JQX...",
3 "keyId": "ak_test_...",
4 "entitlements": {
5 "merchantOrgId": "morg_01JQX...",
6 "products": {
7 "payments": { "enabled": true, "features": {}, "limits": {} }
8 }
9 }
10}

Was this section helpful?

Errors

CX Pay uses conventional HTTP response codes. 2xx means success. 4xx means a client problem (missing field, bad signature, replay, rate limit). 5xx means our problem and is rare.

Error response shape

Every non-2xx response is JSON with the same envelope:

ERROR RESPONSE
JSON
1{
2 "error": {
3 "type": "VALIDATION",
4 "code": "AMOUNT_BELOW_MINIMUM",
5 "message": "Amount is below the minimum for this account.",
6 "retryable": false,
7 "details": [
8 {
9 "kind": "FIELD",
10 "field": "amount",
11 "location": "body",
12 "message": "Must be at least 50.",
13 "code": "AMOUNT_BELOW_MINIMUM"
14 }
15 ],
16 "correlationId": "01JQX...",
17 "timestamp": "2026-04-07T18:30:00.000Z"
18 }
19}
typestring
One of the error types listed in the right rail. Always uppercase (e.g. VALIDATION, AUTH).
codestring
A short machine-readable code. Stable across versions.
messagestring
Human-readable description. Safe to log; not always safe to show users verbatim.
retryableboolean
Whether another attempt is allowed. It does not promise the same request will succeed; decide what to change from code. A declined payment uses the same meaning on last_payment_error.retryable: see Declines.
retryAfterMsinteger|null
Milliseconds until the client may retry. Present on RATE_LIMIT errors.
detailsarray|null
Array of field-level details. Each item has kind (uppercase, e.g. FIELD), field, location, message, and code.
error.correlationIdstring
Trace id for this request (nested inside error). Include it when contacting support.
error.timestampstring
ISO-8601 timestamp of when the error was generated (inside error).
HTTP STATUS CODE SUMMARY
200
OKEverything worked as expected.
400
Bad RequestMissing or invalid parameter, malformed body, currency mismatch, line items don't sum to amount.
403
ForbiddenAuthentication failure — bad signature, expired timestamp, reused nonce, or unknown key id.
404
Not FoundThe requested object doesn't exist.
409
ConflictIdempotency-Key reused with a different request body.
429
Too Many RequestsReserved. Rarely seen — there is no platform-wide throttle. The only case is a short per-payment-link cooldown; the cooldown is reported as retryAfterMs in the error body.
5xx
Server ErrorsSomething went wrong on our end. Rare. Retry safely if the request was idempotent.
ERROR TYPES
AUTH
Signature invalid, timestamp out of range, nonce reused, or key id unknown. Surfaces as 403.
VALIDATION
Request shape was valid but values didn't pass field-level checks (e.g., AMOUNT_BELOW_MINIMUM, CURRENCY_NOT_SUPPORTED, UNSUPPORTED_CURRENCY_PRECISION).
IDEMPOTENCY
The Idempotency-Key was reused with different request parameters.
DOMAIN
A business rule rejected the action in its current state (e.g., CHECKOUT_CANCELED on a canceled session). Often a 410.
CONFLICT
State transition rejected — the resource is already in a terminal or incompatible state.
NOT_FOUND
The requested object doesn't exist or belongs to a different account.
RATE_LIMIT
Reserved, rarely seen — the only case today is a short per-payment-link cooldown. When present, retryAfterMs in the error body carries the cooldown.
DEPENDENCY
A downstream dependency we rely on failed or timed out (e.g., FX_RATE_NOT_FOUND). Typically a 5xx; safe to retry.
UPSTREAM
A payment processor or third-party service we depend on returned an error (e.g., a 502 from a downstream provider).
INTERNAL
Internal failure on our side. We're paged on these.

Was this section helpful?

Idempotency

Idempotency-Key is required on creates and the payment mutations listed here: every create (checkout sessions, payment intents, customers, setup intents, payment links, return domains), payment-intent update/capture/cancel/refund, setup-intent update/confirm/complete-action/cancel, payment-method attach/detach/delete, and mandate revoke. Same key + same body replays the original response (with a replayed: true marker added, so it isn't byte-identical), except a 4xx or 5xx response: those aren't replayed, and the request runs again. Same key + different body returns 409 Conflict.

DELETE /v1/return-domains/:id does not require this header. Repeating that delete returns 404and writes nothing; see removing a return domain.

Use a UUID v4. One key per logical operation. Keys are cached for 24 hours; after that the key is forgettable and a new request creates a fresh resource.

A saved-card charge (POST /v1/payment-intents with confirm: true) is stricter. Its key names one charge with no expiry: the same key always answers with the same PaymentIntent, and a refused card answers the same 402 again, with no new attempt on the card. Derive the key from the thing being billed, such as an invoice id plus the attempt number. See Charging saved cards.

A 202 while the first request is running

Any request that requires Idempotency-Key can return 202 with {"status":"processing"} when you repeat it with the same key and body while the first request is still running. The first request has not finished. This is not a PaymentIntent status, and it does not tell you the outcome.

Wait, then retrieve the object or retry with the same key. A create has nothing to retrieve yet, so retry it. If the first request stopped before finishing, the key keeps returning 202 for about 24 hours, until it expires. If a 202 persists, retrieve the object, and contact support if you have no id or the outcome is still unclear. Never retry with a new key: a new key runs the operation again, and on a saved-card charge that can charge the card twice.

WITH IDEMPOTENCY-KEY
cURL
1curl https://api.cxpay.net/v1/checkout-sessions \
2 -H "Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000" \
3 -H "X-Key-Id: ak_test_..." \
4 -H "X-Signature: ..." \
5 -H "Content-Type: application/json" \
6 -d '{"mode":"payment","amount":5000,"currency":"USD"}'
TestPOST /v1/checkout-sessions

Was this section helpful?

Webhooks

We POST events to your webhook URL when something happens. You verify the signature, process the event, and return 200. Anything else triggers retry.

Events you'll care about

For hosted checkout, four events matter. Start with payment_intent.succeeded — that's the one that means "you got paid." See the full catalog at Events.

Verifying signatures

Every webhook includes a X-CXPay-Signature header in the form t=<timestamp>,v1=<hex>. Compute HMAC-SHA256(secret, "{t}.{raw_body}") and compare with constant time. Reject anything older than 5 minutes.

Retry behavior

Non-2xx response or timeout: we make up to 8 attempts, the first delivery and up to 7 retries with exponential backoff at about 5s, 30s, 2m, 10m, 1h, 4h and 12h (~17h total). These delays are approximate: a retry can run up to about 5 minutes after its scheduled time. After that, the delivery is marked failed. Your endpoint must start responding within 5 seconds. With no 2xx by then we retry, so the same event can arrive again. Delivery order is not guaranteed. Make your endpoint idempotent — use the event id to deduplicate.

WEBHOOK PAYLOAD
JSON
1{
2 "id": "evt_01JQX...",
3 "object": "event",
4 "type": "payment_intent.succeeded",
5 "created": 1744050900,
6 "createdAt": "2026-04-07T18:35:00.000Z",
7 "apiVersion": "2026-01-01",
8 "livemode": false,
9 "merchantOrgId": "morg_01JQX...",
10 "data": {
11 "object": {
12 "paymentIntentId": "pi_01JQX...",
13 "amount": 5000,
14 "amountReceived": 5000,
15 "currency": "USD",
16 "status": "succeeded",
17 "chargeId": "ch_01JQX...",
18 "clientReferenceCode": "ORD-123",
19 "customerId": "cus_01JQX..."
20 }
21 }
22}
VERIFY SIGNATURE
1import crypto from "crypto";
2
3function verifyWebhook(rawBody, header, secret) {
4 const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
5 const { t: timestamp, v1: signature } = parts;
6
7 // Reject if the webhook is older than 5 minutes
8 const age = Math.abs(Date.now() / 1000 - parseInt(timestamp));
9 if (age > 300) throw new Error("Webhook too old");
10
11 const expected = crypto
12 .createHmac("sha256", secret)
13 .update(`${timestamp}.${rawBody}`)
14 .digest("hex");
15
16 if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
17 throw new Error("Invalid signature");
18 }
19 return JSON.parse(rawBody);
20}

Was this section helpful?

Powered by CX Pay