Cancel
After the buyer places an order, you can cancel the transaction within a specific expiration time using the cancel API. The expiration time for cancellation, fees, and other details depend on the contract with the acquirer. Currently, only full cancellations are supported while partial cancellations are not available.
For Antom, please refer to the rules for cancellations in Cancel.
How to cancel a transaction
- Initiate a cancellation request
- Obtain the cancellation result
Step 2: Initiate a cancellation request
You can initiate the cancellation of a single transaction using the cancel AP. The following sample code shows how to call the cancel API:
public static void payCancel() {
AlipayPayCancelRequest alipayPayCancelRequest = new AlipayPayCancelRequest();
// replace with your paymentId
alipayPayCancelRequest.setPaymentId("yourPaymentId");
AlipayPayCancelResponse alipayPayCancelResponse = null;
try {
alipayPayCancelResponse = CLIENT.execute(alipayPayCancelRequest);
} catch (AlipayApiException e) {
String errorMsg = e.getMessage();
// handle error condition
}
}
You must pass in one of the following parameters in your request:
Parameter name | Whether required | Description |
paymentId | No | The unique identifier that APO assigns to a transaction. |
paymentRequestId | No | The unique identifier that you assign to a request. |
Table 1. Details of the request parameters of the cancel API
The following shows the sample code of a request:
{
"paymentId": "2019061218401080010018882020035XXXX"
}
{
"paymentRequestId": "paymentRequestIdXXXX"
}
Step 2: Obtain the cancellation result
After calling the cancel API, APO will return the cancellation result through the result.resultStatus parameter in the response:
{
"cancelTime": "2019-06-12T19:07:11+08:00",
"paymentId": "2019061218401080010018882020035XXXX",
"paymentRequestId": "pay_2089760038715669_20277574507XXXX",
"result": {
"resultCode": "SUCCESS",
"resultMessage": "Success",
"resultStatus": "S"
}
}
result.resultStatus | Message | Further actions |
| Indicates that the cancellation is successful. | Please note that the buyer will be able to proceed with completing the payment if the payment is not submitted when the cancel API is called. |
| Indicates that the cancellation failed. | You can handle the situation according to the error codes. |
| Indicates that the cancellation result is unknown. | Use the same paymentId or paymentRequestId to try again. Please contact APO technical support if the problem persists. |
Table 2. Explanation of result.resultStatus
Notes:
- If you did not receive a response message, it might be due to a network timeout. Please use the same paymentId or paymentRequestId to try again. Please contact APO technical support if the problem persists.
- Transactions that have already been refunded (including full refunds and partial refunds) do not support cancellation. Trying to cancel a refunded transaction will result in the error code
PROCESS_FAIL
.- Even if a successful payment asynchronous notification is received after the transaction is canceled, the transaction status in your system will remain as
CANCELLED
.- Card payments do not support cancellation during capture or after capture is successful.
Common Questions
Q: Can an order be canceled after it has been successfully captured?
A: Once an order has been captured, cancellation is not supported. Instead, you can initiate a refund for the captured order.
Q: Will there be an asynchronous notification for cancellation?
A: Currently, the result of the cancellation is returned synchronously, and asynchronous notifications are not supported.
Q: What is the expiration time for cancellation?
A: The expiration times depends on the acquirers, please reach out to the respective acquirer.