PayPal

Accept payment from consumers using PayPal to transfer funds online.

Digital River offers the following payment methods for PayPal: PayPal, PayPal Billing Agreement, and PayPal Credit.

PayPal

PayPal is a payment service that facilitates payments between parties through online funds transfers. PayPal allows customers to establish an account on its website, which is connected to a user's credit card or checking account.

You can find an example of integration here.

Create a PayPal payment method for your app or website in four easy steps:

Supported geographies

PayPal supports the following geographies and currencies.

Supported Geographies

Andorra

American Samoa

Austria

Australia

Bangladesh

Belgium

Bulgaria Brazil

Bouvet Islands

Canada

Cocos Islands

Switzerland

Cook Islands

Christmas Island

Cyprus

Czech Republic

Germany

Denmark

Ecuador

Estonia

Spain

Finland

Micronesia

Faroe Islands

France

United Kingdom

French Guiana

Greenland

Greece

South Georgia & South Sandwich Islands

Guam

Hong Kong

Heard Island & McDonald Islands

Hungary

Ireland

Israel

British Indian Ocean Territory

Italy

Japan

Kiribati

Liechtenstein

Lithuania

Luxembourg

Latvia

Monaco

Marhsall Islands

Northern Mariana Islands

Malta

Mexico

Norfolk Island

Netherlands

Norway

Niue

N Zealand

Panama

Peru

Philippines

Poland

Saint Pierre & Miquelon

Pitcairn Islands

Puerto Rico

Portugal

Reunion

Romania

Russia

Sweden

Singapore

Slovenia

Svalbard & Jan Mayen Islands

Slovakia

San Marino

El Salvador

Tristan da Cunha

Turks & Caicos Islands

Thailand

Tokelau

Tuvalu

Taiwan

US Minor Outlying Islands

United States

Vatican

Venezuela

Supported Currencies

AUD

BRL

CAD

CHF

CZK

DKK

EUR

GBP

HKD

HUF

ILS

JPY

MXN

NOK

NZD

PHP

PLN

RUB

SEK

SGD

THB

TWD

USD

Step 1. Build the PayPal objects

Build the PayPal objects.

PayPal Source Request object

A PayPal Source Request object requires the following fields.

Field

Value

type

payPal

amount

The total value of the transaction.

currency

The currency of the transaction.

payPal

A PayPal Source Details object that includes the details of the transaction.

PayPal Source Details object

The PayPal Source Details object requires the following fields.

{
"returnUrl": "http://mypage.com",
"cancelUrl": "https://mypage.com/cancel",
"items": [{
"name": "Cell Phone (Unlocked)",
"quantity": 1,
"unitAmount": 100
},
{
"name": "Headphones",
"quantity": 1,
"unitAmount": 15
}
],
"taxAmount": 0.99,
"shippingAmount": 5,
"amountsEstimated": true,
"shipping": {
"recipient": "John Doe",
"phoneNumber": "555-555-1212",
"address": {
"line1": "54321 Fake St.",
"line2": "Apt. 3C",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55341"
}
}
}

Field

Required/Optional

Description

returnUrl

Required

If you choose to utilize the full redirect flow, this is where you will redirect your customer to after authorizing within the PayPal experience.

cancelUrl

Required

If you choose to utilize the full redirect flow, this is where you will redirect your customer to after canceling within the PayPal experience.

items

Required

An array of PayPal Item objects.

taxAmount

Required

The value of the total tax amount of the transaction.

shippingAmount

Required

The value of the total shipping amount of the transaction.

amountsEstimated

Required

A true/false flag to identify these amounts as estimated within the PayPal experience. You can use this when authorization requires a final calculation of shipping rates or taxes.

requestShipping

Required

A true/false flag to tell PayPal to request the shipping address from the Shopper within the PayPal experience.

shipping

Optional

A PayPal Shipping Information object that may be populated if you have already captured the shipping address and wish to pre-populate it within the PayPal experience.

PayPal Item object

