Why it matters
How it works
The first request carrying a given Idempotency-Key is processed and cached. Any retry with the same key returns the cached result — the customer is never charged twice.
1
Generate a unique key
For each payment, generate a UUID v4 as your idempotency key.
2
Send the key with your request
Add the
Idempotency-Key header to your payment creation request:3
Handle the response
- First request → Creates the transaction normally
- Subsequent requests with the same key → Returns the existing transaction without creating a new one
Key format
Best practices
Use UUID v4
UUID v4 guarantees sufficient uniqueness. Avoid time-based or sequential keys.
One key per operation
Create a new key for each new operation. Reuse the same key only for retries of the same request.
Store the key
Save the idempotency key alongside the transaction in your database for audit trails.
Don't reuse across operations
Using the same key for different operations may return unexpected results.

