/v2/payments/cancel
POST /v2/payments/cancel
The cancel
API is used to cancel a payment when the payment result does not return for a long time. You can also use the API to cancel a payment authorization after the authorization is completed.
To cancel a payment, you need to provide one of the following parameters:
paymentId
: The original payment ID of the payment request to be canceled. It is generated by Alipay when a merchant initiates the original payment.paymentRequestId
: The originalpaymentRequestId
of the payment request to be canceled.
Message structure
A message consists of a header and body. The following sections are focused on the body structure. For the header structure, see:
Request
Property | Data Type | Required | Description |
paymentId | String | No | The unique ID that is assigned by the wallet to identify a payment.
Max. length: 64 characters. |
paymentRequestId | String | No | The unique ID is assigned by a merchant to identify a payment request.
Max. length: 64 characters. |
extendInfo | String | No | The extension information that wallets and merchants want to describe. Max. length: 4096 characters. |
Response
Property | Data Type | Required | Description |
result | Yes | The request result, which contains information such as result status and error codes. | |
paymentId | String | No | The unique ID is assigned by the wallet to identify a payment. Max. length: 64 characters. |
paymentRequestId | String | No | The unique ID is assigned by a merchant to identify a payment request. Max. length: 64 characters. |
cancelTime | Datetime | No | The actual time when the payment cancellation process is completed. This property is returned only when the cancellation succeeds. The value follows the ISO 8601 standard. |
extendInfo | String | No | The extension information that wallets and merchants want to describe. Max. length: 4096 characters. |
Result process logic
In the response, the result.resultStatus
field indicates the result of processing a request. The following table describes each result status:
resultStatus | Decription |
S | The cancellation is successful. The corresponding
|
U | The status of the cancellation result is unknown. The corresponding
|
F | The cancellation fails. The corresponding
|
Error codes
Error codes are usually classified into the following categories:
- Common error codes are common across all mini program's APIs.
- API-specific error codes: are listed in the following table.
resultCode | resultStatus | resultMessage |
SUCCESS | S | Success |
CANCEL_WINDOW_EXCEED | F | The cancellation date is beyond the period that is agreed in the contract. |
ORDER_NOT_EXIST | F | The order does not exist. |
KEY_NOT_FOUND | F | The key is not found. |
CLIENT_INVALID | F | The client is invalid. |
INVALID_SIGNATURE | F | The signature is invalid. |
METHOD_NOT _SUPPORTED | F | The server does not implement the requested HTTP method. |
MEDIA_TYPE_NOT _ACCEPTABLE | F | The server does not implement the media type that can be accepted by the client. |
MERCHANT_BALANCE_NOT_ENOUGH | F | The merchant's balance is not enough. |
Samples
Request
{
"paymentId":"20191127190741010007013213123",
"paymentRequestId":"201231231313123123"
}
Response
{
"result": {
"resultCode":"SUCCESS",
"resultStatus":"S"
},
"paymentId":"20191127190741010007013213123",
"paymentRequestId":"201231231313123123",
"cancelTime":"2021-06-08T12:12:12+08:00"
}