# cancelPayment

`POST /aps/api/v1/payments/cancelPayment`

The Acquiring Partner (ACQP) uses the **cancelPayment** API to proactively cancel a payment when no payment result is received after the payment expires, or when the ACQP has closed the payment already.  

A payment can be canceled before 00:15 UTC+8 of the T+1 day.

**Note**: In the following sections, the Mobile Payment Provider (MPP) is also known as PSP. For example, _pspId_ refers to the ID that identifies an MPP.

Structure

A message consists of a header and body. The following sections are focused on the body structure. For the header structure, see:

-   [Request header](api_overview.md#3mLq0)
-   [Response header](api_overview.md#YdmVS) 

**Note:** 

Set the data type of each field (except array) as String. This means that you must use double quotation marks (" ") to enclose the field value. Examples:

-   If the data type of a field is Integer and its value is 20, set it as "20".
-   If the data type of a field is Boolean and its value is true, set it as "true".

## Request parameters

#### paymentRequestId (String)

The request ID of the payment to be canceled, assigned by the ACQP to identify the original payment order.

**Note:** Required if the value of the _paymentId_ parameter is empty.

More information:

- This field is an API idempotency field.This parameter is used for idempotency control. For requests that are initiated with the same paymentRequestId, Alipay+ regards the requests as repeated and processes the requests only once.
- Maximum length: 64 characters

#### paymentId (String)

The ID of the payment to be canceled, assigned by Alipay+ to identify the original payment order.

**Note:** Required if the value of the _paymentRequestId_ parameter is empty.

More information:

- Maximum length: 64 characters

## Response parameters

#### result (Result, REQUIRED)

The result of the payment cancelation. If the value of the _result_._resultCode_ parameter is `SUCCESS`, the cancelation succeeds. See Result processing logic for details.

##### resultCode (String, REQUIRED)

The result code that indicates the detailed processing result.

More information:

- Maximum length: 64 characters

##### resultStatus (String, REQUIRED)

The result status that indicates the processing result. Valid values are:

-   `S`: Successful
-   `F`: Failed
-   `U`: Unknown

##### resultMessage (String)

The result message that describes the result code in detail.

More information:

- Maximum length: 256 characters

#### pspId (String)

The unique ID that is assigned by Alipay+ to identify an MPP.

**Note:**

Returned by Alipay+ if the value of the _result.resultStatus_ parameter is `S` and Alipay+ knows the related MPP ID.

More information:

- Maximum length: 64 characters

#### acquirerId (String)

The unique ID that is assigned by Alipay+ to identify an ACQP.

**Note:**

Returned by Alipay+ if the value of the _result.resultStatus_ parameter is `S`.

More information:

- Maximum length: 64 characters

More information

**Result processing logic**

For different results returned by Alipay+, take actions as below:

<table style="width:735px;outline:none;border-collapse:collapse;border:1px solid rgb(217, 217, 217)" class="lake-table"><colgroup><col width="67" span="1"><col width="208" span="1"><col width="168" span="1"><col width="292" span="1"></colgroup><tbody><tr style="height:33px"><td style="background-color:rgb(212, 238, 252);min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="0cec1a65b987582f5013dd7abd03fdd0" data-lake-id="bab753917c13ba73dfb38b7809e6186d" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><strong><span>result.resultStatus</span></strong></p></td><td style="background-color:rgb(212, 238, 252);min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="4947cbbf1ef92ae571301c495f2324e7" data-lake-id="8a4b719ab35414ec7a48830ef65d5374" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><strong><span>result.resultCode</span></strong></p></td><td style="background-color:rgb(212, 238, 252);min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="1babaa1f6fb0a9b8a9f6e96d1871435c" data-lake-id="b6affbbd29d10de41b3c545dbc24d616" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><strong><span>Cancellation status</span></strong></p></td><td style="background-color:rgb(212, 238, 252);min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="714cc9a456fbbf3b1f556c8d2ffc101f" data-lake-id="1a763ccf319a000b99159110747ffa05" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><strong><span>Further Actions</span></strong></p></td></tr><tr style="height:33px"><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="a5f96de777d0abec63d4d219051bdbff" data-lake-id="b1be5fcc453b4bed46438a9e841b6be1" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><code style="font-family:monospace;font-size:inherit;background-color:rgba(0, 0, 0, 0.06);padding:0px 2px;border:1px solid rgba(0, 0, 0, 0.08);border-radius:2px;line-height:inherit;overflow-wrap:break-word;text-indent:0px"><span>S</span></code></p></td><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="b993a5e945ca98b2a5f16a68d1560b9e" data-lake-id="3a9cc6250428db46ea6fbf738c1b60e0" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><code style="font-family:monospace;font-size:inherit;background-color:rgba(0, 0, 0, 0.06);padding:0px 2px;border:1px solid rgba(0, 0, 0, 0.08);border-radius:2px;line-height:inherit;overflow-wrap:break-word;text-indent:0px"><span>SUCCESS</span></code></p></td><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="f283b2cd9d6254af36ac060109943d7e" data-lake-id="829b8b6390115ffae7837fc9c71beda2" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><span>Cancellation succeeds</span></p></td><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="d38a1ee7c252a477e598e6c24095dd75" data-lake-id="1260182c4bcde424b9b72732e5d6f378" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><span>The merchant can reinitiate a payment request.</span></p></td></tr><tr style="height:33px"><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="bb6b7ac72fdbe9fa9088cfd0b65e6072" data-lake-id="a5f3b46ceb36350b7f462c4600afa255" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><code style="font-family:monospace;font-size:inherit;background-color:rgba(0, 0, 0, 0.06);padding:0px 2px;border:1px solid rgba(0, 0, 0, 0.08);border-radius:2px;line-height:inherit;overflow-wrap:break-word;text-indent:0px"><span>F</span></code></p></td><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="ffec1685c14eedf46f6d80e97cd7d5e8" data-lake-id="d2fcd93ab4fd56d7d540e47fd6fab874" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><span>Multiple possible values exist, such as </span></p><p id="u30224224" data-lake-id="6e12bb862ed26a3c709489a90a01e477" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><code style="font-family:monospace;font-size:inherit;background-color:rgba(0, 0, 0, 0.06);padding:0px 2px;border:1px solid rgba(0, 0, 0, 0.08);border-radius:2px;line-height:inherit;overflow-wrap:break-word;text-indent:0px"><span>ACCESS\_DENIED</span></code><span>, </span></p><p id="u44a508b6" data-lake-id="45c34e2ab55756a2bedcfa52e9b9905c" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><code style="font-family:monospace;font-size:inherit;background-color:rgba(0, 0, 0, 0.06);padding:0px 2px;border:1px solid rgba(0, 0, 0, 0.08);border-radius:2px;line-height:inherit;overflow-wrap:break-word;text-indent:0px"><span>KEY\_NOT\_FOUND</span></code><span>, etc.</span></p></td><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="40e4bf47c0e46b5035a1ee549bdc4df3" data-lake-id="b1e03113c1c30e04701940f2922bc613" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><span>Cancellation fails</span></p></td><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="2e02e4b4a3de2332d184c595d9079fcb" data-lake-id="93da111499914038c933b78f5184e645" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><span>Take actions according to the error code in </span><em><span>result.resultCode</span></em><span>. </span></p><p id="u59532d6c" data-lake-id="cdce357acf4eba16b9d52b2e7884e634" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><strong><span>Note</span></strong><span>: If the value of the </span><em><span>result.resultCode</span></em><span> parameter is </span><code style="font-family:monospace;font-size:inherit;background-color:rgba(0, 0, 0, 0.06);padding:0px 2px;border:1px solid rgba(0, 0, 0, 0.08);border-radius:2px;line-height:inherit;overflow-wrap:break-word;text-indent:0px"><span>CANCEL\_WINDOW\_EXCEED</span></code><span>, call the </span><a href="refund" target="\_blank"><span>refund</span></a><span> API. </span></p></td></tr><tr style="height:33px"><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="e15aa5c387c766f4a7733716c8927a97" data-lake-id="9158159eb9e9656315741f07b4159e07" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><code style="font-family:monospace;font-size:inherit;background-color:rgba(0, 0, 0, 0.06);padding:0px 2px;border:1px solid rgba(0, 0, 0, 0.08);border-radius:2px;line-height:inherit;overflow-wrap:break-word;text-indent:0px"><span>U</span></code></p></td><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="u504f0ff2" data-lake-id="7ea08818d391d8cbb75d51452cb317c7" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><span>Multiple possible values exist, such as </span></p><p id="u64dd844b" data-lake-id="493ff1337af979ecc30b0596a2eb3bc8" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><code style="font-family:monospace;font-size:inherit;background-color:rgba(0, 0, 0, 0.06);padding:0px 2px;border:1px solid rgba(0, 0, 0, 0.08);border-radius:2px;line-height:inherit;overflow-wrap:break-word;text-indent:0px"><span>ACCESS\_DENIED</span></code><span>, </span></p><p id="uc59e0754" data-lake-id="80b1db0954d8077df68706f4e7a707e1" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><code style="font-family:monospace;font-size:inherit;background-color:rgba(0, 0, 0, 0.06);padding:0px 2px;border:1px solid rgba(0, 0, 0, 0.08);border-radius:2px;line-height:inherit;overflow-wrap:break-word;text-indent:0px"><span>KEY\_NOT\_FOUND</span></code><span>, etc.</span></p></td><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="99f8e6faf8e44b3d65ed2dde99d1733f" data-lake-id="5926878c17da26ba09fa28ed7ed6b690" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><span>Unknown</span></p></td><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="affbd959f3bbabf61a4f88ccf91aa3ca" data-lake-id="8f00f69424a7811661399b5e4f39acdb" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><span>Use the same parameter to retry the cancelPayment request. </span></p><ul data-lake-id="8354d2c752960fe31799c655b5192323" lake-indent="0" style="list-style-type:disc;padding-left:23px;margin:0px;font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word"><li id="u192ae06e" data-lake-id="a3ad1357b9927a66c77f1cecc773854c"><span>In the first 60 seconds, you can retry the request with an interval of 5 to 10 seconds. </span></li><li id="ufe89350c" data-lake-id="0cb67aa04c34eed1857c433313466804"><span>After 60 seconds, you can still retry the request before 00:15 UTC+8 of T+1 day.</span></li><li id="u9c3060c1" data-lake-id="721705dc86bca479badbcb927338c268"><span>If you keep receiving the same result indicating the unknown status, contact </span><a href="mailto:connect\_support@service.alipay.com" target="\_blank"><span>connect\_support@service.alipay.com</span></a><span>.</span></li></ul></td></tr><tr style="height:33px"><td colspan="2" style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="a20d224c568e48b9d67847a2c66a8c01\_p\_0" data-lake-id="bbb1d090d90e47a4d8e42252df215c11" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><span>No result received&nbsp;after trying several times</span></p></td><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="uce42e1b2" data-lake-id="64214f0be4324808711ab1293ca32252" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><span>Unknown</span></p></td><td style="min-width:90px;font-size:14px;white-space:normal;overflow-wrap:break-word;border:1px solid rgb(217, 217, 217);padding:4px 8px;cursor:default"><p id="u62fc59b0" data-lake-id="a8a3e8e4d2048f2723a5cb6f34bc2c44" style="font-size:14px;color:rgb(38, 38, 38);line-height:1.74;letter-spacing:0.05em;outline-style:none;overflow-wrap:break-word;margin-top:0px;margin-bottom:0px"><span>Contact </span><a href="mailto:connect\_support@service.alipay.com" target="\_blank"><span>connect\_support@service.alipay.com</span></a><span>.</span></p></td></tr></tbody></table>

## Result/Error codes

| Code | Value | Message | Further action |
| --- | --- | --- | --- |
| SUCCESS | S | Success | The merchant can reinitiate a payment request. |
| ACCESS_DENIED | F | Access is denied. | It is recommended that you contact connect_support@service.alipay.com to troubleshoot the issue. |
| CANCEL_WINDOW_EXCEED | F | Exceed Cancel window. | Call the refund API to refund the payment. |
| INVALID_CLIENT | F | The client is invalid. | It is recommended that you contact connect_support@service.alipay.com to troubleshoot the issue. |
| INVALID_SIGNATURE | F | The signature is invalid. | Check whether the public key, signed message, and signature algorithm are as expected. |
| KEY_NOT_FOUND | F | The key is not found. | It is recommended that you contact connect_support@service.alipay.com to troubleshoot the issue. |
| MEDIA_TYPE_NOT_ACCEPTABLE | F | The server does not implement the media type that is acceptable to the client. | Use a media type that is accepted by Alipay+. |
| METHOD_NOT_SUPPORTED | F | The server does not implement the requested HTTPS method.	Ensure the HTTP method is POST. | Ensure the HTTP method is POST. |
| NO_INTERFACE_DEF | F | API is not defined. | Check whether the request URL is correct. Ensure that the endpoint of the called API is correct. |
| PARAM_ILLEGAL | F | Illegal parameters. For example, non-numeric input, invalid date. | Check whether the request parameters, including the header parameters and body parameters, are correct and valid. For more information about the parameters of each API, see the Structure section of the specific API reference topic. |
| PROCESS_FAIL | F | A general business failure occurred. Do not retry. | It is recommended that you contact connect_support@service.alipay.com to troubleshoot the issue. |
| REQUEST_TRAFFIC_EXCEED_LIMIT | U | The request traffic exceeds the limit. | Reduce the frequency of API calls. |
| UNKNOWN_EXCEPTION | U | An API call failed, which is caused by unknown reasons. | Try to recall the API. |

## Request

### ALIPAY, ALIPAY_HK, DANA, H5, DIRECT

```json
{
  "paymentRequestId": "20200101234567890000"
}
```

## Response

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