KashuDocs

Checkout sessions

The checkout sessions endpoints of the Kashu API, with their parameters, objects, errors and examples. The guide explains how they fit together.

EndpointWhat it does
POST /v1/checkout_sessionsCreate a checkout session for Kashu.js to take payment for. The response is the only place its client secret appears.
GET /v1/checkout_sessionsList checkout sessions, newest first.
GET /v1/checkout_sessions/{id}Retrieve a checkout session.
POST /v1/checkout_sessions/{id}/expireExpire an open checkout session now, so it takes no payment. A session whose payment is in flight or made cannot be expired.
GET /v1/checkout_sessions/{id}/clientRead what the card form shows of a session, with the publishable key and the session's client secret.
POST /v1/checkout_sessions/{id}/payPay a checkout session with a card token. Kashu's card form calls this for you.

The checkout session object

FieldTypeAbout
idstringAn id that starts cs_.
objectstringAlways "checkout_session".
statusenumOne of open, complete, expired.
payment_statusenumunpaid until a payment is made or after one failed; processing while one is in flight; authorized when held for capture; paid once captured. One of unpaid, processing, authorized, paid.
amountintegerIn the currency's minor unit, such as cents for USD. More than 0.
currencystringThree capital letters, such as USD.
capture_methodenumOne of automatic, manual.
customerstring or nullAn id that starts cu_.
paymentstring or nullThe latest payment made for the session. An id that starts py_.
storestringAn id that starts st_.
success_urlstring
cancel_urlstring or null
client_secretstring or nullFor Kashu.js in the buyer's page. Shown only in the response that created the session; keep it with the order.
expires_atintegerUnix seconds.
completed_atinteger or nullUnix seconds.
metadatamap of strings
livemodeboolean
createdintegerUnix seconds.
{
  "id": "cs_1a2B3c4D5e6F7g8H9i0J1k2L",
  "object": "checkout_session",
  "status": "open",
  "payment_status": "unpaid",
  "amount": 4999,
  "currency": "USD",
  "capture_method": "automatic",
  "customer": "cu_1a2B3c4D5e6F7g8H9i0J1k2L",
  "payment": "py_1a2B3c4D5e6F7g8H9i0J1k2L",
  "store": "st_1a2B3c4D5e6F7g8H9i0J1k2L",
  "success_url": "https://shop.example.com/thanks",
  "cancel_url": null,
  "client_secret": null,
  "expires_at": 1762473600,
  "completed_at": null,
  "metadata": {
    "order": "1001"
  },
  "livemode": false,
  "created": 1762473600
}

The checkout session client object

FieldTypeAbout
idstringAn id that starts cs_.
objectstringAlways "checkout_session".
statusenumOne of open, complete, expired.
payment_statusenumunpaid until a payment is made or after one failed; processing while one is in flight; authorized when held for capture; paid once captured. One of unpaid, processing, authorized, paid.
payment_errorenum or nullWhy the latest attempt failed, while the session is open for another. One of card_declined, processing_error.
amountintegerIn the currency's minor unit, such as cents for USD. More than 0.
currencystringThree capital letters, such as USD.
collect_emailbooleanWhether the form asks for the buyer's email: the session names no customer.
success_urlstring
expires_atintegerUnix seconds.
livemodeboolean
{
  "id": "cs_1a2B3c4D5e6F7g8H9i0J1k2L",
  "object": "checkout_session",
  "status": "open",
  "payment_status": "unpaid",
  "payment_error": null,
  "amount": 4999,
  "currency": "USD",
  "collect_email": false,
  "success_url": "https://shop.example.com/thanks",
  "expires_at": 1762473600,
  "livemode": false
}

POST /v1/checkout_sessions

Create a checkout session for Kashu.js to take payment for. The response is the only place its client secret appears.

Scope
checkout_sessions:write
Keys
Secret, or restricted with the scope below.
Idempotency-Key
Optional. Without one, Kashu makes one and returns it. See Idempotency.
Answers
201 with the Checkout session.

Parameters

NameInTypeRequiredAbout
Idempotency-KeyheaderstringOptionalOptional. When absent, Kashu mints one and returns it. Up to 255 characters.
Kashu-VersionheaderstringOptionalThe API version to answer in. Defaults to the key's pinned version.

Request body

FieldTypeRequiredAbout
amountintegerRequiredIn the currency's minor unit, such as cents for USD. More than 0. Up to 99999999.
currencystringRequiredThree capital letters, such as USD.
success_urlstringRequiredWhere Kashu.js sends the buyer once the session is paid. https; a test session may use http://localhost. Up to 2048 characters.
cancel_urlstringOptionalWhere the buyer goes back to if they leave. The same rules as success_url. Up to 2048 characters.
customerstringOptionalThe buyer, if you know them. Without one the form asks for an email and makes a customer. An id that starts cu_.
capture_methodenumOptionalOne of automatic, manual.
storestringOptionalAn id that starts st_.
expires_atintegerOptionalWhen the session stops taking payment: 30 minutes to 24 hours from now. Defaults to 24 hours. Unix seconds.
metadatamap of stringsOptionalKeys up to 40 characters, values up to 500.

Errors

Examples

curl https://api.kashupay.com/v1/checkout_sessions \
  -H "Authorization: Bearer $KASHU_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"amount":4999,"currency":"USD","success_url":"https://shop.example.com/thanks"}'
const checkoutSession = await kashu("POST", "/v1/checkout_sessions", {
  "amount": 4999,
  "currency": "USD",
  "success_url": "https://shop.example.com/thanks"
});
console.log(checkoutSession.status);

GET /v1/checkout_sessions

List checkout sessions, newest first.

