Alipay
Alipay is China’s leading third-party mobile and online payment solution.
About Alipay
Alipay provides easy, safe and secure Internet payments for millions of individuals and businesses.
With Alipay, you can process escrow payments that reduce transaction risk for the customer. Before releasing the payment amount, the customer can ensure they’re happy with the items they bought.
Accept an Alipay payment
To accept an Alipay payment, follow the steps below.
When testing, do not use real customer data. Use the test data prepared by Unzer.
Step 1: Create an alipay
resource
To create an alipay
resource, make a POST call with an empty request body to types/alipay
:
POST https://api.unzer.com/v1/types/alipay
"id": "s-ali-otvqlpgqsh7u",
"method": "alipay",
"recurring": false,
"geoLocation": {
"clientIp": "115.77.189.143",
"countryCode": "VN"
}
}
Property | Type | Description |
---|---|---|
id |
String | The returned ID of the alipay resource that you just created. |
method |
String | The payment method. |
recurring |
Boolean | Indicates if this is a recurring payment. |
clientIp |
String | The IP address of the device used for the payment. |
countryCode |
String | The country associated with clientIp , displayed in the ISO 3166-1 alpha-2 format. |
Step 2: Make a charges
call
To charge the Alipay resource, make a payments/charges
call with the following parameters in the request body:
Parameter | Required | Type | Default | Description | Example |
---|---|---|---|---|---|
amount |
Yes | Number | / |
The amount to be charged. | 50 |
currency |
Yes | String | / |
The transaction currency, in the ISO 4217 alpha-3 format. | EUR |
returnUrl |
No | String | / |
After the customer confirms the payment on the Unzer Bank Transfer payment page, returnUrl is called to redirect customer to the shop’s website. |
https://www.unzer.com |
orderId |
No | String | / |
A unique order ID that identifies the payment on your side. | Order-12 |
typeId |
Yes | String | / |
The newly-created payment type ID that you received in response to creating an Unzer Bank Transfer resource (Step 1). | s-pis-ynkylhm788ro |
customerId |
No | String | / |
The ID of the customers resource to be used. |
s-cst-1 |
metadataId |
No | String | / |
The ID of the metadata resource to be used. |
s-mtd-1 |
POST https://api.unzer.com/v1/payments/charges
Body:
{
"amount" : "50",
"currency" : "EUR",
"returnUrl" : "https://www.unzer.com",
"orderId": "",
"resources" : {
"typeId" : "s-ali-otvqlpgqsh7u",
"metadataId": "",
"customerId": ""
}
}
{
"id": "s-chg-1",
"isSuccess": false,
"isPending": true,
"isError": false,
"redirectUrl": "https://dev-payment.unzer.com/v1/redirect/alipay/laksjdfloikwjerklj2lk3j",
....
}
Property | Type | Description |
---|---|---|
id |
String | The transaction’s unique ID. |
isSuccess |
Boolean | Set to true if the transaction was successful. |
isPending |
Boolean | Set to true if the transaction is pending (e.g. if a redirect to an external system is required). |
isError |
Boolean | Set to true if an error occurs. |
redirectUrl |
String | The URL to which the customer will get redirected after the payment. |
Step 3: Forward the customer to the redirect URL
After you charge the alipay
resource, implement the following flow:
- Redirect the customer to the
redirectURL
. - The customer is forwarded to the Alipay payment page.
- After a successful payment, the customer is redirected to the
returnURL
that you specified in thecharges
call (Step 2).
Step 4: Check the payment status
After the customer is redirected to the returnUrl
, check the status of the payment.
Make a GET call with the following parameters in the request path:
Parameter | Required | Type | Default | Description | Example |
---|---|---|---|---|---|
resource_ID |
Yes | String | / |
The returned ID of the alipay resource that you created in Step 1. |
s-ali-otvqlpgqsh7u |
transaction_ID |
Yes | String | / |
The transaction’s unique ID that you received in Step 2. | s-chg-1 |
GET https://api.unzer.com/v1/payments/{resource_ID}>/charges/{transaction_ID}
{
"id": "s-chg-1",
"isSuccess": true,
"isPending": false,
"isError": false,
"redirectUrl": "",
...
}
Property | Type | Description |
---|---|---|
id |
String | The transaction’s unique ID. |
isSuccess |
Boolean | Set to true if the transaction was successful. |
isPending |
Boolean | Set to true if the transaction is pending (e.g. if a redirect to an external system is required). |
isError |
Boolean | Set to true if an error occurs. |
redirectUrl |
String | The URL to which the customer will get redirected after the payment. |