Cancel

After the buyer places an order, you can close that order using the cancel API within a limited period. Transactions can be canceled at any time from the order placement until 00:15 (GMT+8) on T+1 day.

Before issuing a cancellation, ensure to take note of the following information:

  • If a transaction is canceled before the payment is completed, the buyer will be unable to proceed with the payment.
  • If a transaction is canceled after the payment is completed, funds will be refunded to the buyer’s account.
  • Partial cancellation is not allowed. The entire order will be canceled when a transaction cancellation request is initiated.

Integration steps

Step 1: Initiate a cancellation request

Call the cancel API to cancel a single transaction by passing one of the following IDs:

Parameter name

Required?

Description

paymentId

No

The unique transaction ID returned by Antom when an order is placed.

paymentRequestId

No

The unique request ID assigned by the merchant when an order is placed.

The code below shows a sample of calling the cancel API:

  • When using paymentRequestId
copy
public static void payCancel() {
    AlipayPayCancelRequest alipayPayCancelRequest = new AlipayPayCancelRequest();

    // replace with your paymentRequestId
    alipayPayCancelRequest.setPaymentRequestId("yourPaymentRequestId");

    AlipayPayCancelResponse alipayPayCancelResponse = null;
    try {
        alipayPayCancelResponse = CLIENT.execute(alipayPayCancelRequest);
    } catch (AlipayApiException e) {
        String errorMsg = e.getMessage();
        // handle error condition
    }
}
  • When using paymentId
copy
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
    }
}

The following code shows a sample of the request message:

copy
{
  "paymentId": "2019061218401080010018882020035XXXX"
}

{
  "paymentRequestId": "paymentRequestIdXXXX"
}

Step 2: Obtain the cancellation result

After calling the cancel API, Antom returns a cancellation response through the result.resultStatus parameter:

copy
{
  "result": {
    "resultCode": "SUCCESS",
    "resultStatus": "S",
    "resultMessage": "Success"
  },
  "paymentRequestId": "pay_2089760038715669_20277574507XXXX",
  "paymentId": "2019061218401080010018882020035XXXX",
  "cancelTime": "2019-06-12T19:07:11+08:00"
}

The table below shows the possible values of result.resultStatus returned in the response. Handle the result according to the guidance provided:

result.resultStatus

Message

Further action

S

Cancellation is successful.

No further action is needed.

U

Cancellation result is unknown.

Retry the API call with the original request. If the issue persists, contact Antom Technical Support.

F

Cancellation failed.

See Result/Error codes of the cancel API for troubleshooting.

Notes:

  • If no response is received, it may indicate a network timeout. Retry the API call with the original request. If the issue persists, contact Antom Technical Support.
  • Transactions with prior refunds (full or partial) cannot be canceled. Canceling such transactions returns the error code, PROCESS_FAIL.
  • After cancellation, even if you receive an asynchronous notification of payment success, the transaction status in your system should still be maintained as CANCELLED. You need to properly handle the concurrent processing logic of calling the cancel API and payment success notification. It is recommended that you control the locking logic to prevent payment success and cancellation from taking effect at the same time on the merchant side.