Alipay, China's leading third-party online payment solutionAlipay, China's leading third-party online payment solutionDOCS

      Payment Cancellation

      URL: /v1/payments/cancel


      Use this interface to cancel a payment if the payment result is not returned for a long time, or to cancel a payment authorization after the authorization is completed.


      #Sample

      In the following example, a user wanted to buy a product in the Apple store. After the merchant initiating a payment request, the payment result was not returned for a long time. Therefore, the user decided to abandon the payment process. The merchant initiated the payment cancellation. The use of Payment Cancel interface consists of the following steps:


      1. Merchant sends the payment cancel request to Alipay.

      copy
      {
          "paymentId":"20190612184010800100188820200355884"
      }


      2. Alipay returns the cancellation result to the merchant.

      copy
      {
          "result": 
          {
              "resultCode":"SUCCESS",
              "resultStatus":"S",
              "resultMessage":"success"
          },
          "paymentRequestId":"pay_2089760038715669_202775745075669",
          "paymentId":"20190612184010800100188820200355884",
          "cancelTime":"2019-06-12T19:07:11+08:00"
      }


      #Structure

      #Request parameters

      No.

      Field

      Description

      1

      paymentId

      OPTIONAL String (64)

      The unique ID that is assigned by Alipay to identify a payment. A one-to-one correspondence between paymentId and paymentRequestId exists.

      2

      paymentRequestId

      OPTIONAL String (64)

      The unique ID that is assigned by a merchant to identify a payment request. Special characters are not supported. If both paymentRequestId and paymentId are provided, paymentId takes precedence.


      #Response parameters

      No.

      Field

      Description

      1

      result

      MANDATORY Result

      The request result, which contains information related to the request result, such as status and error codes.

      2

      paymentId

      OPTIONAL String (64)

      The unique ID that is assigned by Alipay to identify a payment

      3

      paymentRequestId

      OPTIONAL String (64)

      The unique ID that is assigned by a merchant to identify a payment request. Special characters are not supported.

      4

      cancelTime

      OPTIONAL Datetime

      The actual execution completion time of the payment cancellation process, that is, the date and time when the payment cancellation succeeds. The value follows the ISO 8601 standard. This parameter is returned only when the cancellation succeeds.

       

      #More information

      To cancel the payment, you must provide one of the following parameters:

      • paymentId: The original payment ID of the payment request to be cancelled, generated by Alipay when the merchant initiates the original payment.
      • paymentRequestId: The original paymentRequestId of the payment request to be cancelled.  


      #Result

      #Result process logic

      For different request results, different actions are to be performed. See the following list for details:

      • If the value of result.resultStatus is S, the cancellation succeeds.

      If the value of result.resultStatus is F, the cancellation fails. See the returned error code and determine further actions.

      • If the value of result.resultStatus is U, the cancellation result is unknown. Use the same request parameters to retry the cancellation request.
      • If no response is returned, use the same request parameters to retry the cancellation request.


      #Result code

      This section helps you identify and resolve problems. See the following table for details: 

      No.resultCoderesultStatusresultMessage

      1

      SUCCESS

      S

      Success

      2

      CANCEL_WINDOW_EXCEED

      F

      The cancellation date exceeds the period during which cancellation is supported. The period is agreed in the contract.

      3

      ORDER_NOT_EXIST

      F

      The order doesn't exist.

      4

      PROCESS_FAIL

      F

      A general business failure occurred. Don't retry.

      5

      PARAM_ILLEGAL

      F

      Illegal parameters exist. For example, a non-numeric input, or an invalid date.

      6

      KEY_NOT_FOUND

      F

      The key is not found.

      7

      ACCESS_DENIED

      F

      Access denied.

      8

      REQUEST_TRAFFIC_EXCEED_LIMIT

      U

      The request traffic exceeds the limit.

      9

      API_INVALID

      F

      API is invalid or not active.

      10

      CLIENT_INVALID

      F

      The client is invalid.

      11

      SIGNATURE_INVALID

      F

      The signature is invalid.

      12

      METHOD_NOT_SUPPORTED

      F

      The server does not implement the requested HTTP method.

      13

      MEDIA_TYPE_NOT_ACCEPTABLE

      F

      The server does not implement the media type that is acceptable to the client.

      14

      UNKNOWN_EXCEPTION

      U

      An API calling is failed, which is caused by unknown reasons.