Alipay works much like PayPal, where the consumer chooses to make a payment and is directed to the external Alipay site, where they enter (or choose existing) payment information.
Create an Alipay payment method for your app or website in four easy steps:
Build an Alipay Source Request object. The Alipay Source Request object requires the following fields.
Field | Value |
type | alipay |
amount | The total value of the transaction. |
currency | The currency of the transaction. |
owner | An Owner object. |
alipay | An Alipay Source Details object that includes the details of the transaction. |
{"returnUrl": "https://example.com"}
Field | Required/Optional | Description |
returnUrl | Required | Where you will redirect your customer after the customer authorizes or cancels within the Alipay experience. |
items | Required | An array of Alipay Item objects. |
{"name": "Cell Phone (Unlocked)","quantity": 1,"unitAmount": 100,"sku": "SKU123"}
Field | Required/Optional | Description |
name | Required | The name of the item that will appear in the Alipay authorize screen. |
quantity | Required | The quantity of the item that will appear in the Alipay authorize screen. |
unitAmount | Required | The amount of the item. |
sku | Required | The unique identifier for the item. |
To create an Alipay payment source, you must use the createSource method exposed via DigitalRiver.js.
var data = {"owner": {"firstName": "John","lastName": "Doe","email": "john.doe@hotmail.com","phoneNumber": "000-000-0000","address": {t"line1": "123 Fake Street","city": "BAOSHAN DISTRICT","state": "SHANGHAI","country": "CN","postalCode": "201900"}},"alipay": {"returnUrl": "https://returnUrl.com"},"type": "alipay","sessionId": "9f180964-9da4-43ac-b8e0-ae54d832b03c"}digitalriver.createSource(data).then(function(result) {if (result.error) {//handle errors} else {var source = result.source;//send source to back endsendToBackend(source);}});
{"clientId": "gc","channelId": "drdod15","liveMode": false,"id": "5ce08114-143b-4bf6-ae0e-6fc501ee0c24","clientSecret": "5ce08114-143b-4bf6-ae0e-6fc501ee0c24_a468b08e-2c47-4531-82af-d48d80ff6dcc","type": "alipay","reusable": false,"owner": {"firstName": "John","lastName": "Doe","email": "john.doe@hotmail.com","phoneNumber": "555-555-1234","address": {"line1": "123 First Street","city": "BAOSHAN DISTRICT","state": "SHANGHAI","country": "CN","postalCode": "201900"}},"amount": "10.00","currency": "CNY","state": "pending_redirect","creationIp": "10.81.3.92","createdTime": "2020-02-26T02:48:11.508Z","updatedTime": "2020-02-26T02:48:11.508Z","flow": "redirect","redirect": {"redirectUrl": "https://api.digitalriverws.com:443/payments/redirects/51314834-9bf9-483f-b3a7-4b36a14d3f5c?apiKey=pk_hc_e03ee62c0d964bb3ac75595b1203d13c","returnUrl": "returnUrl.com"},"alipay": {}}
When you create an Alipay source, the customer is required to authorize the charge through their payment provider. You can accomplish this by redirecting the customer to their payment provider.
To redirect your customer to the payment provider for authorization, use the redirectUrl
parameter in your createSource
response.
window.location.href = sourceResponse.redirect.redirectUrl;
The payment provider will present the customer with the transaction details where they can authorize, or cancel the transaction. A successful authorization redirects the customer to the Alipay Return URL parameter you specified when you created the source.
Once authorized, you can use the source by attaching it to a cart.
{"paymentMethod": {"sourceId": "e7ba0595-059c-460c-bad8-2812123b9313"}​
Alipay supports the following geographies and currencies.
Bangladesh (BD), China (CN), Ecuador (EC), El Salvador (SV), Panama (PA), Paraguay (PY), Puerto Rico (PR), United States (US), Venezuela (VE)
CNY, USD