Idempotency-Key header to every payment request, the API guarantees that submitting the same key more than once will return the original result — no matter how many times you retry.
What Is Idempotency?
An operation is idempotent when performing it multiple times produces the same outcome as performing it once. In the context of CertoPay, if you send aPOST /api/payment-gateway/process request and receive no response (timeout, network drop, 5xx error), you cannot know whether the charge was created or not. Retrying without an Idempotency-Key risks a duplicate charge.
When you include an Idempotency-Key:
- The first request is processed normally and the result is stored.
- Any subsequent request with the same key receives the stored result immediately — the charge is not processed again.
- A different key always triggers a brand-new charge attempt.
Idempotency protection applies specifically to
POST /api/payment-gateway/process. Always include the header on every call to this endpoint.Key Lifecycle: 24-Hour Window
EachIdempotency-Key is valid for 24 hours from the time of the first request that used it.
| Period | Behavior |
|---|---|
| Within 24 hours | Same key → returns cached original result |
| After 24 hours | Key expires; the same UUID can be safely reused for a new charge attempt |
How to Generate an Idempotency Key
Use a UUID v4 — a randomly generated, universally unique identifier. Generate one key per charge attempt and store it alongside the order record in your database before making the request.Retry Strategy
Follow these steps every time you callPOST /api/payment-gateway/process:
Generate a UUID v4 key before the first attempt
Create the key, save it to your database alongside the pending order, then make the request with the
Idempotency-Key header set.On timeout or 5xx error, retry with the SAME key
A timeout or server error means the outcome is unknown. Retry the identical request body with the exact same key. CertoPay will either return the original result (if the first attempt succeeded) or process the charge for the first time (if it did not).
For a genuinely new charge, generate a NEW key
If the customer is making a second, separate purchase — or if the previous charge was confirmed as failed and you want to start fresh — generate a brand-new UUID v4. Never reuse a key across different orders or amounts within its 24-hour validity window.
Full Request Example
Idempotency-Key header is sent alongside your X-Api-Key authentication header. Both are required for every call to the process endpoint.
Common Mistakes
| Scenario | Key to use |
|---|---|
| Retry after timeout | Same key |
| Retry after 5xx error | Same key |
| New purchase by the same customer | New key |
| Same purchase, different amount | New key |
| Re-attempting after 24-hour expiry | Same key is safe, or generate a new one |