KashuDocs

Subscriptions

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

EndpointWhat it does
POST /v1/subscriptionsBill a customer's saved card on a schedule. The first charge is made at once; it and every renewal arrive as payments that name the subscription.
GET /v1/subscriptionsList subscriptions, newest first.
GET /v1/subscriptions/{id}Retrieve a subscription.
POST /v1/subscriptions/{id}/cancelCancel a subscription at the end of its period, or now with at_period_end false. Either way nothing more is billed after it ends.
POST /v1/subscriptions/{id}/resumeUndo a cancel scheduled for the end of the period. A canceled subscription cannot be resumed.
POST /v1/subscriptions/{id}/charge_nowBill the subscription now if its next charge is due within 12 hours. Otherwise nothing is charged and it is returned unchanged.

The subscription object

FieldTypeAbout
idstringAn id that starts sb_.
objectstringAlways "subscription".
statusenumOne of pending, active, canceled, failed, processing.
customerstringAn id that starts cu_.
payment_methodstringAn id that starts pm_.
storestringAn id that starts st_.
amountintegerIn the currency's minor unit, such as cents for USD. More than 0.
currencystringThree capital letters, such as USD.
intervalenumOne of day, week, month, year.
interval_countintegerMore than 0.
descriptionstring or null
cancel_at_period_endboolean
current_period_startinteger or nullUnix seconds.
current_period_endinteger or nullUnix seconds.
next_billing_atinteger or nullUnix seconds.
canceled_atinteger or nullUnix seconds.
metadatamap of strings
livemodeboolean
createdintegerUnix seconds.
{
  "id": "sb_1a2B3c4D5e6F7g8H9i0J1k2L",
  "object": "subscription",
  "status": "active",
  "customer": "cu_1a2B3c4D5e6F7g8H9i0J1k2L",
  "payment_method": "pm_1a2B3c4D5e6F7g8H9i0J1k2L",
  "store": "st_1a2B3c4D5e6F7g8H9i0J1k2L",
  "amount": 4999,
  "currency": "USD",
  "interval": "month",
  "interval_count": 1,
  "description": "Order 1001",
  "cancel_at_period_end": false,
  "current_period_start": 1762473600,
  "current_period_end": 1762473600,
  "next_billing_at": 1762473600,
  "canceled_at": null,
  "metadata": {
    "order": "1001"
  },
  "livemode": false,
  "created": 1762473600
}

POST /v1/subscriptions

Bill a customer's saved card on a schedule. The first charge is made at once; it and every renewal arrive as payments that name the subscription.

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

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_.
payment_methodstringRequiredA saved card of the customer's. Every charge goes to it. An id that starts pm_.
amountintegerRequiredIn the currency's minor unit, such as cents for USD. More than 0. Up to 99999999.
currencystringRequiredThree capital letters, such as USD.
intervalenumRequiredOne of day, week, month, year.
interval_countintegerOptionalHow many intervals each period spans, 1 by default. A period is at most a year. At least 1. Up to 365.
storestringOptionalAn id that starts st_.
descriptionstringOptionalWhat the plan is called. The buyer may see it. Up to 200 characters.
metadatamap of stringsOptionalKeys up to 40 characters, values up to 500.

Errors

Examples

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

GET /v1/subscriptions

List subscriptions, newest first.

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

Parameters

NameInTypeRequiredAbout
customerquerystringOptionalAn id that starts cu_.
statusqueryenumOptionalOne of pending, active, canceled, failed.
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/subscriptions?limit=3" \
  -H "Authorization: Bearer $KASHU_SECRET_KEY"
const list = await kashu("GET", "/v1/subscriptions?limit=3");
console.log(list.has_more);

GET /v1/subscriptions/{id}

Retrieve a subscription.

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

Parameters

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

Errors

Examples

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

POST /v1/subscriptions/{id}/cancel

Cancel a subscription at the end of its period, or now with at_period_end false. Either way nothing more is billed after it ends.

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

Parameters

NameInTypeRequiredAbout
idpathstringRequiredAn id that starts sb_.
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
at_period_endbooleanOptionaltrue by default: the subscription runs to the end of the period it is in.

Errors

Examples

curl https://api.kashupay.com/v1/subscriptions/sb_1a2B3c4D5e6F7g8H9i0J1k2L/cancel \
  -H "Authorization: Bearer $KASHU_SECRET_KEY" \
  -H "Idempotency-Key: subscriptions-cancel-1001" \
  -H "Content-Type: application/json" \
  -d '{"at_period_end":false}'
const subscription = await kashu("POST", "/v1/subscriptions/sb_1a2B3c4D5e6F7g8H9i0J1k2L/cancel", {
  "at_period_end": false
}, { idempotencyKey: "subscriptions-cancel-1001" });
console.log(subscription.status);

POST /v1/subscriptions/{id}/resume

Undo a cancel scheduled for the end of the period. A canceled subscription cannot be resumed.

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

Parameters

NameInTypeRequiredAbout
idpathstringRequiredAn id that starts sb_.
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/subscriptions/sb_1a2B3c4D5e6F7g8H9i0J1k2L/resume \
  -X POST \
  -H "Authorization: Bearer $KASHU_SECRET_KEY" \
  -H "Idempotency-Key: subscriptions-resume-1001"
const subscription = await kashu("POST", "/v1/subscriptions/sb_1a2B3c4D5e6F7g8H9i0J1k2L/resume", undefined, { idempotencyKey: "subscriptions-resume-1001" });
console.log(subscription.status);

POST /v1/subscriptions/{id}/charge_now

Bill the subscription now if its next charge is due within 12 hours. Otherwise nothing is charged and it is returned unchanged.

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

Parameters

NameInTypeRequiredAbout
idpathstringRequiredAn id that starts sb_.
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/subscriptions/sb_1a2B3c4D5e6F7g8H9i0J1k2L/charge_now \
  -X POST \
  -H "Authorization: Bearer $KASHU_SECRET_KEY" \
  -H "Idempotency-Key: subscriptions-charge-now-1001"
const subscription = await kashu("POST", "/v1/subscriptions/sb_1a2B3c4D5e6F7g8H9i0J1k2L/charge_now", undefined, { idempotencyKey: "subscriptions-charge-now-1001" });
console.log(subscription.status);