Payments

On this page

Checkout.com-compatible API

A mock of Checkout.com's payments API with sandbox semantics, built around Flow payment sessions: customers, payment sessions and their submit call, payments with 3-D Secure, captures, voids and refunds, card instruments, Checkout.com's error shape and signed webhooks. A hosted test page stands in for the Flow component and the Apple Pay sheet. Only test card numbers are accepted; no money moves.

Testlie is not affiliated with, endorsed or sponsored by Checkout.com. "Checkout.com" is used only to describe API compatibility.

Connect

Create a Checkout.com-compatible gateway under Payment gateways. Use its base URL in place of https://api.sandbox.checkout.com.

Credential Use
Secret key (sk_sbox_...) Every API call, as Authorization: Bearer <key> or the bare key
Public key (pk_sbox_...) Refused by the server API, as on Checkout.com; Flow's own client is not mocked
Webhook secret key Signs each webhook: Cko-Signature
Webhook authorization header key Sent verbatim as the webhook's Authorization header, like the dashboard's Authorization header key

With checkout-sdk-node, pass the base URL as the host option; everything else stays as it is:

js
import Checkout from "checkout-sdk-node";

const cko = new Checkout(process.env.CHECKOUT_API_KEY, { host: process.env.CHECKOUT_API_BASE_URL });

The secret key has the shape of a sandbox key, so the SDK sends it as Bearer like it does for Checkout.com's. Plain HTTP calls (fetch to ${base}/payment-sessions/{id}/submit) work the same way.

A wrong or missing key answers 401 with an empty body, as Checkout.com does; so do unknown ids (404). These refusals are not counted against the quota. Invalid requests answer 422 in Checkout.com's shape, listing every problem:

json
{ "request_id": "0b5cfa4e-...", "error_type": "request_invalid", "error_codes": ["amount_invalid", "billing_required"] }

Every response has a Cko-Request-Id header. Ids look like Checkout.com's: cus_, ps_, pay_, act_, src_, evt_.

Endpoints

Endpoint
POST /customers email (required, unique: a second customer with it is 422 customer_email_already_exists), name, phone, metadata. Answers 201 { "id": "cus_..." }
GET /customers/{id or email} The customer with instruments[] (saved cards: id, fingerprint, scheme, last4, bin, expiry...). The email lookup ignores case
PATCH / DELETE /customers/{id} email, name, phone, metadata, default (an instrument id). 204
POST /payment-sessions Creates a Flow session (see below). Answers 201 { id, payment_session_token, payment_session_secret, _links: { self, test_page } }
GET /payment-sessions/{id} The session: amount, currency, customer, metadata, status (Active, Payment Pending, Completed) and payment_ids
POST /payment-sessions/{id}/submit { "session_data": "..." }, what Flow's handleSubmit callback gives your backend. Answers the payment (see Submitting)
GET /payments/{id} The payment: status, source, customer, metadata, balances, 3ds, response_code, _links
GET /payments/{id}/actions Authorization, Card Verification, Capture, Void and Refund actions, newest first
POST /payments/{id}/captures Optional amount (partial captures), reference, metadata. 202 { action_id, reference }
POST /payments/{id}/voids Voids an authorised, uncaptured payment. 202
POST /payments/{id}/refunds Optional amount, reference, metadata. 202
GET / DELETE /instruments/{id} A saved card and its customer

An action the payment's balances don't allow (refunding an uncaptured payment, voiding after a capture) answers 403 with an empty body; amounts over the balance are 422 capture_amount_exceeds_balance or refund_amount_exceeds_balance.

Not implemented: direct card payments (POST /payments), Hosted Payments Page and payment links, tokens, POST /instruments, idempotency keys, disputes, the events and workflows APIs, and Flow's own browser client.

Payment sessions

POST /payment-sessions takes Checkout.com's fields. Required: amount (an integer in the minor unit), currency, billing.address.country, success_url, failure_url and processing_channel_id (any value). The mock also uses:

  • customer: { id } (it must exist) or customer: { email, name }; without one, a customer is created.
  • metadata: copied to the payment and every webhook, with cko_payment_session_id added, as Checkout.com does for Flow payments.
  • 3ds: { enabled, challenge_indicator }: with enabled: true and challenge_indicator challenge_requested (or challenge_requested_mandate), every card payment goes through a 3-D Secure challenge. Otherwise authentication is frictionless.
  • enabled_payment_methods: card, applepay, stored_card; the test page and submit only allow these.
  • payment_method_configuration.card.store_payment_details: enabled or collect_consent saves the card as an instrument of the customer (consent is assumed). stored_card.instrument_ids lists saved cards the shopper may pick.
  • capture: false leaves approved payments Authorized until you capture them; by default they are captured.
  • reference, description, display_name, expires_on (default one hour).

The test page

