Alipay

Alipay is a delayed fulfillment payment method, meaning fulfillment occurs after authorization and settlement.

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.

Configuring Alipay for DigitalRiver.js

Create an Alipay payment method for your app or website in four easy steps:

Step 1: 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.

Alipay source details object

{
"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.

Alipay item object

{
"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.

Step 2: Create the Alipay source using DigitalRiver.js

To create an Alipay payment source, you must use the createSource method exposed via DigitalRiver.js.

var data = {
"owner": {
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"phoneNumber": "000-000-0000",
"address": {
"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 end
sendToBackend(source);
}
});

Alipay source example

{
"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": "[email protected]",
"phoneNumber": "000-000-0000",
"address": {
"line1": "123 Fake 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": {}
}

Step 3: Authorize an Alipay source

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.

Redirecting the customer for authorization

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 presents the customer with the transaction details where the customer 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.

Step 4: Use the authorized source

Once authorized, you can use the source by attaching it to a checkout.

POST /checkouts/{id}
POST /checkouts/{id}
{
"customerId": "5774321008",
"sourceId": "src_a78cfeae-f7ae-4719-8e1c-d05ec04e4d37"
}

Supported markets

For information on supported markets and currencies for Drop-in and DigitalRiver.js, go to: