# Cancel a payment

The Acquiring Service Provider (ACQP) can use the [**cancelPayment**](../api_acq_tile/cancel_payment) 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](../rules/rules).

# When to cancel a payment

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

| **Scenario** | **pay** **API** | **notifyPayment** **API** | **inquiryPayment** **API** |
| --- | --- | --- | --- |
| 1 | The returned parameter _paymentResult.resultStatus_ is`U`, or no result is received. | 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 | The returned parameter _paymentResult.resultStatus_ is`U`, or no result is received. | 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 Auto Debit, the default expiry time is 1 minute.

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_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:

-   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 _p__aymentResult.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` | Multiple possible values exist, such as `ACCESS_DENIED`, and `KEY_NOT_FOUND`. | Cancellation fails | Take actions according to the error code in the Result code section in [API reference for cancelPayment](../api_acq_tile/cancel_payment). > **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 [overseas\_support@service.alibaba.com](mailto:overseas_support@service.alibaba.com). |
| No result received after trying several times | No result received after trying several times | Unknown | Contact [overseas\_support@service.alibaba.com](mailto: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._

```plaintext
{
 "paymentRequestId":"20200101234567897890"
}
```

```plaintext
{
 "paymentId":"20190608114010800100188820200350000"
}
```

**Response from Alipay+ to the ACQP**

The ACQP receives a response indicating a successful cancellation.

```plaintext
{
 "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 the [**cancelPayment**](../api_acq_tile/cancel_payment) API.