pay (User-presented Mode Payment)
Use the pay API to initiate a payment to Alipay and process payment results according to the status and operation instructions returned by Alipay.
Structure
A message consists of a header and body. The following sections are focused on the body structure. For the header structure, see:
Note: Set the data type of each field (except array) as String. This means that you must use double quotation marks (" ") to enclose the field value. Examples:
- If the data type of a field is Integer and its value is 20, set it as "20".
- If the data type of a field is Boolean and its value is true, set it as "true".
Request parameters
productCode String REQUIRED
The payment product that the merchant can use, based on the contract between the merchant and Alipay. For User-presented Mode Payment, the value is fixed as IN_STORE_PAYMENT
.
paymentRequestId String REQUIRED
The unique ID that is assigned by a merchant to identify a payment request. Alipay uses this field for idempotence control.
More information:
- This field is an API idempotency field.Merchant uses the paymentRequestId field for idempotency control. For payment requests that are initiated with the same value of paymentRequestId and reach a final status (S or F), the same result is to be returned for the request.
- Maximum length: 64 characters
order Order REQUIRED
Order information, such as buyer information, merchant information, order description, and order amount.
The parameter is also used for risk control, supervision, reporting, user payment result display, and so on.
paymentAmount Amount REQUIRED
The payment amount that the merchant requests to receive in the order currency.
paymentMethod PaymentMethod REQUIRED
The payment method that is used to collect the payment by the payment executor.
paymentExpiryTime Datetime
A specific time, after which the payment will not succeed.
More information:
- The value follows the ISO 8601 standard format. For example, "2019-11-27T12:01:01+08:00".
paymentRedirectUrl URL
More information:
- Maximum length: 2048 characters
paymentNotifyUrl URL REQUIRED
More information:
- Maximum length: 2048 characters
isAuthorization Boolean
paymentVerificationData PaymentVerificationData
Payment verification information
paymentFactor PaymentFactor
Specifies the payment scenario
Response parameters
result Result REQUIRED
The request result contains information such as status and error codes.
paymentRequestId String
The unique ID that is assigned by a merchant to identify a payment request.
More information:
- Maximum length: 64 characters
paymentId String
The unique ID that is assigned by Alipay to identify a payment.
More information:
- Maximum length: 64 characters
paymentAmount Amount
The payment amount that the merchant requests to receive in the order currency.
paymentTime Datetime
The date and time when the payment reaches a final state of success or failure.
More information:
- The value follows the ISO 8601 standard format. For example, "2019-11-27T12:01:01+08:00".
paymentCreateTime Datetime
The date and time when the payment is created.
More information:
- The value follows the ISO 8601 standard format. For example, "2019-11-27T12:01:01+08:00".
authExpiryTime Datetime
Authorization expiration time.
More information:
- The value follows the ISO 8601 standard format. For example, "2019-11-27T12:01:01+08:00".
pspCustomerInfo PspCustomerInfo
The customer information of Alipay+ MPP .
Note: Alipay+ Mobile Payment Partner, is an organization that processes payment services and other value-added services on behalf of the payer. For online and in-store payments, an Alipay+ Mobile Payment Partner is a digital wallet, such as GCash.
challengeActionForm ChallengeActionForm
Provides information about the challenge action when the payment result is not in a final state of success or failure.
redirectActionForm RedirectActionForm
Provides information about the redirection action.
orderCodeForm OrderCodeForm
Provides information about the order code.
grossSettlementAmount Amount
Gross settlement amount, which equals to the transaction amount multiplied by the value of settlementQuote.
Note: This field is empty when the settlement currency is the same as the transaction currency.
settlementQuote Quote
The exchange rate between the settlement currency and transaction currency at the time of the transaction, which is provided only in the locked-in rate case.
Note: This field is empty when the settlement currency is the same as the transaction currency.
Request
Response
More information
This section gives additional information about other parameters. See the following parameters for details:
• productCode:
The value of this parameter is the payment product that the merchant uses for collecting payments, based on the contract between the merchant and Alipay. When the merchant can use multiple products, this parameter is required.
• order:
The order parameter contains order information, such as Merchant, Goods, logistic, and purchase environment. During the payment process, the order information is mainly used by Alipay for risk control or anti-money laundering. After the payment is completed, the information is used to display consumption records, regulatory reporting, and other purposes. However, Alipay does not verify the consistency of the amount in order and the amount in the payment request. The order information is not applied in fund operations either. Use the env field if the risk control capability provided by Alipay is needed.
In this case, order.merchant.referenceMechantId, order.merchant.merchantMCC, order.merchant.store.referenceStoreId, and order.merchant.store.storeMCC are mandatory. It is recommended to specify order.env.storeTerminalRequestTime and order.env.storeTerminalId.
• paymentMethod:
The value of paymentMethod is CONNECT_WALLET
, indicating that Alipay collects money from the user's payment code that was generated by Alipay.
• paymentMethodId:
The unique identifier of the user's payment asset, which can be obtained by using the applyToken interface. For User-Presented Mode payments, this field is required and can be used by the merchant to decide which payment service should be called to process the payment. See Payment Code Specification for more information.
• paymentExpiryTime:
The payment executor must ensure that the payment will not succeed after the expiration time. If this parameter is not specified in the request, the expiration time is then decided by the payment executor.
• paymentFactor:
The value of paymentFactor.inStorePaymentScenario is PaymentCode
, indicating that the payment code is used for payment.
• authExpiredTime:
If the value of this field is true
, a specific value is returned.
Payment code specifications
An Alipay payment code is a number that is between 16 to 24 digits and starts with a number ranging from 25 to 30.
For user-presented code payments, use the following rules to determine which payment service is to be called:
- If an Alipay payment code is used for payment, the merchant needs to route the payment to Alipay.
- If a non-Alipay payment code is used for payment, the merchant needs to route the payment to the corresponding payment provider of the non-Alipay payment code.
- If a merchant that is integrated with Alipay has integrated with other local wallets that provide payment codes conforming to Alipay payment code rule, for example, the Macao Wallet, or the PayPay wallet, the merchant needs to route the payment to the local wallet system when payment codes from such local wallets are used, or to route the payment to Alipay when Alipay payment codes are used. To determine the payment code belongs to Alipay or the local wallet, use the following rules:
Asia
Payment code rule Payment service Length First two digits Special rule 24 25 - 30 The fourth, fifth, and sixth digits are 8, 0, and 1. PayPay 16~24 25 - 30 / Alipay
Payment code rule Payment service Length First two digits Special rule 16~24 25 - 30 The fourth, fifth, and sixth digits are 0, 0, and 3. Macao Wallet 16~24 25 - 30 / Alipay
Payment code rule PaymentService Length First two digits Special rule 16~24 25 - 30 - Alipay
Payment code rule PaymentService Length First two digits Special rule 16~24 25 - 30 - Alipay
Result process logic
After calling a pay interface, the following results might be returned from Alipay or no result is received by the merchant:
- Alipay returns that result.resultStatus is
S
, which indicates the transaction succeeds and the money is deducted successfully. - Alipay returns that result.resultStatus is
F
, the merchant needs to take further actions according to the error message in result.resultCode. - Alipay returns that result.resultStatus is
U
, the merchant needs to use the inquiryPayment interface to inquire the payment result. The inquiry request can be sent 10 to 20 times, with an interval of 3 seconds. - If no asynchronous notification and payment result are returned from Alipay within 5 seconds after the payment request is sent, the merchant needs to use the inquiryPayment interface to inquire the payment result. The inquiry request can be sent 10 to 20 times, with an interval of 3 seconds.
- When calling the inquiryPayment interfaces, if no payment result can be obtained after the inquiry requests being sent more than the maximum number of times, the merchant needs to call the cancel interface to cancel the transaction. If being out of the cancellable period, the merchant cannot use the cancel interface to cancel the transaction. The merchant can call the refund interface to make a refund instead.
Error codes
Error codes are usually classified into the following categories:
- Common error codes: common for all online and in-store payment APIs.
- API-specific error codes: listed in the following table.
Result/Error codes
Code | Value | Message | Further action |
---|---|---|---|
SUCCESS | S | Success | The payment is successful, no further action is needed. |
INVALID_PAYMENT_CODE | F | The payment code cannot be accepted by Alipay+. | Refresh the payment code and try again. |
CURRENCY_NOT_SUPPORT | F | The currency is not supported. | Use the currency that is agreed in the contract. |
USER_BALANCE_NOT_ENOUGH | F | The user balance is not enough for the payment. | Prompt the user that the user balance is insufficient. |
USER_STATUS_ABNORMAL | F | The user status is abnormal. | Prompt the user to contact the wallet. |
PAYMENT_AMOUNT_EXCEED_LIMIT | F | The payment amount exceeds the limit. | Prompt the user that the amount exceeds the limit. Contact Alipay technical support to know the speciific limitation. |
PAYMENT_COUNT_EXCEED_LIMIT | F | The number of payments exceeds the limit. | Prompt the user that the number of payments exceeds the limit. Contact Alipay technical support to know the speciific limitation. |
REPEAT_REQ_INCONSISTENT | F | Repeated requests are inconsistent. | Change paymentRequestID and call the interface again. |
USER_AMOUNT_EXCEED_LIMIT | F | The payment amount exceeds the user payment limit. | Prompt the user to check the payment amount. |
CLIENT_INVALID | F | The client is invalid. | Check whether the clientId is correct. |
METHOD_NOT_SUPPORTED | F | The server does not implement the requested HTTP method. | Check whether the HTTP method is correct. |
MEDIA_TYPE_NOT_ACCEPTABLE | F | The server does not implement the media type that is acceptable to the client. | Check whether the media type is correct. |
PAYMENT_IN_PROCESS | U | The payment is being processed. | The user has not completed the payment, call the inquiryPayment interface to query the final status of the order. |
USER_KYC_NOT_QUALIFIED | F | Payment failed because of the user's KYC status. The user is either not KYC compliant, or the KYC status is not qualified for this transaction (for example, limitations on the payment amount or product information). | Prompt the user to complete KYC. |