Build the PayPal Item object. A PayPal Item object requires the following fields.

{
"name": "Cell Phone (Unlocked)",
"quantity": 1,
"unitAmount": 100
}

Field

Required/Optional

Description

name

Required

The name of the item that appears in the PayPal authorize screen.

quantity

Required

The quantity of the item that appears in the PayPal authorize screen.

unitAmount

Required

The amount of the item.

PayPal Shipping Information object

Build the PayPal Shipping Information object. A PayPal Shipping Information object requires the following fields.

{
"recipient": "John Doe",
"phoneNumber": "952-555-1212",
"address": {
"line1": "54321 Fake St.",
"line2": "Apt. 3C",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55341",
"country": "US"
}
}

Field

Required/Optional

Description

recipient

Required

The first and last name of the person receiving the shipment.

phoneNumber

Required

The phone number of the person receiving the shipment.

address

Required

A PayPal Shipping Address object which contains the Shipping Address of the person receiving the shipment.

PayPal Shipping Address object

Build the PayPal Shipping Address object. A PayPal Shipping Address object requires the following fields.

{
"line1": "54321 Fake St.",
"line2": "Apt. 3C",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55341"
}

Field

Required/Optional

Description

line1

Required

Line 1 of the customer's billing address.

line2

Required

Line 2 of the Customer's billing address.

city

Required

City of the customer's billing address.

state

Required

State of the customer's billing address.

postalCode

Required

Postal code of the customer's billing address.

country

Required

Country of the customer's billing address.

Step 2. Create a PayPal source using DigitalRiver.js

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

JavaScript
JavaScript
var payPalData = {
"type": "payPal",
"amount": 120.99,
"currency": "USD",
"payPal": {
"returnUrl": "http://mypage.com",
"cancelUrl": "https://mypage.com/cancel",
"items": [{
"name": "Cell Phone (Unlocked)",
"quantity": 1,
"unitAmount": 100
},
{
"name": "Headphones",
"quantity": 1,
"unitAmount": 15
}
],
"taxAmount": 0.99,
"shippingAmount": 5,
"amountsEstimated": true,
"requestShipping": true,
"shipping": {
"recipient": "Fred Flintstone",
"phoneNumber": "952-555-1212",
"address": {
"line1": "10380 Bren Road W",
"line2": "",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55343"
}
}
}
}
digitalriver.createSource(payPalData).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

PayPal source response example

Source response
Source response
{
"clientId": "gc",
"channelId": "drdod15",
"liveMode": false,
{
"clientId": "gc",
"channelId": "drdod15",
"liveMode": false,
"id": "d6a44e5d-1373-4013-847d-10deb4ded4df",
"clientSecret": "d6a44e5d-1373-4013-847d-10deb4ded4df_ddd44e5d-1373-4013-847d-10deb4ded4df",
"type": "payPal",
"reusable": false,
"amount": "10.00",
"currency": "USD",
"state": "pending_redirect",
"creationIp": "209.87.178.4",
"createdTime": "2019-05-22T00:00:46.975Z",
"updatedTime": "2019-05-22T00:00:46.975Z",
"flow": "redirect",
"redirect": {
"redirectUrl": "https://api.digitalriver.com:443/payments/redirects/b8f2207b-8236-4608-b5a2-812790d42ed8?apiKey=pk_test_6cb0fe9ce3124093a9ad906f6c589e2ds",
"returnUrl": "https://example.com?action=paymentSuccess",
"cancelUrl": "https://example.com?action=paymentFailure"
},
"payPal": {
"shipping": {
"recipient": "Fred Flintstone",
"phoneNumber": "952-555-1212",
"address": {
"line1": "54321 Fake St.",
"line2": "Apt. 3C",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55341"
}
},
"token": "EC-1HD67063RG318840B"
}
} "clientSecret": "d6a44e5d-1373-4013-847d-10deb4ded4df_ddd44e5d-1373-4013-847d-10deb4ded4df",
"type": "payPal",
"reusable": false,
"amount": "10.00",
"currency": "USD",
"state": "pending",
"creationIp": "209.87.178.4",
"createdTime": "2019-05-22T00:00:46.975Z",
"updatedTime": "2019-05-22T00:00:46.975Z",
"flow": "redirect",
"redirect": {
"redirectUrl": "https://api.digitalriver.com:443/payments/redirects/b8f2207b-8236-4608-b5a2-812790d42ed8?apiKey=pk_test_6cb0fe9ce3124093a9ad906f6c589e2ds",
"returnUrl": "https://example.com?action=paymentSuccess",
"cancelUrl": "https://example.com?action=paymentFailure"
},
"payPal": {
"shipping": {
"recipient": "Fred Flintstone",
"phoneNumber": "952-555-1212",
"address": {
"line1": "10380 Bren Road W",
"line2": "",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55343"
}
},
"token": "EC-1HD67063RG318840B"
}
}