Scope
checkout_sessions:read
Keys
Secret, or restricted with the scope below.
Idempotency-Key
Not used. A read changes nothing.
Answers
200 with a list of Checkout session, newest first.

Parameters

NameInTypeRequiredAbout
statusqueryenumOptionalOne of open, complete, expired.
customerquerystringOptionalAn id that starts cu_.
limitqueryintegerOptionalAt least 1. Up to 100. Defaults to 10.
cursorquerystringOptional
Kashu-VersionheaderstringOptionalThe API version to answer in. Defaults to the key's pinned version.

Errors

Examples

curl "https://api.kashupay.com/v1/checkout_sessions?limit=3" \
  -H "Authorization: Bearer $KASHU_SECRET_KEY"
const list = await kashu("GET", "/v1/checkout_sessions?limit=3");
console.log(list.has_more);

GET /v1/checkout_sessions/{id}

Retrieve a checkout session.

Scope
checkout_sessions:read
Keys
Secret, or restricted with the scope below.
Idempotency-Key
Not used. A read changes nothing.
Answers
200 with the Checkout session.

Parameters

NameInTypeRequiredAbout
idpathstringRequiredAn id that starts cs_.
Kashu-VersionheaderstringOptionalThe API version to answer in. Defaults to the key's pinned version.

Errors

Examples

curl https://api.kashupay.com/v1/checkout_sessions/cs_1a2B3c4D5e6F7g8H9i0J1k2L \
  -H "Authorization: Bearer $KASHU_SECRET_KEY"
const checkoutSession = await kashu("GET", "/v1/checkout_sessions/cs_1a2B3c4D5e6F7g8H9i0J1k2L");
console.log(checkoutSession.status);

POST /v1/checkout_sessions/{id}/expire

Expire an open checkout session now, so it takes no payment. A session whose payment is in flight or made cannot be expired.

Scope
checkout_sessions:write
Keys
Secret, or restricted with the scope below.
Idempotency-Key
Optional. Without one, Kashu makes one and returns it. See Idempotency.
Answers
200 with the Checkout session.

Parameters

NameInTypeRequiredAbout
idpathstringRequiredAn id that starts cs_.
Idempotency-KeyheaderstringOptionalOptional. When absent, Kashu mints one and returns it. Up to 255 characters.
Kashu-VersionheaderstringOptionalThe API version to answer in. Defaults to the key's pinned version.

Request body

Send no body, or an empty JSON object.

Errors

Examples

curl https://api.kashupay.com/v1/checkout_sessions/cs_1a2B3c4D5e6F7g8H9i0J1k2L/expire \
  -X POST \
  -H "Authorization: Bearer $KASHU_SECRET_KEY"
const checkoutSession = await kashu("POST", "/v1/checkout_sessions/cs_1a2B3c4D5e6F7g8H9i0J1k2L/expire");
console.log(checkoutSession.status);

GET /v1/checkout_sessions/{id}/client

Read what the card form shows of a session, with the publishable key and the session's client secret.

Scope
checkout_sessions:read
Keys
Publishable, for the card form, or secret.
Idempotency-Key
Not used. A read changes nothing.
Answers
200 with the Checkout session client.

Parameters

NameInTypeRequiredAbout
idpathstringRequiredAn id that starts cs_.
client_secretquerystringRequiredUp to 200 characters.
Kashu-VersionheaderstringOptionalThe API version to answer in. Defaults to the key's pinned version.

Errors

Examples

curl "https://api.kashupay.com/v1/checkout_sessions/cs_1a2B3c4D5e6F7g8H9i0J1k2L/client?client_secret=cs_..._secret_x" \
  -H "Authorization: Bearer $KASHU_PUBLISHABLE_KEY"
const checkoutSessionClient = await kashu("GET", "/v1/checkout_sessions/cs_1a2B3c4D5e6F7g8H9i0J1k2L/client?client_secret=cs_..._secret_x");
console.log(checkoutSessionClient.status);

POST /v1/checkout_sessions/{id}/pay

Pay a checkout session with a card token. Kashu's card form calls this for you.

Scope
checkout_sessions:write
Keys
Publishable, for the card form, or secret.
Idempotency-Key
Required. This endpoint moves money. See Idempotency.
Answers
200 with the Checkout session client.

Parameters

NameInTypeRequiredAbout
idpathstringRequiredAn id that starts cs_.
Idempotency-KeyheaderstringRequiredRequired. Retry with the same key and get the same result. Up to 255 characters.
Kashu-VersionheaderstringOptionalThe API version to answer in. Defaults to the key's pinned version.

Request body

FieldTypeRequiredAbout
client_secretstringRequiredUp to 200 characters.
tokenstringRequiredA card token (tok_) from the card form. Paying spends it. An id that starts tok_.
emailstringOptionalThe buyer's email, required when the session names no customer. An email address. Up to 254 characters.
namestringOptionalThe name on the card. Up to 200 characters.

Errors

Examples

curl https://api.kashupay.com/v1/checkout_sessions/cs_1a2B3c4D5e6F7g8H9i0J1k2L/pay \
  -H "Authorization: Bearer $KASHU_PUBLISHABLE_KEY" \
  -H "Idempotency-Key: checkout-sessions-pay-1001" \
  -H "Content-Type: application/json" \
  -d '{"client_secret":"cs_..._secret_x","token":"tok_1a2B3c4D5e6F7g8H9i0J1k2L"}'
const checkoutSessionClient = await kashu("POST", "/v1/checkout_sessions/cs_1a2B3c4D5e6F7g8H9i0J1k2L/pay", {
  "client_secret": "cs_..._secret_x",
  "token": "tok_1a2B3c4D5e6F7g8H9i0J1k2L"
}, { idempotencyKey: "checkout-sessions-pay-1001" });
console.log(checkoutSessionClient.status);