Payment sessions

Learn the basics of payment sessions and how to migrate your integration

A payment session tracks a customer's order and payment throughout the checkout flow. Although you're not required to, we highly recommend you use payment sessions to reduce the complexity of building DigitalRiver.js payment collection flows and to comply with PSD2 and Strong Customer Authentication (SCA) regulations.

Migrating to payment sessions is relatively straightforward and mostly involves updating the code for each of your approved payment methods.

Why use payment sessions?

Payment sessions allow you to comply with PSD2 and SCA regulations. When using payment sessions to create credit card sources, applicable PSD2 transactions automatically collect the required authentication data from the customer.

Payment sessions also simplify source creation by reducing the data you're required to provide. If you don't use payment sessions, you'll need to copy data returned in the response and ensure it is properly formatted before passing it to the create source method.

When creating a source with payment sessions, however, you can provide the unique identifier of the session, thereby minimizing the data you must transfer.

They also allow you to gain access to Drop-in, which lessens your front-end development burden. For each transaction, Drop-in needs to retrieve the available payment methods, and the payment session flow supports this functionality.

Creating a source with payment sessions

When creating a source, specify the sessionId in the payload that you pass to the createSource method. The details required to create the source are retrieved from the payment session and a Source object is returned.

JavaScript
JavaScript
let payload = {
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"type": "payPal",
"payPal": {
"returnUrl": "https://yourReturnUrl.com",
"cancelUrl": "https://yourCancelUrl.com"
}
}
digitalriver.createSource(payload).then(function(result) {
if(result.state === "chargeable") {
sendToBackEnd(result);
} else {
doErrorScenario();
}
});

Retrieving available payment methods

With the retrieveAvailablePaymentMethods in DigitalRiver.js, payment sessions allow you to return the payment methods available for each transaction. You can then display these to the customer during the checkout process.

The method also returns the data required to use one-click payment methods like Apple Pay and Google Pay, as well as the data needed to retrieve compliance information via the DigitalRiver.js compliance methods.

JavaScript
JavaScript
digitalriver.retrieveAvailablePaymentMethods({
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f"
}).then(function(result) {
//do something with the data
});

Migrating to payment sessions

Although we generally recommend that you use Drop-in to integrate payments, you can also migrate your existing integration directly to payment sessions.

Once you have completed this migration process, you'll need to build your SCA workflows using Drop-in or Elements.

Enable payment sessions

In the Digital River API, payment sessions are automatically enabled. No additional work is required on your end. When you create a Checkout, you'll see a paymentSessionId returned in the response. This is true even when no payment source has been provided yet. The same identifier is also returned in the Order resource.

JSON
JSON
{
"id": "180601610336",
...
"paymentSessionId": "ab71f890-7fdf-4f1a-a168-94358d3c31c8",
...
}

To enable payment sessions for the Commerce API, you'll need to contact your Account Manager. Once enabled, you'll see the following hash table returned in your Cart responses:

JSON
JSON
{
...
"paymentSession": {
"id": "8af78166-e526-40bd-9c95-1071d161a94a",
"clientSecret": "8af78166-e526-40bd-9c95-1071d161a94a_4179e432-b714-4451-9137-ac08a1d9af19",
"status": "requires_source"
}
...
}

Update your code

You'll need to update your code to fully integrate with payment sessions. For each payment method supported by DigitalRiver.js, add the sessionId parameter to the payload that you pass to the createSource method.

The parameters to remove are specific to each payment method. These parameters, along with example code, are listed in the following sections: Credit Card, PayPal, PayPal Billing, PayPal Credit, Direct Debit, Wire Transfer, Cash on Delivery - Japan, Payco - Korea Payments, Bank Transfer - Korea Payments, Online Banking - IBP, bPay, Konbini, Klarna, Klarna Recurring.

Credit Card