_links.test_page.href (an addition of the mock) opens a page that stands in for Flow. It shows the amount and lets the shopper pick a test card, the Apple Pay test wallet or a saved card, then:

  • Pay does what Flow does on its own: it submits the payment, opens the 3-D Secure challenge when the session asks for one, and sends the browser to success_url (or back to the page with the decline reason) with ?cko-payment-session-id=...&cko-payment-id=....
  • Get session_data for my backend shows a session_data value (sd_...), what Flow gives a handleSubmit callback. Your backend submits it with POST /payment-sessions/{id}/submit; the page keeps showing the latest value.

Submitting

session_data can be a value from the test page or, for automated tests, a test card number, applepay, or a saved card's instrument id (src_...). The answer is always a 2xx, as on Checkout.com:

Result Response
Approved 201 { "id": "pay_...", "status": "Approved", "type": "card", "response_code": "10000" }
Declined 201 { "id": "pay_...", "status": "Declined", "type": "card", "response_code": "20051", "decline_reason": "Insufficient funds" }
3-D Secure 202 { "id": "pay_...", "status": "Action Required", "type": "card", "action": { "type": "redirect", "url": "<challenge page>" } }

type is applepay for the Apple Pay wallet and stored_card for a saved card. The payment exists at once (Pending while the challenge waits) with its source (id, scheme, last4, bin, fingerprint, expiry, holder name), customer and metadata. The card's fingerprint is the same every time the same card is used with the gateway, and the customer's saved instrument has it too. A declined session can be submitted again; an approved one answers 422 payment_session_already_completed.

The challenge page offers Complete authentication (the payment is then approved, or declined if the card declines), Fail authentication and Let it expire, and sends the browser to success_url or failure_url.

A zero amount verifies the card instead of charging it: the payment becomes Card Verified and the events are card_verified or card_verification_declined.

Test cards only

A card number must pass the Luhn check and be one of these. Anything else, including a real card, is refused; card numbers are never stored.

Card Result
4242 4242 4242 4242, 4543 4740 0224 9996 (Visa) Approved
5436 0310 3060 6378, 5555 5555 5555 4444 (Mastercard) Approved
3456 789012 34564 (Amex), 6011 1111 1111 1117 (Discover), 3530 1113 3330 0000 (JCB) Approved
4544 2491 6767 3670, 4000 0000 0000 0002 20005 Declined - Do not honour
4000 0000 0000 9995 20051 Insufficient funds
4000 0000 0000 0069 20054 Expired card
4100 0000 0000 0019 20059 Suspected fraud
Apple Pay test wallet Approved (a Visa device card); no 3-D Secure

The Outcome scenario overrides the table: every payment succeeds approves every test card without a challenge, every payment is declined declines with the code you pick (20005, 20012, 20014, 20051, 20054, 20059, 20062), and every payment needs 3-D Secure challenges every card payment.

Webhooks

Set the gateway's webhook URL to receive Checkout.com events:

json
{ "id": "evt_...", "type": "payment_captured", "version": "1.0.33", "created_on": "2026-11-16T09:00:00.000Z",
  "data": { "id": "pay_...", "action_id": "act_...", "amount": 10250, "currency": "AED", "response_code": "10000", "response_summary": "Approved",
            "balances": { "total_captured": 10250, ... }, "customer": { "id": "cus_..." }, "metadata": { "cko_payment_session_id": "ps_...", ... },
            "source": { "id": "src_...", "type": "card", "scheme": "Visa", "last_4": "4242", "fingerprint": "..." }, ... },
  "_links": { "self": { "href": "..." }, "payment": { "href": "..." } } }
Event When
payment_approved, then payment_captured A payment is authorised, then captured (automatically, about a second later, unless the session set capture: false)
payment_declined The card declines, or 3-D Secure fails
card_verified, card_verification_declined A zero-amount session
authentication_failed The shopper fails the challenge (data.payment_id, data.session_id, data.metadata), followed by payment_declined
authentication_expired The challenge expires, followed by payment_expired
payment_captured, payment_voided, payment_refunded Your capture, void and refund calls

Events about a payment that is decided at submit time are sent after the Asynchronous steps delay (2 seconds by default), as the sandbox's are, so your submit handler can record the payment before its events arrive.

Each delivery carries:

  • Cko-Signature: the hex HMAC-SHA256 of the raw body with the webhook secret key.
  • Authorization: the webhook authorization header key, verbatim.
js
import { createHmac, timingSafeEqual } from "node:crypto";

const expected = createHmac("sha256", process.env.CHECKOUT_WEBHOOK_SECRET).update(rawBody).digest("hex");
const ok = req.headers.authorization === process.env.CHECKOUT_AUTHORIZATION_HEADER_KEY
  && timingSafeEqual(Buffer.from(expected, "hex"), Buffer.from(req.headers["cko-signature"], "hex"));

The webhook scenarios (delay, drop, duplicate, bad signature) and Next time webhook outcomes apply, and failed deliveries are retried.