Step 3. Authorize a PayPal source

When you create a PayPal source, the customer is required to authorize the charge at PayPal. You can accomplish this by either redirecting the customer to PayPal or using the PayPal SDK to authorize the charge as part of your experience.

Redirecting the customer to PayPal for authorization

To redirect your customer to PayPal for authorization, use the redirectUrl parameter in your createSource response.

window.location.href = sourceResponse.redirect.redirectUrl;

At PayPal, the customer can authorize or cancel the transaction when presented with the transaction details. If the authorization is successful, the customer will be redirected to the PayPal Return URL parameter you specified when you created the source. If the customer cancels, they will be returned to the PayPal Cancel URL parameter you specified.

Using the PayPal SDK to authorize payment

Use the PayPal Checkout SDK to streamline the authorizing PayPal transactions. This will allow you to control things like the appearance of the PayPal button and embed the entire experience into your workflow.

Example:

  1. Include the PayPal Checkout SDK on your page and specify a location where the button will appear.

  2. Use the PayPal SDK to customize and place the PayPal button on your page. The PayPal SDK returns two functions, onAuthorize and onCancel. If the payment was authorized, use the source you created earlier by attaching to checkout.

HTML
HTML
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<div id="paypal-button"></div>
JavaScript
JavaScript
var paypalSourceData = {
"type": "payPal",
"amount": 10,
"currency": "USD",
"payPal": {
"returnUrl": redirectUrl,
"cancelUrl": cancelUrl,
"items": [{
"name": "Galaxy S9+ 256GB (Unlocked)",
"quantity": 1,
"unitAmount": 959.99,
},
{
"name": "AKG Y50BT On-Ear Bluetooth Headphones",
"quantity": 1,
"unitAmount": 0,
}
],
"taxAmount": 67.20,
"shippingAmount": 0,
"amountsEstimated": true,
"requestShipping": true,
"shipping": {
"recipient": "Fred Flintstone",
"phoneNumber": "952-555-1212",
"address": {
"line1": "10380 Bren Road W",
"line2": "",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55343"
}
}
}
};
paypal.Button.render({
// Configure environment
env: 'sandbox',
// Customize button (optional)
locale: 'en_US',
style: {
label: 'checkout',
size: 'responsive',
color: 'gold',
shape: 'rect',
layout: 'horizontal',
fundingicons: 'false',
tagline: 'false'
},
// Set up a payment
payment: function(data, actions) {
return digitalriver.createSource(paypalSourceData).then(function(result) {
if (result.error) {
//handle the errors that were returned
handleErrors(result.error)
} else {
return result.source.payPal.token;
}
});
},
// Execute the payment
onAuthorize: function(data, actions) {
//the payment has been authorized, use the source and attach it to your customer's account.
doSomething();
},
onCancel: function(data) {
//the payment has been cancelled, do something to try and get the shopper back on track
doSomethingElse();
}
}, '#paypal-button');
PayPal login

Step 4. Use the Authorized source

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

Attach the source to a checkout

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

PayPal Billing Aggreement

