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

Make a payment

After completing the authorization process and getting the accessToken, you can directly initiate the auto debit without the need to go through the authorization process again for each payment. You can initiate the auto debit by calling the pay API and then use inquiryPayment and notifyPayment to check the payment status. The whole payment process is composed of the following steps:

  1. Initiate the payment
  2. Check the payment result

Step 1: Initiate a payment

After getting accessToken, you can deduct money from the user's account. Call the pay API by making a POST request to the Alipay server with the correct request URL path. For example, if you use the domain name of https://open-na-global.alipay.com, the request URL path is: https://<https://open-na-global.alipay.com>/ams/api/v1/payments/pay. Specify these fields in the API request:

  • paymentRequestId: Specify an ID to identify this request.
  • order: Specify the information about the order.
  • paymentAmount: Specify the amount to pay.
  • paymentMethod: Specify the target Alipay+ MPP to paymentMethodType and specify the value of accessToken obtained by calling the applyToken API to paymentMethodId.
  • productCode: Specify the value as AGREEMENT_PAYMENT.

The following sample shows a pay request. The value of paymentMethodId is the accessToken value that is returned in the response of the applyToken call.

copy
{
  "productCode": "AGREEMENT_PAYMENT",
  "paymentRequestId": "pay_1089760038715669_102775745075656",
  "order": {
    "referenceOrderId": "102775745075669",
    "orderDescription": "Mi Band 3 Wrist Strap Metal Screwless Stainless
    "orderAmount": {
      "value": "800",
      "currency": "PHP"
    }
  },
  "paymentAmount": {
    "currency": "PHP",
    "value": "800"
  },
  "paymentMethod": {
    "paymentMethodType": "GCASH",
    "paymentMethodId": "20190828054139156697089972935735984402094237jmfUW
  }
}

After calling the pay API, if no response is returned, call the API again with the same fields as the previous request. If a response is returned, take the following actions for each case:

  • If the value of result.resultStatus is S, the payment succeeded.
  • If the value of result.resultStatus is F, the payment failed. For more information about the reason for failure, see resultCode.
  • If the value of result.resultStatus is U, the payment is still in process. In this case, the inquiryPayment API needs to be called until the value of paymentStatus is SUCCESS, FAIL, or CANCELLED, or until an asynchronous notification is received.

The following sample shows a response of a successfully called pay API:

copy
{
    "result": {
        "resultStatus": "S",
        "resultCode": "Success",
    "resultMessage": "Success" 
    },
    "paymentId": "071329156697640993635741494609211863FOkUAZHdoQ201908280
    "paymentRequestId": "pay_1089760038715669_102775745075656",
    "pspCustomerInfo": {
        "displayCustomerId": "test***@xxx.com", 
        "pspCustomerId": "20881111111234",
        "pspName": "ALIPAY_CN" 
    },
    "paymentAmount": {
        "currency": "PHP",
        "value": "800"
    },
    "paymentTime": "2019-08-28 00:13:29",
    "resultInfo": {
        "resultStatus": "S",
        "resultCode": "Success",
    "resultMessage": "Success" 
    },
    "paymentCreateTime": "2019-08-28 00:13:29"
 }

Step 2: Get the payment result

To obtain accurate payment results, you must integrate both the asynchronous notification and payment result inquiry services. Because some payment methods might not return any notification when the payment fails, integrating both the asynchronous notification and payment result inquiry services will ensure the payment result is obtained from any payment method.

Get asynchronous notification

After the user completes the payment successfully or when the payment fails, you can get the payment result notification sent by Alipay if you have provided an address to receive the payment notification (Payment Notification URL) to Alipay. You can provide the Payment Notification URL to Alipay in two ways:

If you have specified the Payment Notification URL in both the pay request and Alipay Developer Center, the value specified in the pay request takes precedence.

Upon receipt of the notification, you must verify the signature of the notification and return a receipt acknowledgment message to Alipay. For more information about handling the asynchronous notification, see Receive payment notification.

Call the inquiryPayment API

It is strongly recommended to integrate the inquiryPayment API in your system for the auto debit payment. The payment result is indicated by the paymentStatus field of the response. If the value of paymentStatus is PROCESSING in the inquiryPayment response, the inquiryPayment API needs to be called continuously for more than one minute until a final status of SUCCESS or FAIL in the paymentStatus field is returned. For Auto Debit, Alipay's payment expiration time is one minute.