What is Idempotency?
An API call is idempotent if it has the same result no matter how many times the call is applied. When a request reaches a final status (Success or Failure), the system returns an identical result on subsequent attempts with the same idempotency identifier.Idempotency prevents accidental duplicate transactions when retrying requests after network timeouts or failures.
When to Use Idempotency
The primary use case is handling timeout errors:- You send a payment request
- Network issues cause a timeout before receiving a response
- You don’t know if the payment was processed
- You safely retry using the same idempotency key
- If the original request succeeded, you receive the same successful response
- If the original request failed, you receive the same failure response
- No duplicate payment is created
Idempotency Fields by API
Different APIs use different fields as idempotency keys:| API Endpoint | Idempotency Field | Purpose |
|---|---|---|
/v2/payments/pay | paymentRequestId | Prevents duplicate charges |
/v2/payments/refund | refundRequestId | Ensures single refund processing |
/v2/payments/retailPay | paymentRequestId | Prevents duplicate retail payments |
/v2/payments/linkPayCreate | paymentRequestId | Prevents duplicate link pay orders |
/v2/payments/createQrOrder | paymentRequestId | Prevents duplicate QR orders |
/v2/messages/sendPush | requestId | Returns same messageId for duplicates |
/v2/messages/sendInbox | requestId | Returns same messageId for duplicates |
Implementation Guidelines
Generate Unique Identifiers
Always generate unique, consistent identifiers for each operation:Retry Strategy
Best Practices
Example: Payment Retry
Important Considerations
Idempotency Window: Idempotency keys are typically valid for a limited time period (usually 24-48 hours). After this window, the key may be reused, but this is not recommended.