The PayPal Billing Agreement allows consumers to use their PayPal account to make recurring subscription payments. Consumers have the option to choose to auto renew or manually renew.

Currency supported: All currencies available in supported countries.

You can find an example of the integration here.

Create a PayPal Billing Agreement payment method for your app or website in four easy steps:

Supported geographies

PayPal Billing Agreement supports the following geographies and currencies.

Supported Geographies

Andorra

American Samoa

Austria

Australia

Bangladesh

Belgium

Bulgaria

Brazil

Bouvet Islands

Canada

Cocos Islands

Switzerland

Cook Islands

Christmas Island

Cyprus

Czech Rpb

Germany

Denmark

Ecuador

Estonia

Spain

Finland

Micronesia

Faroe Islands

France

United Kingdom

French Guiana

Greenland

Greece

South Georgia & South Sandwich Islands

Guam

Hong Kong

Heard Island & McDonald Islands

Hungary

Ireland

Israel

British Indian Ocean Territory

Italy

Japan

Kiribati

Liechtenstein

Lithuania

Luxembourg

Latvia

Monaco

Marhsall Islands

Northern Mariana Islands

Malta

Mexico

Norfolk Island

Netherlands

Norway

Niue

N Zealand

Panama

Peru

Philippines

Poland

Saint Pierre & Miquelon

Pitcairn Islands

Puerto Rico

Portugal

Reunion

Romania

Russia

Sweden

Singapore

Slovenia

Svalbard & Jan Mayen Islands

Slovakia

San Marino

El Salvador

Tristan da Cunha

Turks & Caicos Islands

Thailand

Tokelau

Tuvalu

Taiwan

US Minor Outlying Islands

United States

Vatican

Venezuela

Supported Currencies

AUD

BRL

CAD

CHF

CZK

DKK

EUR

GBP

HKD

HUF

ILS

JPY

MXN

NOK

NZD

PHP

PLN

RUB

SEK

SGD

THB

TWD

USD

Step 1. Build a PayPal Billing Agreement Source Request object

Build the PayPal Billing Agreement Source Request object. A PayPal Billing Agreement Source Request object requires the following fields.

Field

Value

type

payPalBilling

amount

The total value of the transaction.

currency

The currency of the transaction.

payPalBilling

A PayPal Source Details object that includes the details of the transaction.

Step 2. Create a PayPal Billing Agreement source using DigitalRiver.js

To create a PayPal Billing Agreement payment source, you must use the createSource method exposed via DigitalRiver.js.

JavaScript
JavaScript
var payPalData = {
"type": "payPalBilling",
"amount": 120.99,
"currency": "USD",
"payPalBilling": {
"returnUrl": "http://mypage.com",
"cancelUrl": "https://mypage.com/cancel",
"items": [{
"name": "Cell Phone (Unlocked)",
"quantity": 1,
"unitAmount": 100
},
{
"name": "Headphones",
"quantity": 1,
"unitAmount": 15
}
],
"taxAmount": 0.99,
"shippingAmount": 5,
"amountsEstimated": true,
"requestShipping": true,
"shipping": {
"recipient": "Fred Flintstone",
"phoneNumber": "952-555-1212",
"address": {
"line1": "10380 Bren Road W",
"line2": "",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55343"
}
}
}
}
digitalriver.createSource(payPalData).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

PayPal Billing source example

