KashuDocs

Payment methods

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

EndpointWhat it does
POST /v1/payment_methodsSave a card for a customer from a single-use card token.
GET /v1/payment_methodsList a customer's saved cards, newest first.
GET /v1/payment_methods/{id}Retrieve a payment method.
POST /v1/payment_methods/{id}/detachDetach a saved card from its customer. It can no longer be charged.

The payment method object

FieldTypeAbout
idstringAn id that starts pm_.
objectstringAlways "payment_method".
typeenumOne of card.
statusenumOne of active, detached, processing, failed.
customerstring or nullAn id that starts cu_.
cardobject or null
card.brandstring
card.last4string
card.exp_monthinteger or null
card.exp_yearinteger or null
card.fundingenumOne of credit, debit, prepaid, unknown.
card.countrystring or null
livemodeboolean
createdintegerUnix seconds.
{
  "id": "pm_1a2B3c4D5e6F7g8H9i0J1k2L",
  "object": "payment_method",
  "type": "card",
  "status": "active",
  "customer": "cu_1a2B3c4D5e6F7g8H9i0J1k2L",
  "card": {
    "brand": "visa",
    "last4": "4242",
    "exp_month": 12,
    "exp_year": 2030,
    "funding": "credit",
    "country": "US"
  },
  "livemode": false,
  "created": 1762473600
}

POST /v1/payment_methods

Save a card for a customer from a single-use card token.

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

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
customerstringRequiredAn id that starts cu_.
tokenstringRequiredA card token (tok_) from Kashu's card form. This request spends it. An id that starts tok_.

Errors

Examples

curl https://api.kashupay.com/v1/payment_methods \
  -H "Authorization: Bearer $KASHU_SECRET_KEY" \
  -H "Idempotency-Key: payment-methods-create-1001" \
  -H "Content-Type: application/json" \
  -d '{"customer":"cu_1a2B3c4D5e6F7g8H9i0J1k2L","token":"tok_1a2B3c4D5e6F7g8H9i0J1k2L"}'
const paymentMethod = await kashu("POST", "/v1/payment_methods", {
  "customer": "cu_1a2B3c4D5e6F7g8H9i0J1k2L",
  "token": "tok_1a2B3c4D5e6F7g8H9i0J1k2L"
}, { idempotencyKey: "payment-methods-create-1001" });
console.log(paymentMethod.status);

GET /v1/payment_methods

List a customer's saved cards, newest first.

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

Parameters

NameInTypeRequiredAbout
customerquerystringRequiredAn 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/payment_methods?customer=cu_1a2B3c4D5e6F7g8H9i0J1k2L&limit=3" \
  -H "Authorization: Bearer $KASHU_SECRET_KEY"
const list = await kashu("GET", "/v1/payment_methods?customer=cu_1a2B3c4D5e6F7g8H9i0J1k2L&limit=3");
console.log(list.has_more);

GET /v1/payment_methods/{id}

Retrieve a payment method.

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

Parameters

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

Errors

Examples

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

POST /v1/payment_methods/{id}/detach

Detach a saved card from its customer. It can no longer be charged.

Scope
payment_methods: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 Payment method.

Parameters

NameInTypeRequiredAbout
idpathstringRequiredAn id that starts pm_.
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/payment_methods/pm_1a2B3c4D5e6F7g8H9i0J1k2L/detach \
  -X POST \
  -H "Authorization: Bearer $KASHU_SECRET_KEY"
const paymentMethod = await kashu("POST", "/v1/payment_methods/pm_1a2B3c4D5e6F7g8H9i0J1k2L/detach");
console.log(paymentMethod.status);