# Idempotency

An API call is idempotent if the action is performed only once no matter how many times the API call is retried.

Idempotency helps to avoid unwanted duplication in case of failures and retries. For example, idempotency can guarantee that the payment is charged only once if the same API payment call is retried multiple times in the case of a timeout error.

In Alipay+, API idempotency is enabled by an idempotency field. Idempotency fields stay unique without a time limit.

# Idempotency fields

The following tables list the APIs that need idempotency control, the idempotency parameters of APIs, and key parameters that are checked for consistency in idempotency control. For detailed information, see the specific API chapter.

## Direction: ACQP > Alipay+

For APIs that are used by the ACQP to call Alipay+, Alipay+ decides the idempotency parameters and key parameters that are checked for consistency. The following table lists the APIs that need idempotency control, idempotency parameters of APIs, and key parameters that are checked for consistency in idempotency control:

| **Interface** | **Idempotency p****arameter** | **Key parameter to check consistency** |
| --- | --- | --- |
| [pay (User-presented Mode Payment)](pay_user_presented_mode) | _paymentRequestId_ | _paymentAmount_, _paymentMethod.paymentMethodType_, and _order.orderAmount_ |
| [pay (Merchant-presented Mode Payment -Entry Code)](pay_entry_code) | _paymentRequestId_ | _paymentAmount_, _paymentMethod.paymentMethodType_, and _order.orderAmount_ |
| [pay (Merchant-presented Mode Payment - Order Code)](pay_order_code) | _paymentRequestId_ | _paymentAmount_, _paymentMethod.paymentMethodType_, and _order.orderAmount_ |
| [pay (Cashier Payment)](pay_cashier) | _paymentRequestId_ | _paymentAmount_, _paymentMethod.paymentMethodType_, and _order.orderAmount_ |
| [pay (Auto Debit)](pay_auto_debit) | _paymentRequestId_ | _paymentAmount_, _paymentMethod.paymentMethodType_, and _order.orderAmount_ |
| [refund](refund) | _refundRequestId_ | _refundAmount_ and _paymentRequestId_, or _refundAmount_ and _paymentId_ |
| [cancelPayment](cancel_payment) | _paymentRequestId_ | N/A |
| [prepare](prepare) | _authClientId_ and _referenceAgreementId_ > **Note**: _authClientId_ and _referenceAgreementId_ are jointly used for idempotency control. | ALL the other request parameters |
| [cancelToken](cancel_token) | _accessToken_ | N/A |
| [registration](registration) | _registrationRequestId_ | N/A |
| [declare](declare) | _customsDeclarationRequestId_ | N/A |
| [responseRetrieval](response_retrieval) | _disputeRequestId_ | N/A |
| [responseEscalation](response_escalation) | _disputeRequestId_ | _refundType_ and _refundAmount_ |

## Direction: Alipay+ \> ACQP

For APIs that are used by Alipay+ to call the ACQP, the ACQP decides the idempotency parameters and key parameters that are checked for consistency. The following table lists the APIs that need idempotency control, the idempotency parameters of APIs, and recommended key parameters that are checked for consistency in idempotency control:

| **Interface** | **Idempotency p****arameter** | **Key parameter to check consistency** |
| --- | --- | --- |
| [userInitiatedPay](pay_private_order_code) | _codeValue_ | _customerId_ |
| [initiateRetrieval](initiate_retrieval) | _disputeRequestId_ | _paymentRequestId_ |
| [initiateEscalation](initiate_escalation) | _disputeRequestId_ | _paymentRequestId_ |