/v1/payments/cancel

POST /v1/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 original paymentRequestId 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. paymentId and

paymentRequestId cannot both be Null. paymentId and paymentRequestId exists one-to-one correspondence.

Max. length: 64 characters.

paymentRequestId

String

No

The unique ID is assigned by a merchant to identify a payment request.

paymentRequestId and

paymentId cannot both be

Null. Special characters are not supported. When

paymentRequestId and

paymentId are provided at the same time, paymentId takes precedence.

Max. length: 64 characters.

Response

Property

Data Type

Required

Description

result

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

String

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.

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 result.resultCodeis "SUCCESS" and the 

result.resultMessage is "Success".

U

The status of the cancellation result is unknown. 

The corresponding result.resultCode is UNKNOWN_EXCEPTION, and 

result.resultMessage  is "An API calling is failed, which is caused by unknown reasons". For details, see the Common error codes section.

F

The cancellation fails. The corresponding result.resultCode  and

result.resultMessage may vary based on different situations. For details, see the Error codes section.

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

MSG_PARSE_ERROR

F

Message parsed error.

FUNCTION_NOT_MATCH

F

Function parameter does not match API.

INVALID_CLIENT

F

Invalid client.

INVALID_SIGNATURE

F

Signature is invalid.

INVALID_CLIENT_STATUS

F

Invalid client status.

ORDER_NOT_EXIST

F

The order doesn't exist.

Samples

Request

copy
{
  "paymentId": "20221124111212800100166473700277756"
}

Response

copy
{
  "result": {
    "resultCode": "SUCCESS",
    "resultStatus": "S",
    "resultMessage": "Success"
  },
  "paymentId": "20221124111212800100166473700277756",
  "cancelTime": "2022-11-24T19:04:30+03:00",
  "paymentRequestId": "rrIX-vONE-HiNM-QLMJ-emWN-sFlC-JX"
}