Idempotency
The required Idempotency-Key on every money request.
Networks fail after a request leaves. An Idempotency-Key lets you retry a request that moves
money without moving it twice.
Where it is required
Idempotency-Key is required on every request that moves money or stores a card:
| Endpoint |
|---|
POST /v1/payments |
POST /v1/payments/{id}/capture |
POST /v1/payments/{id}/refunds |
POST /v1/payments/{id}/void |
POST /v1/payment-instruments |
POST /v1/payment-instruments/{id}/charges |
Without the header, or with a blank one, the request is refused with 400
idempotency_key_required and nothing runs.
The key
- 1 to 255 visible ASCII characters (no spaces). Anything else is
400idempotency_key_invalid. - Case-sensitive:
Order-1andorder-1are two keys. - Scoped to your project and environment: the same key in test and live, or in two projects, never collides.
- Make it unique per operation you intend, such as
order-1001-charge-1. A UUID works too.
What a retry gets
The first request with a key runs and its answer is stored. A later request with the same key:
| When | Answer |
|---|---|
Same endpoint, same amount and currency | The original status and body, with Idempotent-Replayed: true. Nothing runs again: no second charge, no second card stored. |
Different amount or currency | 422 idempotency_key_mismatch |
| Another endpoint | 422 idempotency_key_reused |
| The first request is still running | 409 idempotency_key_in_use: retry in a few seconds |
A replay returns what the first request returned, including a 402 decline or a 202
unknown outcome. Other fields that differ (a description, metadata) don't matter: the stored
answer comes back.
When the key is freed
A request refused before it did anything, such as a 400, 401, 403, 404, 429 or a
422 validation error, doesn't keep the key: fix the request and send it again with the same
key. Everything else is stored: successes, 402 declines, 202 unknown outcomes, 409
duplicate_reference, 422 operation_declined, and 5xx errors (which may have happened
after money moved).
Stored answers are kept for 7 days. After that, the same key runs as a new request.
Retrying safely
Retry with the same key after a timeout, a dropped connection or a 5xx. Re-sign the
request with a fresh timestamp; the signature may also be the original one, since the same
signed bytes with the same key are accepted as a retry (see
Authentication).
Use a new key only for a new attempt you intend, such as after a decline when the buyer tries another card.