KashuDocs

Idempotency

A network error can leave you unsure whether a request reached Kashu. An idempotency key makes the retry safe. Send the request again with the same Idempotency-Key header, and Kashu answers with the result of the first request instead of doing the work twice.

Send a key with every write

Pick a key that names the operation, such as order-1001-charge, and store it with the order, so a retry sends the same key. A key is 1 to 255 printable ASCII characters. Keys belong to your account and mode, so your keys never meet another account's.

Endpoints that move money require a key, and answer 400 idempotency_key_missing without one:

GroupEndpointWhat it does
Payment methodsPOST /v1/payment_methodsSave a card for a customer from a single-use card token.
PaymentsPOST /v1/paymentsCharge a saved card or a card token, or authorize it with capture_method manual. A decline is a payment with status failed.
PaymentsPOST /v1/payments/{id}/captureCapture an authorized payment, once, for at most the amount held. Without an amount, all of it.
PaymentsPOST /v1/payments/{id}/voidRelease an authorized payment that has not been captured.
RefundsPOST /v1/refundsRefund part or all of a captured payment. Without an amount, all that is left.
SubscriptionsPOST /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.
SubscriptionsPOST /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.
SubscriptionsPOST /v1/subscriptions/{id}/resumeUndo a cancel scheduled for the end of the period. A canceled subscription cannot be resumed.
SubscriptionsPOST /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.
DisputesPOST /v1/disputes/{id}/evidenceSend evidence for a dispute. Not available yet: every request answers feature_unavailable.
DisputesPOST /v1/disputes/{id}/acceptAccept a dispute and give up the disputed amount. Not available yet: every request answers feature_unavailable.
Checkout sessionsPOST /v1/checkout_sessions/{id}/payPay a checkout session with a card token. Kashu's card form calls this for you.

On every other write the key is optional. Without one, Kashu makes a key for the request and returns it in the Idempotency-Key response header, so every write follows the same rules.

What a retry gets back

When a payment says processing

processing means Kashu is waiting for the card network's answer. It is a normal state, not an error. Do not make a new payment for the same order. Retry with the same key, read the payment, or wait for its webhook: the payment moves to succeeded or failed on its own.

A payment that ends failed took no money, so you may then charge again, with a new key.