Alipay
Topics covered on this page
Accepting payments through Alipay, one of China's most popular online payment method gives you access to over 450 million registered Chinese consumers. Omise handles payments between the merchant and Alipay allowing you to accept payments without having to setup an Alipay account or registering for a Chinese bank account.
The payment flow
When your customers chooses Alipay as their preferred payment method at checkout, they go through a redirect payment flow. What this means is that they are redirected from the merchant’s website to Alipay’s secure checkout page where they authorize and confirm the payment. Upon completion, the customer is automatically redirected back to the merchant’s website.
On Alipay’s checkout page, the payment amount is pre-filled for your customer. All they’ve got to do is review and confirm. The currency displayed to your customer will be in the merchant account’s currency (current currency support: THB) and will be automatically converted to CNY by Alipay when it's processed. You’ll receive funds in your Omise account in your account’s currency.
Creating a charge
Creating an offsite Alipay charge is almost identical to creating an internet banking charge; you just need to pass alipay
value in offsite
field.
Here is a cURL snippet for creating an Alipay charge:
curl https://api.omise.co/charges \
-X POST \
-u skey_test_56rn509djosl176cmm4: \
-d "amount=100000" \
-d "currency=thb" \
-d "offsite=alipay" \
-d "return_uri=http://example.com/orders/1235813/complete"
return_uri
- is the URI where the customer is redirected back to upon charge completion.
An example of JSON response is shown below.
{
"object": "charge",
"id": "chrg_test_57003cpwde7oww4x3o0",
"livemode": false,
"location": "/charges/chrg_test_57003cpwde7oww4x3o0",
"amount": 100000,
"currency": "thb",
"description": null,
"status": "pending",
"capture": true,
"authorized": false,
"reversed": false,
"paid": false,
"transaction": null,
"source_of_fund": "offsite",
"refunded": 0,
"refunds": {
"object": "list",
"from": "1970-01-01T09:00:00+09:00",
"to": "2017-02-14T22:57:38+09:00",
"offset": 0,
"limit": 20,
"total": 0,
"order": null,
"location": "/charges/chrg_test_57003cpwde7oww4x3o0/refunds",
"data": []
},
"return_uri": "http://example.com/orders/1235813/complete",
"offsite": "alipay",
"reference": "ofsp_test_57003craqffu31xi1mu",
"authorize_uri": "https://pay.omise.co/offsites/ofsp_test_57003craqffu31xi1mu/pay",
"failure_code": null,
"failure_message": null,
"card": null,
"customer": null,
"ip": null,
"dispute": null,
"created": "2017-02-14T13:57:38Z"
}
To proceed to the Alipay checkout page, you’ll need to redirect the customer to the authorize_uri
.
*Note: In test mode, copy the URL returned in the authorize_uri
and paste it to your browser to proceed with testing.
You can always check the status of the charge by retrieving the charge as described in the Charges API.
- If both
authorized
andpaid
are true, the charge succeeded. - If both
authorized
andpaid
are false, the charge failed. For detailed explanation on the reason the charge failed, check thefailure_code
andfailure_message
in the Charge object. - There is no scenario where
authorized
andpaid
are different values.
Refund
You can create a full or partial refund through our refund API or from the charge page on your dashboard.
Note: Alipay charges can only be refunded within 3 months of the transaction date.
Webhooks
Rather than relying on the redirection back to the return_uri
, we suggest you make use of our Webhook API . Whenever a transaction is completed, a webhook is sent to the URL that is specified in the dashboard with the event name charge.complete
Note
- For users with a live account, please send an email to support@omise.co You’ll need to review Terms & Conditions before testing the API.