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

      cancel

      Use the cancel API 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. 

      Request parameters

      paymentId String(64)Optional

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

      paymentRequestId String(64)Optional

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

      Response parameters

      result ResultRequired

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

      resultCode String(64)Required
      Result code
      resultStatus StringRequired

      Result status. Possible values are:   

      • S: Indicates that the result status is successful. 
      • F: Indicates that the result status is failed. 
      • U: Indicates that the result status is unknown.
      resultMessage String(256)Optional
      Result message
      paymentId String(64)Optional
      The unique ID that is assigned by Alipay to identify a payment
      paymentRequestId String(64)Optional
      The unique ID that is assigned by a merchant to identify a payment request. Special characters are not supported.
      cancelTime DatetimeOptional

      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 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/Error codes

      CodeValueMessage
      SUCCESSSSuccess
      CANCEL_WINDOW_EXCEEDFThe cancellation date exceeds the period during which cancellation is supported. The period is agreed in the contract.
      ORDER_NOT_EXISTFThe order does not exist.
      PROCESS_FAILFA general business failure occurred. Do not retry.
      PARAM_ILLEGALFIllegal parameters exist. For example, a non-numeric input, or an invalid date.
      KEY_NOT_FOUNDFThe key is not found.
      ACCESS_DENIEDFAccess denied
      REQUEST_TRAFFIC_EXCEED_LIMITUThe request traffic exceeds the limit.
      API_INVALIDFAPI is invalid or not active.
      CLIENT_INVALIDFThe client is invalid.
      INVALID_SIGNATUREFThe signature is invalid.
      METHOD_NOT_SUPPORTEDFThe server does not implement the requested HTTP method.
      MEDIA_TYPE_NOT_ACCEPTABLEFThe server does not implement the media type that is acceptable to the client.
      UNKNOWN_EXCEPTIONUAn API calling is failed, which is caused by unknown reasons.
      MERCHANT_BALANCE_NOT_ENOUGHFThe merchant balance is not enough.
      Request/Response Code

      Request

      Method

      POST

      Endpoint

      /v1/payments/cancel

      Header

      Accept: application/json

      URL

      Domain name

      Request Body
      Request parameters
      Response Body
      Body content