Alipay+ DocsAlipay+ Docs

Cancel a payment

The Acquiring Service Provider (ACQP) can use the cancelPayment API to cancel a payment when no payment result is received after the payment expires, or when the ACQP closes the payment before receiving the payment result.

The following list introduces more information about the payment cancellation service that is provided by Alipay+:

Cancellable period: You (the ACQP) can cancel a payment within the agreed cancellable period, which ends at 00:15 UTC+8 of T+1 day, regardless of the payment status.

Cancellable amount: The payment can be canceled only in the full amount.

Fee items and settlement: No fees are charged by Alipay+ for canceled transactions. Canceled transactions do not proceed to the settlement stage and are not included in the clearing and settlement files. The current policies on fee items are subject to adjustment according to Alipay+ Core Rules.

When to cancel a payment

You usually need to cancel the payment when you cannot obtain the final payment status (success or failure) from any of the following two APIs within the payment expiry time. In detail, you need to cancel the payment in one of the following scenarios:

Scenario

notifyPayment API

inquiryPayment API

1

No notification is received within the payment expiry time.

You keep calling the inquiryPayment API until the payment is expired, or until the maximum number of inquiries is exceeded, but the returned parameter paymentResult.resultStatus remains U, or no result is received.

2

No notification is received within the payment expiry time.

You keep calling the inquiryPayment API until the payment is expired, or until the maximum number of inquiries is exceeded, but the returned parameter paymentResult.resultCode remains ORDER_NOT_EXIST, which indicates the payment order does not exist.

Note: The payment expiry time is usually specified by the ACQP with the parameter paymentExpiryTime in the pay API. The specified expiry time must be shorter than the default expiry time set by Alipay+, otherwise the default expiry time takes effect. For Cashier Payment, the default expiry time is 10 minutes.

On the other hand, if you want to close the payment before receiving the payment result, you also need to cancel the payment.

How to cancel a payment

To cancel a payment, you can call the cancelPayment API. You can confirm whether the cancellation succeeds by the synchronous result returned by Alipay+.

Processing logic

When using the cancelPayment API, you need to take the following things into consideration:

  • After you initiate a cancellation, you cannot change the order status to status other than canceled.
  • If you initiate a cancellation on a successful transaction, the parameter paymentResult.resultStatus is changed to F, and paymentResult.resultCode is changed to ORDER_IS_CLOSED. If you initiate a cancellation on a failed transaction, the parameters paymentResult.resultStatus and paymentResult.resultCode remain the same before the cancellation is initiated.
  • If payment notification comes later than the cancellation response, handle the payment result based on the cancellation response.
  • You might receive different results from Alipay+, follow the instructions below to handle the result:

result.resultStatus

result.resultCode

Cancellation status

Further Actions

S

SUCCESS

Cancellation succeeds

The merchant can reinitiate a payment request.

F

...

Cancellation fails

Take actions according to the error code in Result/Error codes in API reference for cancelPayment.

Note: If the result.resultCode value returns as

CANCEL_WINDOW_EXCEED, please call the refund API.

U

...

Unknown

Use the same parameter to retry the cancelPayment request.

  • In the first 60 seconds, you can retry the request with an interval of 5 to 10 seconds.
  • After 60 seconds, you can retry the request at least 10 times, with an interval of 5 minutes.
  • If keep receiving the result that indicates the status is U, contact overseas_support@service.alibaba.com.

No result received after trying several times

Unknown

Contact overseas_support@service.alibaba.com.

Sample

The following sample shows the request and response when you call the cancelPayment API.

Request from the ACQP to Alipay+

The ACQP can send the request with the parameter paymentRequestId or paymentId.

copy
{
 "paymentRequestId":"20200101234567897890"
}

or

copy
{
 "paymentId":"20190608114010800100188820200350000"
}

Response from Alipay+ to the ACQP

The ACQP receives a response indicating a successful cancellation.

copy
{
 "acquirerId": "1111088000000000002",
 "pspId":"1022172000000000001",
 "result": {
    "resultCode":"SUCCESS",
    "resultStatus":"S",
    "resultMessage":"success"
  }
}

Related links

For more information about how to use the cancelPayment API (such as the field description), see cancelPayment.