Alipay+ DocsAlipay+ Docs

Cancel a payment

The Acquiring Partner(ACQP) can cancel the payment by using the cancelPayment API.

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 is from T day to 00:15 UTC+8 of T+1 day, regardless of the payment status. The cancellable period is the only factor determining whether you are able to initiate a cancellation. If a payment exceeds the cancellable period, you need to initiate a refund instead.

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

Fee items and settlement: No fees are charged by Alipay+ for cancelled transactions. Cancelled 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+ Rules.

When to cancel a payment

For Merchant-presented Mode 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, or when you want to close the order before the payment expires for time-sensitive scenarios. In detail, you need to cancel the transaction in one of the following scenarios:

Scenarios

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_EXISTthat 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 Merchant-presented Mode Payment, the default expiry time is 3 minutes.

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 cancelled.
  • 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 connect_support@service.alipay.com.

No result received after trying several times

Unknown

Contact connect_support@service.alipay.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.