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

      Post payments

      After making a payment, if further actions are needed, the cancel, refund, or query services can be initiated. Go through the Development section to learn about how to invoke an interface in both sandbox and production environments.


      #Query payment result

      You can query the status of a transaction order by using the Inquiry Payment interface. Call the inquiry interface when one of the following cases is encountered:

      • No clear result of the payment result can be obtained.
      • The payment process times out and no payment result is obtained. 
      • A refund record related to the transaction needs to be checked.


      Use the same paymentRequestId that is used in the payment API to inquire the payment transaction status. After Alipay processes the result, the payment or refund details are to be returned to the merchant synchronously. If no response from Alipay is received, retry the inquiry process.


      Construct the request message

      Construct the request message with the HTTP body as below:

      copy
      {
         "paymentRequestId": "pay_test_1106_0002"
      }


      Handle the response

      Process the inquiry response by verifying the signature of the notification. The following example shows a typical response for an inquiry request:

      copy
      {
          "result":{
              "resultCode":"SUCCESS",
              "resultStatus":"S",
              "resultMessage":"success"
          },
          "paymentStatus": "Success",
          "paymentRequestId":"pay_test_1106_0002",
          "paymentId":"20190608114010800100188820200355883",
          "paymentAmount":{
              "value":"500",
              "currency":"USD"
          },
          "actualPaymentAmount":{
              "value":"500",
              "currency":"USD"
          },
          "paymentCreateTime":"2019-06-01T12:01:01+08:30",
          "paymentTime":"2019-06-01T12:01:01+08:30"
      }


      The following graphic shows the process of inquiring the transaction status:

      image.png

      Figure 1. Inquiry process


      Note:

      Here are details about the result status that might be returned for a query request:

      • S: indicates that the inquiry was successful and the merchant can get the payment status from the value of paymentStatus.
      • F : a system alert is to be triggered after getting a resultStatus of F. The merchant's technical support team must investigate the root cause. If the root cause is fixable and the order still exists in the Alipay system, the merchant needs to retry the inquiry API until a result of S is obtained.
      • U: the merchant needs to call the inquiry API with the same parameters multiple times after getting a resultStatus of U, until a result of S or F is obtained. After the maximum number of retries, if still no S or F is returned, the merchant must call the cancel interface to cancel the transaction.


      #Cancel the transaction

      You can cancel a transaction if the transaction encounters technical issues during making the payment. The Payment Cancellation interface can be used to roll back all the actions performed in the Alipay system regarding the specific transaction. The cancellable period is specified in the contract. If being out of the agreed cancellable period, the cancellation cannot be performed. 


      Use the same paymentId that is used in the payment API to cancel the payment transaction. After Alipay processes the cancellation, the cancellation result is to be returned to the merchant synchronously. If no response from Alipay is received, retry the cancellation process.


      Construct the request message

      Construct the request message with the HTTP body as below:

      copy
      {
          "paymentId":"20190612184010800100188820200355884"
      }


      Handle the response

      Process the cancellation response by verifying the signature of the notification. The following example shows a typical response for a cancellation request:

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


      The following graphic shows the process of cancelling the transaction:

      image.png

      Figure 2. Cancellation process


      Notes:

      1. Integrator might implement the store and forward logic in the gateway. If the cancel request reaches to gateway before the payment API request, the cancel request should not be relayed to the next hop. 
      2. Here are details about the result status that might be returned for a cancellation request:
        • S: indicates that the cancellation was successful.
        • F : a system alert is to be triggered after getting a resultStatus of F. The merchant's technical support team must investigate the root cause. If the root cause is fixable and the order still exists in the Alipay system, the merchant needs to retry the cancellation API until a result of S is obtained.
        • U: the merchant needs to call the cancellation API with the same parameters multiple times after getting a resultStatus of U, until a result of S or F is obtained. After the maximum number of retries, if still no S or F is returned, the system alarm is to be triggered and the merchant's technical support team needs to be involved to solve the problem.


      #Refund

      You can issue a refund by using the Refund interface. The refund service is only applicable to a transaction that has been successfully paid and can be initiated any time after the transaction being paid and before the refund period expiration.


      The refund of a transaction can be full or partial, that is, the refund amount can be the same as or less than the original transaction amount that has been paid. If a refund request encounters a failure, retry for a reasonable number of times and follow these suggestions:

      • Use the original refund request ID and retry the refund request. Alipay supports idempotency if a merchant uses the same refund request.
      • The maximum number for retires and the interval for synchronous and asynchronous refund should be configured. 


      No fee is charged for a refund transaction. Your contract with Alipay determines whether the transaction fee charged by Alipay will be refunded or not. After Alipay processes a refund request, the refund is settled by transferring funds to payer's funding instrument. It depends on a bank's policy to determine when a refund settlement can finish. If a payer makes a payment with a credit card and rejects to pay for the credit card's balance, the rejected amount cannot be refunded.


      Construct the request message

      Construct the request message with the HTTP body as below:

      copy
      {
       "paymentId":"201811291907410100070000001111",
       "refundRequestId":"201811291907410200070000001111",
       "refundAmount":{
          "value":"100",
          "currency":"USD"
       }
      }


      Handle the response

      Process the cancellation response by verifying the signature of the notification. The following example shows a typical response for a refund request:

      copy
      {
       "result": {
          "resultCode":"SUCCESS",
          "resultStatus":"S",
          "resultMessage":"success"
        },
       "refundAmount":{
          "value":"100",
          "currency":"USD"
       },
       "refundTime": "2020-10-10T12:01:01+08:30",
       "paymentId":"201811291907410100070000001111",
       "refundRequestId":"201811291907410200070000001111",
       "refundId":"401811291907410200070000001111"
      }


      The following graphic shows the process of using a refund service:


      image.png

      Figure 3. Refund process


      Notes:

      1. After Alipay completes a refund, the transaction cannot be cancelled.
      2. Integrator might implement the store and forward logic in the gateway. If the refund request reaches to gateway before the gateway getting the success payment result, the refund request should not be relayed to the next hop.
      3. Here are details about the result status that might be returned for a refund request. The merchant must get a confirmative result status, either S or F for a refund request:  
        • S: indicates that the refund was successful.
        • F: indicates that a system alert is to be triggered after getting a resultStatus of F. The merchant's technical support team must investigate the root cause. If the root cause is fixable and the order still exists in the Alipay system, the merchant needs to retry the refund API one more time.
        • U: the merchant needs to call the refund API multiple times until a result of S or F is obtained. After the maximum number of retries, if still no S or F is obtained, the merchant should initialize an asynchronous refund request. After retrying the maximum number of async refund request, system alarm should be triggered and the merchant's technical support team needs to be involved to solve the problem.


      For more information about when to implement the Inquiry Payment, Payment Cancellation, and Refund interfaces, see Best practice.


      #More information

      Alipay developers center user guidance

      Testing