PayPal Billing source response
PayPal Billing source response
{
"clientId": "gc",
"channelId": "drdod15",
"liveMode": false,
"id": "d6a44e5d-1373-4013-847d-10deb4ded4df",
"clientSecret": "d6a44e5d-1373-4013-847d-10deb4ded4df_accd4e5d-1373-4013-847d-10deb4ded4df",
"type": "payPalBilling",
"reusable": false,
"amount": "10.00",
"currency": "USD",
"state": "pending",
"creationIp": "209.87.178.4",
"createdTime": "2019-05-22T00:00:46.975Z",
"updatedTime": "2019-05-22T00:00:46.975Z",
"flow": "redirect",
"redirect": {
"redirectUrl": "https://api.digitalriver.com:443/payments/redirects/b8f2207b-8236-4608-b5a2-812790d42ed8?apiKey=pk_test_6cb0fe9ce3124093a9ad906f6c589e2ds",
"returnUrl": "https://example.com?action=paymentSuccess",
"cancelUrl": "https://example.com?action=paymentFailure"
},
"payPalBilling": {
"shipping": {
"recipient": "Fred Flintstone",
"phoneNumber": "952-555-1212",
"address": {
"line1": "10380 Bren Road W",
"line2": "",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55343"
}
},
"token": "EC-1HD67063RG318840B"
}
}
PayPal Billing source response
PayPal Billing source response
{
"clientId": "gc",
"channelId": "drdod15",
"liveMode": false,
"id": "d6a44e5d-1373-4013-847d-10deb4ded4df",
"clientSecret": "d6a44e5d-1373-4013-847d-10deb4ded4df_accd4e5d-1373-4013-847d-10deb4ded4df",
"type": "payPalBilling",
"reusable": false,
"amount": "10.00",
"currency": "USD",
"state": "pending",
"creationIp": "209.87.178.4",
"createdTime": "2019-05-22T00:00:46.975Z",
"updatedTime": "2019-05-22T00:00:46.975Z",
"flow": "redirect",
"redirect": {
"redirectUrl": "https://api.digitalriver.com:443/payments/redirects/b8f2207b-8236-4608-b5a2-812790d42ed8?apiKey=pk_test_6cb0fe9ce3124093a9ad906f6c589e2ds",
"returnUrl": "https://example.com?action=paymentSuccess",
"cancelUrl": "https://example.com?action=paymentFailure"
},
"payPalBilling": {
"shipping": {
"recipient": "Fred Flintstone",
"phoneNumber": "952-555-1212",
"address": {
"line1": "10380 Bren Road W",
"line2": "",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55343"
}
},
"token": "EC-1HD67063RG318840B"
}
}

Step 3. Authorize a PayPal Billing Agreement source

When you create a PayPal Billing Agreement source, the customer is required to authorize the charge through PayPal. You can accomplish this by either redirecting the customer to PayPal or use the PayPal SDK to authorize the charge as part of your experience.

Redirecting the customer to PayPal for authorization

To redirect your customer to PayPal for authorization, use the redirectUrl parameter in your createSource response.

HTML
HTML
window.location.href = sourceResponse.redirect.redirectUrl;

PayPal will present the customer with the transaction details where they can authorize, or cancel the transaction. A successful authorization redirects the customer to the PayPal Return URL parameter you specified when you created the source. If the customer cancels, they will return to the PayPal Cancel URL parameter you specified when you created the source.

Using the PayPal SDK to authorize payment

Use the PayPal Checkout SDK to streamline the authorizing PayPal transactions. This will allow you to control things like the appearance of the PayPal button and embed the entire experience into your workflow.

Example:

  1. Include the PayPal Checkout SDK on your page and specify a location where the button will appear.

  2. Use the PayPal SDK to customize and place the PayPal button on your page. The PayPal SDK returns two functions, onAuthorize and onCancel. If the payment was authorized, use the source you created earlier by attaching to a shopper or customer.