For credit cards, you add sessionId to the payload but do not remove any existing parameters.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
var payload = {
"type": "creditCard",
"owner": {
firstName: "John",
lastName: "Doe",
email: "john.doe@digitalriver.com",
phoneNumber: "000-000-0000",
address: {
line1: "10380 Bren Road West",
line2: "Suite 123",
city: "Minnetonka",
state: "MN",
postalCode: "55343",
country: "US"
}
}
}
digitalriver.createSource(cardCVV, payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"type": "creditCard",
"owner": {
firstName: "John",
lastName: "Doe",
email: "john.doe@digitalriver.com",
phoneNumber: "000-000-0000",
address: {
line1: "10380 Bren Road West",
line2: "Suite 123",
city: "Minnetonka",
state: "MN",
postalCode: "55343",
country: "US"
}
}
}
digitalriver.createSource(cardCVV, payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

PayPal

For PayPal, you add sessionId to the payload and remove amount, currency, payPal.items, payPal.taxAmount, payPal.shippingAmount, payPal.amountsEstimated, payPal.requestShipping, and payPal.shipping.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
var payload = {
"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": "John Doe",
"phoneNumber": "952-555-1212",
"address": {
"line1": "54321 Fake St.",
"line2": "Apt. 3C",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55341"
}
}
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"type": "payPal",
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"payPal": {
"returnUrl": "http://mypage.com",
"cancelUrl": "https://mypage.com/cancel"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

PayPal Billing

For PayPal Billing, you add sessionId to the payload and remove amount, currency, payPalBilling.items, payPalBilling.taxAmount, payPalBilling.shippingAmount, payPalBilling.amountsEstimated, payPalBilling.requestShipping, and payPalBilling.shipping.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
var payload = {
"type": "payPalBilling",
"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": "John Doe",
"phoneNumber": "952-555-1212",
"address": {
"line1": "54321 Fake St.",
"line2": "Apt. 3C",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55341"
}
}
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"type": "payPalBilling",
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"payPal": {
"returnUrl": "http://mypage.com",
"cancelUrl": "https://mypage.com/cancel"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

PayPal Credit

For PayPal Credit, you add sessionId to the payload and remove amount, currency, payPal.items, payPal.taxAmount, payPal.shippingAmount, payPal.amountsEstimated, payPal.requestShipping, and payPal.shipping.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
var payload = {
"type": "payPalCredit",
"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": "John Doe",
"phoneNumber": "952-555-1212",
"address": {
"line1": "54321 Fake St.",
"line2": "Apt. 3C",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55341"
}
}
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"type": "payPalCredit",
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"payPal": {
"returnUrl": "http://mypage.com",
"cancelUrl": "https://mypage.com/cancel"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

Direct Debit

For Direct Debit, you add sessionId to the payload and remove amount and currency.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
let payload = {
"type": "directDebit",
"amount": 100,
"currency": "EUR",
"owner": {
firstName: "John",
lastName: "Doe",
email: "test@digitalriver.com",
phoneNumber: "000-000-0000",
address: {
line1: "123 Main Street",
line2: "",
city: "Paris",
postalCode: "14390",
country: "FR"
}
},
"directDebit": {
"returnUrl": "https://mypage.com"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"type": "directDebit",
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"owner": {
firstName: "John",
lastName: "Doe",
email: "test@digitalriver.com",
phoneNumber: "000-000-0000",
address: {
line1: "123 Main Street",
line2: "",
city: "Paris",
postalCode: "14390",
country: "FR"
}
},
"directDebit": {
"returnUrl": "https://mypage.com"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

Wire Transfer

For Wire Transfer, you add sessionIdto the payload and remove amount and currency.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
let payload = {
"type": "wireTransfer",
"amount": 100,
"currency": "EUR",
"owner": {
firstName: "John",
lastName: "Doe",
email: "test@digitalriver.com",
phoneNumber: "000-000-0000",
address: {
line1: "123 Main Street",
line2: "",
city: "Paris",
postalCode: "14390",
country: "FR"
}
},
"wireTransfer": {
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var data = {
"type": "wireTransfer",
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"owner": {
firstName: "John",
lastName: "Doe",
email: "test@digitalriver.com",
phoneNumber: "000-000-0000",
address: {
line1: "123 Main Street",
line2: "",
city: "Paris",
postalCode: "14390",
country: "FR"
}
},
"wireTransfer": {
}
}
digitalriver.createSource(data).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

Cash on Delivery - Japan

For Cash on Delivery - Japan, you add sessionId to the payload and remove amount and currency.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
let payload = {
"type": "codJapan",
"amount": 100,
"currency": "EUR",
"owner": {
firstName: "John",
lastName: "Doe",
email: "test@digitalriver.com",
phoneNumber: "000-000-0000",
address: {
line1: "123 Main Street",
line2: "",
city: "Paris",
postalCode: "14390",
country: "FR"
}
},
"codJapan": {
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"type": "codJapan",
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"owner": {
firstName: "John",
lastName: "Doe",
email: "test@digitalriver.com",
phoneNumber: "000-000-0000",
address: {
line1: "123 Main Street",
line2: "",
city: "Paris",
postalCode: "14390",
country: "FR"
}
},
"codJapan": {
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

Payco - Korea Payments

For Payco - Korea Payments, you add sessionId to the payload and remove amount and currency.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
let payload = {
"type": "payco",
"amount": 100,
"currency": "KRW",
"owner": {
firstName: "John",
lastName: "Doe",
email: "test@digitalriver.com",
address: {
line1: "1234 Fake Street",
line2: "Yaum-dong",
city: "Ulsan-si",
state: "Kyongsangnamdo",
postalCode: "100-011",
country: "KR"
}
},
"payco": {
"returnUrl": "https://yourReturnUrl.com"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"type": "payco",
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"owner": {
firstName: "John",
lastName: "Doe",
email: "test@digitalriver.com",
address: {
line1: "1234 Fake Street",
line2: "Yaum-dong",
city: "Ulsan-si",
state: "Kyongsangnamdo",
postalCode: "100-011",
country: "KR"
}
},
"payco": {
"returnUrl": "https://yourReturnUrl.com"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

Bank Transfer - Korea Payments

For Bank Transfer - Korea Payments, you add sessionId to the payload and remove amount and currency.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
let payload = {
"type": "bankTransfer",
"amount": 100,
"currency": "KRW",
"owner": {
firstName: "John",
lastName: "Doe",
email: "test@digitalriver.com",
address: {
line1: "1234 Fake Street",
line2: "Yaum-dong",
city: "Ulsan-si",
state: "Kyongsangnamdo",
postalCode: "100-011",
country: "KR"
}
},
"bankTransfer": {
"returnUrl": "https://yourReturnUrl.com"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"type": "bankTransfer",
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"owner": {
firstName: "John",
lastName: "Doe",
email: "test@digitalriver.com",
address: {
line1: "1234 Fake Street",
line2: "Yaum-dong",
city: "Ulsan-si",
state: "Kyongsangnamdo",
postalCode: "100-011",
country: "KR"
}
},
"bankTransfer": {
"returnUrl": "https://yourReturnUrl.com"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

Online Banking - IBP

For Online Banking - IBP, you add sessionId to the payload and remove amount and currency.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
let payload = {
"type": "onlineBanking",
"amount": 100,
"currency": "EUR",
"owner": {
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@digitalriver.com",
"phoneNumber": "000-000-0000",
"address": {
"line1": "52-58 Neue Mainzer Straße",
"line2": "",
"city": "Frankfurt am Main",
"state": "HE",
"postalCode": "60311",
"country": "DE"
}
},
"onlineBanking": {
"returnUrl": "https://myurl.com/success",
"cancelUrl": "https://myurl.com/cancel",
"bankCode": "82"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"type": "onlineBanking",
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"owner": {
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@digitalriver.com",
"phoneNumber": "000-000-0000",
"address": {
"line1": "52-58 Neue Mainzer Straße",
"line2": "",
"city": "Frankfurt am Main",
"state": "HE",
"postalCode": "60311",
"country": "DE"
}
},
"onlineBanking": {
"returnUrl": "https://myurl.com/success",
"cancelUrl": "https://myurl.com/cancel",
"bankCode": "82"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

bPay

For bPay, you add sessionId to the payload and remove amount and currency.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
let payload = {
"type": "bPay",
"amount": 120.99,
"currency": "AUD",
"owner": {
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@digitalriver.com",
"phoneNumber": "000-000-0000",
"address": {
"line1": "3 Bridge Lane",
"line2": "",
"city": "Sydney",
"state": "NSW",
"postalCode": "2000",
"country": "AU"
}
},
"bPay": {}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"type": "bPay",
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"owner": {
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@digitalriver.com",
"phoneNumber": "000-000-0000",
"address": {
"line1": "3 Bridge Lane",
"line2": "",
"city": "Sydney",
"state": "NSW",
"postalCode": "2000",
"country": "AU"
}
},
"bPay": {}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

Konbini

For Konbini, you add sessionId to the payload and remove amount and currency.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
let payload = {
"type": "konbini",
"amount": 120.99,
"currency": "JPY",
"owner": {
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@digitalriver.com",
"phoneNumber": "000-000-0000",
"address": {
"line1": "6 Chome-10-1 Roppongi, Minato",
"state": "Tokyo",
"postalCode": "106-0032",
"country": "JP"
}
},
"konbini": {
"storeId": "010"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"type": "konbini",
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f",
"owner": {
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@digitalriver.com",
"phoneNumber": "000-000-0000",
"address": {
"line1": "6 Chome-10-1 Roppongi, Minato",
"state": "Tokyo",
"postalCode": "106-0032",
"country": "JP"
}
},
"konbini": {
"storeId": "010"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

Klarna

For Klarna, you add sessionId to the payload and remove amount, currency, klarnaCredit.items, klarnaCredit.locale, klarnaCredit.discountAmount, klarnaCredit.taxAmount, klarnaCredit.shippingAmount, klarnaCredit.shipping, klarnaCredit.accountId, klarnaCredit.accountCreatedDate, klarnaCredit.accountUpdatedDate, klarnaCredit.hasPaidBefore, klarnaCredit.subscriptionDescription, klarnaCredit.subscriptionStartDate, klarnaCredit.subscriptionEndDate, klarnaCredit.autoRenewal, and klarnaCredit.affiliateName.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
let payload = {
"type": "klarnaCredit",
"owner": {
"firstName": "John",
"lastName": "Doe",
"email": "email@email.org",
"phoneNumber": "9522253720",
"address": {
"line1": "line1",
"line2": "line2",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55410"
}
},
"amount": "101.50",
"currency": "USD",
"klarnaCredit": {
"returnUrl": "http://example.com/return",
"cancelUrl": "http://example.com/cancel",
"taxAmount": 0,
"shippingAmount": 5.75,
"items": [{
"name": "Happy Ball",
"quantity": "1",
"unitAmount": "94.25",
"subscriptionInfo": {
"autoRenewal": true,
"freeTrial": false
}
},
{
"name": "Happy Ball1",
"quantity": "2",
"unitAmount": "0.75"
}],
"locale": "en_US",
"shipping": {
"recipient": "Guy Incognito",
"phoneNumber": "9522253720",
"address": {
"line1": "line1",
"line2": "line2",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55410"
},
"email": "test_email@email.org"
},
"accountId": "456789",
"accountCreatedDate": "2020-11-24T15:20:00.000Z",
"accountUpdatedDate": "2012-11-25T15:30:00.001Z",
"hasPaidBefore": false,
"subscriptionDescription": "Klarna Credit Recurring",
"subscriptionStartDate": "2019-10-24T15:00:00.030Z",
"subscriptionEndDate": "2021-10-24T15:00:00.030Z",
"autoRenewal": "false",
"affiliateName": "Sample Affiliate"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"type" : "klarnaCredit",
"owner" : {
"firstName" : "firstName",
"lastName" : "lastName",
"email" : "email@email.org",
"phoneNumber" : "9522253720",
"address" : {
"line1" : "line1",
"line2" : "line2",
"city" : "Minnetonka",
"state" : "MN",
"country" : "US",
"postalCode" : "55410"
}
},
"sessionId" : "3aa75613-9596-438a-9604-67e20016aa96",
"klarnaCredit" : {
"returnUrl" : "http://example.org/return",
"cancelUrl" : "http://example.org/cancel"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});

Klarna Recurring

For Klarna Recurring, you add sessionId to the payload and remove amount, currency, klarnaCreditRecurring.items, klarnaCreditRecurring.locale, klarnaCreditRecurring.discountAmount, klarnaCreditRecurring.taxAmount, klarnaCreditRecurring.shippingAmount, klarnaCreditRecurring.shipping, klarnaCreditRecurring.accountId, klarnaCreditRecurring.accountCreatedDate, klarnaCreditRecurring.accountUpdatedDate, klarnaCreditRecurring.hasPaidBefore, klarnaCreditRecurring.subscriptionDescription, klarnaCreditRecurring.subscriptionStartDate, klarnaCreditRecurring.subscriptionEndDate, klarnaCreditRecurring.autoRenewal, and klarnaCreditRecurring.affiliateName.

The following tabs provide code examples of how sources are created without and with payment sessions.

Without payment sessions
With payment sessions
Without payment sessions
let payload = {
"type": "klarnaCreditRecurring",
"owner": {
"firstName": "John",
"lastName": "Doe",
"email": "email@email.org",
"phoneNumber": "9522253720",
"address": {
"line1": "line1",
"line2": "line2",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55410"
}
},
"amount": "101.50",
"currency": "USD",
"klarnaCreditRecurring": {
"returnUrl": "http://example.com/return",
"cancelUrl": "http://example.com/cancel",
"taxAmount": 0,
"shippingAmount": 5.75,
"items": [{
"name": "Happy Ball",
"quantity": "1",
"unitAmount": "94.25",
"subscriptionInfo": {
"autoRenewal": true,
"freeTrial": false
}
},
{
"name": "Happy Ball1",
"quantity": "2",
"unitAmount": "0.75"
}],
"locale": "en_US",
"shipping": {
"recipient": "Guy Incognito",
"phoneNumber": "9522253720",
"address": {
"line1": "line1",
"line2": "line2",
"city": "Minnetonka",
"state": "MN",
"country": "US",
"postalCode": "55410"
},
"email": "test_email@email.org"
},
"accountId": "456789",
"accountCreatedDate": "2020-11-24T15:20:00.000Z",
"accountUpdatedDate": "2012-11-25T15:30:00.001Z",
"hasPaidBefore": false,
"subscriptionDescription": "Klarna Credit Recurring",
"subscriptionStartDate": "2019-10-24T15:00:00.030Z",
"subscriptionEndDate": "2021-10-24T15:00:00.030Z",
"autoRenewal": "false",
"affiliateName": "Sample Affiliate"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});
With payment sessions
var payload = {
"type" : "klarnaCreditRecurring",
"owner" : {
"firstName" : "firstName",
"lastName" : "lastName",
"email" : "email@email.org",
"phoneNumber" : "9522253720",
"address" : {
"line1" : "line1",
"line2" : "line2",
"city" : "Minnetonka",
"state" : "MN",
"country" : "US",
"postalCode" : "55410"
}
},
"sessionId" : "3aa75613-9596-438a-9604-67e20016aa96",
"klarnaCreditRecurring" : {
"returnUrl" : "http://example.org/return",
"cancelUrl" : "http://example.org/cancel"
}
}
digitalriver.createSource(payload).then(function(result) {
if (result.error) {
//handle errors
} else {
var source = result.source;
//send source to back end
sendToBackend(source);
}
});