# Cancel a payment

The payment can be cancelled within the agreed cancellable period, which is from the time when the transaction is initiated to 00:15 UTC+8 of T+1 day, regardless of the payment status.

# When to cancel a payment

The Acquiring Service Provider (ACQP) can call the [**cancelPayment**](../api_acq_tile/cancel_payment) API to cancel a payment in one of the following scenarios:

-   The merchant/ACQP cannot receive the payment result from Alipay+ for a long time, or cannot obtain the payment result via the **inquiryPayment** API.
-   The transaction is not completed after exceeding the maximum number of inquiries.

# How to cancel a payment

The following figure illustrates the flow of payment cancellation initiated by the ACQP:

![image.png](https://idocs-assets.marmot-cloud.com/storage/idocs87c36dc8dac653c1/1756286239721-98aa9a40-1836-4195-8966-ca380eb25e34.png)

The payment cancellation initiated by the ACQP contains the following steps:

1.  The ACQP submits the cancellation request to Alipay+ (step 1).
2.  Alipay+ returns the cancellation result to the ACQP (step 1.1).

To cancel a payment, you can call the [**cancelPayment**](../api_acq_tile/cancel_payment) 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:

-   The cancel request only works on the payment and cannot be used on a refund.
-   After you request a cancellation, you cannot change the order status to status other than cancelled. If the payment notification comes later than the cancellation response, the ACQP handles the payment result based on the cancellation response. If the cancellation fails, you need to retry the cancelPayment request until the cancellation succeeds.
-   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 | Multiple possible values exist, such as `ACCESS_DENIED` and `KEY_NOT_FOUND`. | Cancellation fails | Take actions according to the error message in _result.resultCode_. > **Note**: If the result.resultCode value returns as `CANCEL_WINDOW_EXCEED`，please call the [**refund**](../api_acq_tile/refund) API. |
| U | Multiple possible values exist, such as `REQUEST_TRAFFIC_EXCEED_LIMIT` and `UNKNOWN_EXCEPTION`. | 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](mailto:connect_support@service.alipay.com). |
| No result received after trying several times | No result received after trying several times | Unknown | Contact [connect\_support@service.alipay.com](mailto: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._

```json
{
 "paymentRequestId":"20200101234567897890"
}
```

or

```json
{
 "paymentId":"20190608114010800100188820200350000"
}
```

-   **Response from Alipay+ to the ACQP**

The ACQP receives a response indicating a successful cancellation.

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

# More information

For more information about how to use the **cancelPayment** API (such as the field description), see [**cancelPayment**](../api_acq_tile/cancel_payment).