JavaScript
JavaScript
var paypalSourceData = {
"type": "payPalBilling",
"amount": 10,
"currency": "USD",
"payPalBilling": {
"returnUrl": redirectUrl,
"cancelUrl": cancelUrl,
"items": [{
"name": "Galaxy S9+ 256GB (Unlocked)",
"quantity": 1,
"unitAmount": 959.99,
},
{
"name": "AKG Y50BT On-Ear Bluetooth Headphones",
"quantity": 1,
"unitAmount": 0,
}
],
"taxAmount": 67.20,
"shippingAmount": 0,
"amountsEstimated": true,
"requestShipping": true,
"shipping": {
"recipient": "Fred Flintstone",
"phoneNumber": "952-555-1212",
"address": {
"line1": "10380 Bren Road W",
"line2": "",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55343"
}
}
}
};
paypal.Button.render({
// Configure environment
env: 'sandbox',
// Customize button (optional)
locale: 'en_US',
style: {
label: 'checkout',
size: 'responsive',
color: 'gold',
shape: 'rect',
layout: 'horizontal',
fundingicons: 'false',
tagline: 'false'
},
// Set up a payment
payment: function(data, actions) {
return digitalriver.createSource(paypalSourceData).then(function(result) {
if (result.error) {
//handle the errors that were returned
handleErrors(result.error)
} else {
return result.source.payPal.token;
}
});
},
// Execute the payment
onAuthorize: function(data, actions) {
//the payment has been authorized, use the source and attach it to your customer's account.
doSomething();
},
onCancel: function(data) {
//the payment has been cancelled, do something to try and get the shopper back on track
doSomethingElse();
}
}, '#paypal-button');
PayPal login

Step 4. Use the authorized source

Once authorized, you can use the source by attaching it to a checkout or attaching it to a customer or shopper for multiple uses.

Option 1. Attach the source to a checkout

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

Option 2. Attach the source to a customer

POST /customers/{id}/sources/{sourcesId}
{
"id": "5774321008",
"sourceId": "src_a78cfeae-f7ae-4719-8e1c-d05ec04e4d37"
}

PayPal Credit

Additional Setup Required: If you are interested in using PayPal Credit, please contact your Account Manager.

PayPal Credit allows consumers to buy online and pay later for their products. This payment method is accepted in thousands of online stores and is available everywhere PayPal is accepted (as long as the PayPal Credit and PayPal accounts are linked). PayPal Credit uses the date of birth and last 4 digits of SSN to approve or deny a consumer for a line of credit, and the applicant will be notified within seconds whether they have been approved or not.

Create a PayPal payment method for your app or website in four easy steps:

Supported geographies

PayPal Credit supports the following geographies and currencies.

Supported Geographies

US

Supported Currencies

USD

Step 1. Build a Credit Source Request object

Build a Credit Source Request object. A PayPal Billing Credit Source Request object requires the following fields.

Field

Value

type

payPalCredit

amount

The total value of the transaction.

currency

The currency of the transaction.

payPalCredit

A PayPal Source Details object that includes the details of the transaction.

Step 2. Create a PayPal Credit source using DigitalRiver.js

To create a PayPal Credit payment source, you must use the createSource method exposed via DigitalRiver.js.

JavaScript
JavaScript
var payPalData = {
"type": "payPalCredit",
"amount": 120.99,
"currency": "USD",
"payPalCredit": {
"returnUrl": "http://mypage.com",
"cancelUrl": "https://mypage.com/cancel",
"items": [{
"name": "Cell Phone (Unlocked)",
"quantity": 1,
"unitAmount": 100
},
{
"name": "Headphones",
"quantity": 1,
"unitAmount": 15
}
],
"taxAmount": 0.99,
"shippingAmount": 5,
"amountsEstimated": true,
"requestShipping": true,
"shipping": {
"recipient": "Fred Flintstone",
"phoneNumber": "952-555-1212",
"address": {
"line1": "54321 Fake St.",
"line2": "Apt. 3C",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55341"
}
}
}
}
digitalriver.createSource(payPalData).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

PayPal Credit source response example

Source response
Source response
{
"clientId": "gc",
"channelId": "drdod15",
"liveMode": false,
"id": "d6a44e5d-1373-4013-847d-10deb4ded4df",
"clientSecret": "d6a44e5d-1373-4013-847d-10deb4ded4df_ssdd4e5d-1373-4013-847d-10deb4ded4df",
"type": "payPal",
"reusable": false,
"amount": "120.99",
"currency": "USD",
"state": "pending_redirect",
"creationIp": "209.87.178.4",
"createdTime": "2019-05-22T00:00:46.975Z",
"updatedTime": "2019-05-22T00:00:46.975Z",
"flow": "redirect",
"redirect": {
"redirectUrl": "https://api.digitalriver.com:443/payments/redirects/b8f2207b-8236-4608-b5a2-812790d42ed8?apiKey=pk_test_6cb0fe9ce3124093a9ad906f6c589e2ds",
"returnUrl": "https://example.com?action=paymentSuccess",
"cancelUrl": "https://example.com?action=paymentFailure"
},
"payPalCredit": {
"shipping": {
"recipient": "Fred Flintstone",
"phoneNumber": "952-555-1212",
"address": {
"line1": "54321 Fake St.",
"line2": "Apt. 3C",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55341"
}
},
"token": "EC-1HD67063RG318840B"
}
}

