Inquire about payment status
To obtain the payment status, you can monitor the asynchronous notification or actively call the inquiryPayment API to get the payment status. Although a retransmission mechanism exists for the asynchronous notification, the notification might not be received due to network issues when the user successfully completes the payment. Therefore, it is necessary to actively inquire about the payment status by using the inquiryPayment API.
Usually, when you encounter one of the following cases, call the inquiryPayment API:
- No clear payment status can be obtained. For example, when the payment status notification is not received within one minute after receiving the response of the payment request.
- The payment process times out and no payment status is obtained.
Request
If the domain name is open-na.alipay.com
, the request URLs for calling the inquiryPayment API are as follows:
- Sandbox environment:
https://open-na.alipay.com/ams/sandbox/api/v1/payments/inquiryPayment
- Production environment:
https://open-na.alipay.com/ams/api/v1/payments/inquiryPayment
You can use paymentId or paymentRequestId to initiate the inquiryPayment request. It is suggested to use the paymentRequestId field because it is assigned by the merchant to identify each unique request. The following example shows an inquiryPayment request with the paymentId field specified.
{ "paymentId": "212302615674274268857659685498868097avhIBxVMMX201909020000024285" }
Response
The following example shows a response of the inquiryPayment API. The payment status is presented in the paymentStatus field.
{
"result": {
"resultStatus": "S",
"resultCode": "SUCCESS",
"resultMessage": "success."
},
"paymentResultCode": "SUCCESS",
"paymentResultMessage": "success",
"paymentStatus": "SUCCESS",
"paymentId": "212302615674274268857659685498868097avhIBxVMMX201909020000024285",
"paymentRequestId": "pay_1029760066716669_102775765079666",
"paymentAmount": {
"currency": "PHP",
"value": "800"
},
"RediretActionForm": {
"redirectUrl": "https://payments.gcash.com/gcashapp/gcash-cashier-web/1.2.1/index.html#/confirm?bizNo=111111111111111",
"method": "GET"
},
"transactions":[]
}
The result field: This field only indicates the call status of this inquiry request. It does not indicate the payment status. Details about the call status are as follows:
S
: indicates that the inquiryPayment API call was successful and you can get the payment status from the value of paymentStatus.F
: indicates that the inquiryPayment API call failed. You must investigate the root cause. If the root cause is fixable and the order still exists in the Alipay system, retry the inquiryPayment API until a result of S
is obtained.U
: indicates that the inquiryPayment API call status is unknown. After getting a resultStatus ofU
, call the inquiryPayment API with the same parameters multiple times until a result ofS
orF
is obtained. IfS
orF
is not returned after the maximum number of retries, the system alarm will be triggered and you must investigate and solve the problem.
The paymentStatus field: This field indicates the payment status of the order. This field is returned only when the value of result.resultStatus is S
. The value of this field can be:
SUCCESS
: indicates the payment succeeded. As this is a final payment status, stop the inquiry process.FAIL
: indicates the payment failed. As this is a final payment status, stop the inquiry process.CANCELLED
: indicates the payment is canceled. As this is a final payment status, stop the inquiry process.PROCESSING
: indicates that the payment is still processing. This is an intermediate payment status. When this value is returned, continue the inquiry process in the form of polling until a final payment status is obtained or until the asynchronous notification is received. The polling time needs to last for at least 14 minutes (Alipay's payment expiration time).