KashuDocs

Payments

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

EndpointWhat it does
POST /v1/paymentsCharge a saved card or a card token, or authorize it with capture_method manual. A decline is a payment with status failed.
GET /v1/paymentsList payments, newest first.
GET /v1/payments/{id}Retrieve a payment.
POST /v1/payments/{id}/captureCapture an authorized payment, once, for at most the amount held. Without an amount, all of it.
POST /v1/payments/{id}/voidRelease an authorized payment that has not been captured.

The payment object

FieldTypeAbout
idstringAn id that starts py_.
objectstringAlways "payment".
amountintegerIn the currency's minor unit, such as cents for USD. More than 0.
amount_capturableintegerIn the currency's minor unit, such as cents for USD.
amount_capturedintegerIn the currency's minor unit, such as cents for USD.
amount_refundedintegerIn the currency's minor unit, such as cents for USD.
currencystringThree capital letters, such as USD.
capture_methodenumOne of automatic, manual.
statusenumOne of pending, requires_action, requires_capture, succeeded, failed, canceled, processing.
storestringAn id that starts st_.
customerstring or nullAn id that starts cu_.
payment_methodstring or nullAn id that starts pm_.
subscriptionstring or nullThe subscription this payment renewed, for a payment made on a schedule. An id that starts sb_.
disputedbooleanWhether the buyer has disputed the payment. The dispute never changes its amounts.
descriptionstring or null
statement_descriptorstring or null
failure_codeenum or nullOne of card_declined, processing_error.
decline_codeenum or nullOne of generic_decline, insufficient_funds, do_not_honor, expired_card, incorrect_cvc, lost_card, stolen_card, fraudulent.
next_actionobject or null
next_action.typestringAlways "redirect_to_url".
next_action.redirect_to_urlobject
next_action.redirect_to_url.urlstring
metadatamap of strings
livemodeboolean
createdintegerUnix seconds.
{
  "id": "py_1a2B3c4D5e6F7g8H9i0J1k2L",
  "object": "payment",
  "amount": 4999,
  "amount_capturable": 0,
  "amount_captured": 4999,
  "amount_refunded": 0,
  "currency": "USD",
  "capture_method": "automatic",
  "status": "succeeded",
  "store": "st_1a2B3c4D5e6F7g8H9i0J1k2L",
  "customer": "cu_1a2B3c4D5e6F7g8H9i0J1k2L",
  "payment_method": "pm_1a2B3c4D5e6F7g8H9i0J1k2L",
  "subscription": null,
  "disputed": false,
  "description": "Order 1001",
  "statement_descriptor": "Example Shop",
  "failure_code": null,
  "decline_code": null,
  "next_action": null,
  "metadata": {
    "order": "1001"
  },
  "livemode": false,
  "created": 1762473600
}

POST /v1/payments

Charge a saved card or a card token, or authorize it with capture_method manual. A decline is a payment with status failed.

Scope
payments:write
Keys
Secret, or restricted with the scope below.
Idempotency-Key
Required. This endpoint moves money. See Idempotency.
Answers
201 with the Payment.

Parameters

NameInTypeRequiredAbout
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
amountintegerRequiredIn the currency's minor unit, such as cents for USD. More than 0. Up to 99999999.
currencystringRequiredThree capital letters, such as USD.
payment_methodstringOptionalA saved card to charge. Give this or token. An id that starts pm_.
tokenstringOptionalA card token (tok_) to charge instead of a saved card; customer is then required. The card is saved for the customer and the token is spent. An id that starts tok_.
customerstringOptionalAn id that starts cu_.
capture_methodenumOptionalOne of automatic, manual.
storestringOptionalAn id that starts st_.
descriptionstringOptionalUp to 500 characters.
statement_descriptorstringOptionalUp to 22 characters.
metadatamap of stringsOptionalKeys up to 40 characters, values up to 500.

Errors

Examples

curl https://api.kashupay.com/v1/payments \
  -H "Authorization: Bearer $KASHU_SECRET_KEY" \
  -H "Idempotency-Key: payments-create-1001" \
  -H "Content-Type: application/json" \
  -d '{"amount":4999,"currency":"USD","payment_method":"pm_1a2B3c4D5e6F7g8H9i0J1k2L","customer":"cu_1a2B3c4D5e6F7g8H9i0J1k2L"}'
const payment = await kashu("POST", "/v1/payments", {
  "amount": 4999,
  "currency": "USD",
  "payment_method": "pm_1a2B3c4D5e6F7g8H9i0J1k2L",
  "customer": "cu_1a2B3c4D5e6F7g8H9i0J1k2L"
}, { idempotencyKey: "payments-create-1001" });
console.log(payment.status);

GET /v1/payments

List payments, newest first.

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

Parameters

NameInTypeRequiredAbout
statusqueryenumOptionalOne of pending, requires_action, requires_capture, succeeded, failed, canceled.
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/payments?limit=3" \
  -H "Authorization: Bearer $KASHU_SECRET_KEY"
const list = await kashu("GET", "/v1/payments?limit=3");
console.log(list.has_more);

GET /v1/payments/{id}

Retrieve a payment.

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

Parameters

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

Errors

Examples

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

POST /v1/payments/{id}/capture

Capture an authorized payment, once, for at most the amount held. Without an amount, all of it.

Scope
payments:write
Keys
Secret, or restricted with the scope below.
Idempotency-Key
Required. This endpoint moves money. See Idempotency.
Answers
200 with the Payment.

Parameters

NameInTypeRequiredAbout
idpathstringRequiredAn id that starts py_.
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
amountintegerOptionalIn the currency's minor unit, such as cents for USD. More than 0. Up to 99999999.

Errors

Examples

curl https://api.kashupay.com/v1/payments/py_1a2B3c4D5e6F7g8H9i0J1k2L/capture \
  -H "Authorization: Bearer $KASHU_SECRET_KEY" \
  -H "Idempotency-Key: payments-capture-1001" \
  -H "Content-Type: application/json" \
  -d '{"amount":4999}'
const payment = await kashu("POST", "/v1/payments/py_1a2B3c4D5e6F7g8H9i0J1k2L/capture", {
  "amount": 4999
}, { idempotencyKey: "payments-capture-1001" });
console.log(payment.status);

POST /v1/payments/{id}/void

Release an authorized payment that has not been captured.

Scope
payments:write
Keys
Secret, or restricted with the scope below.
Idempotency-Key
Required. This endpoint moves money. See Idempotency.
Answers
200 with the Payment.

Parameters

NameInTypeRequiredAbout
idpathstringRequiredAn id that starts py_.
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

Send no body, or an empty JSON object.

Errors

Examples

curl https://api.kashupay.com/v1/payments/py_1a2B3c4D5e6F7g8H9i0J1k2L/void \
  -X POST \
  -H "Authorization: Bearer $KASHU_SECRET_KEY" \
  -H "Idempotency-Key: payments-void-1001"
const payment = await kashu("POST", "/v1/payments/py_1a2B3c4D5e6F7g8H9i0J1k2L/void", undefined, { idempotencyKey: "payments-void-1001" });
console.log(payment.status);