Step 3. Authorize a PayPal Credit source

When you create a PayPal Credit Source, the customer is required to authorize the charge at PayPal. You can accomplish this by either redirecting the customer to PayPal or use the PayPal SDK to authorize the charge as part of your experience.

Redirecting the customer to PayPal for authorization

To redirect your customer to PayPal for authorization, use the redirectUrl parameter in your createSource response.

Redirect example
Redirect example
window.location.href = sourceResponse.redirect.redirectUrl;

PayPal will present the customer with the transaction details where they can authorize or cancel the transaction. A successful authorization redirects the customer to the PayPal Return URL parameter you specified when you created the source. If the customer cancels, they will return to the PayPal Cancel URL parameter you specified when you created the source.

Using the PayPal SDK to authorize payment

Use the PayPal Checkout SDK to streamline the authorizing PayPal transactions. This will allow you to control things like the appearance of the PayPal button and embed the entire experience into your workflow.

Example:

  1. Include the PayPal Checkout SDK on your page and specify a location where the button will appear.

    <script src="https://www.paypalobjects.com/api/checkout.js"></script>
    <div id="paypal-button"></div>
  2. Use the PayPal SDK to customize and place the PayPal button on your page. The PayPal SDK returns two functions, onAuthorize and onCancel. If the payment was authorized, use the source you created earlier by attaching to a checkout.

    var paypalSourceData = {
    "type": "payPal",
    "amount": 10,
    "currency": "USD",
    "payPal": {
    "returnUrl": redirectUrl,
    "cancelUrl": cancelUrl,
    "items": [{
    "name": "Galaxy S9+ 256GB (Unlocked)",
    "quantity": 1,
    "unitAmount": 959.99,
    },
    {
    "name": "AKG Y50BT On-Ear Bluetooth Headphones",
    "quantity": 1,
    "unitAmount": 0,
    }
    ],
    "taxAmount": 67.20,
    "shippingAmount": 0,
    "amountsEstimated": true,
    "requestShipping": true,
    "shipping": {
    "recipient": "Fred Flintstone",
    "phoneNumber": "952-555-1212",
    "address": {
    "line1": "54321 Fake St.",
    "line2": "Apt. 3C",
    "city": "Minnetonka",
    "state": "MN",
    "country": "US",
    "postalCode": "55341"
    }
    }
    }
    };
    paypal.Button.render({
    // Configure environment
    env: 'sandbox',
    // Customize button (optional)
    locale: 'en_US',
    style: {
    label: 'credit',
    size: 'responsive',
    color: 'blue',
    shape: 'rect',
    layout: 'horizontal',
    fundingicons: 'false',
    tagline: 'false'
    },
    // Set up a payment
    payment: function(data, actions) {
    return digitalriver.createSource(paypalSourceData).then(function(result) {
    if (result.error) {
    //handle the errors that were returned
    handleErrors(result.error)
    } else {
    return result.source.payPalCredit.token;
    }
    });
    },
    // Execute the payment
    onAuthorize: function(data, actions) {
    //the payment has been authorized, use the source and attach it to your customer's account.
    doSomething();
    },
    onCancel: function(data) {
    //the payment has been cancelled, do something to try and get the shopper back on track
    doSomethingElse();
    }
    }, '#paypal-button');

Step 4. Use the Authorized source

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

Attach the source to a checkout

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