After making a payment, further actions might be required, such as canceling, and refund. This page illustrates when to use the cancel and refund processes.
#Refund a payment
A merchant can refund a payment by using refund (
/v1/payments/refund) API and the paymentId that is returned from the payAPI.
Request URL: https://open-na.alipay.com/ams/sandbox/api/v1/payments/refund.
Set the value of paymentId to the value of paymentId that was from the response of the payment request, which is 071329156697640993635741494609211863FOkUAZHdoQ201908280000008675.
#Cancel a transaction
You can cancel a transaction if the transaction encounters technical issues during making the payment. The cancel (
v1/payments/cancel) API can be used to roll back all the actions performed in the Alipay system regarding the specific transaction. The cancellable period is specified in the contract. The cancellation cannot be performed if it is not within the agreed cancellable period. Use the same paymentId that is used in the payment API to cancel the payment transaction.
- Sandbox environment: https://open-na.alipay.com/ams/sandbox/api/v1/payments/cancel
- Production environment: https://open-na.alipay.com/ams/api/v1/payments/cancel
For a payment transaction, the merchant must get a confirmative result status of the payment, which is
F. Otherwise, the cancel API needs to be called. For example, during the payment process of a transaction:
- If the merchant receives a
Uresult status, the merchant needs to repeat the inquiryPayment API request until gets the confirmative payment status, either
CANCELED. If the merchant cannot get any of those payment status before timeout, the transaction must be canceled.
- If a network issue occurs, and the merchant cannot get any response from Alipay, the merchant must call the cancel API to ensure that the transaction is canceled and the payment result is consistent.
Merchant must get a result status of
F for the cancel API response:
S: indicates that the cancellation was successful.
F: a system alert is to be triggered after getting a resultStatus of
F. Investigate the root cause. If the root cause is fixed and the order still exists in the Alipay system, the merchant can retry the cancel API until a result of
S is obtained.
U: the merchant needs to call the cancel API with the same parameters multiple times after getting a resultStatus of
U, until a result of
Fis obtained. If
F is not returned after the maximum number of retries, the system alarm will be triggered and the merchant must investigate and solve the problem.
- The merchant might implement the store and forward logic in the gateway. If the cancel request reaches to gateway before the payment API request, the cancel request should not be relayed to the next hop.
- When the cancellation is not allowed, the merchant needs to try the refund service.
- Cancelation is allowed before the cancelation window expires, which is 15 minutes after the transaction time.