Search…
⌃K
Links

Retrieving sources

Learn how to retrieve a single source as well as all the Source objects attached to a customer.

Get a source object by identifier

The following GET/sources/{id} request retrieves a source by supplying its unique identifier as a path parameter.
This identifier was returned when you used the DigitalRiver.js library to create the source.
cURL
curl --location --request GET 'https://api.digitalriver.com/sources/e59c8303-139a-4077-bd26-78d20b43d52b' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer '<API_key>' \
If a valid identifier and API key are provided, the response returns a Source object. This sample response returns a Source with a type of creditCard and a state of chargeable.
Only the last four digits of credit card numbers are returned by a GET Source request.
JSON
{
"id": "e59c8303-139a-4077-bd26-78d20b43d52b",
"createdTime": "2020-06-17T19:54:54Z",
"type": "creditCard",
"currency": "USD",
"amount": 24.89,
"reusable": true,
"state": "chargeable",
"customerId": "517796760336",
"owner": {
"firstName": "William",
"lastName": "Brown",
"email": "[email protected]",
"address": {
"line1": "10380 Bren Road West",
"city": "Minnetonka",
"postalCode": "55343",
"state": "MN",
"country": "US"
}
},
"paymentSessionId": "8ff5840f-b0ec-44f2-8e88-647627a0ba0d",
"clientSecret": "e59c8303-139a-4077-bd26-78d20b43d52b_5e943931-e4e7-4537-8ae4-f7ff991f463c",
"creditCard": {
"brand": "MasterCard",
"expirationMonth": 5,
"expirationYear": 2025,
"lastFourDigits": "0008"
},
"liveMode": false
}

Obtain a shopper's sources

You can retrieve the Sources associated with a Shopper by making a get shopper by ID request and parsing the sources array contained in the response if the payment source is attached to the shopper's payment option. When the shopper gets their payment options, all payment sources will be listed.

Step 1: Create your first payment source and option

  1. 1.
    Create your first payment source using: POST https://{{dispatchHost}}/payments/sources/
  2. 2.
    Create your first payment option using: POST https://{{dispatchHost}}/v1/shoppers/me/payment-options/
cURL
curl --location --request POST 'https://api.digitalriver.com/v1/shoppers/me/payment-options/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API_key>' \
--data-raw '{
"paymentOption" : {
"nickName" : "Credit Card",
"isDefault" : "true",
"sourceId":"{{sourceId1}}"
}
}'

Step 2: Create your second payment source and option

  1. 1.
    Create your second payment source using: POST https://{{dispatchHost}}/payments/sources/
  2. 2.
    Create your second payment option using: POST https://{{dispatchHost}}/v1/shoppers/me/payment-options/
Request body
curl --location --request POST 'https://api.digitalriver.com/v1/shoppers/me/payment-options/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API_key>' \
--data-raw '{
"paymentOption" : {
"nickName" : "PayPal",
"isDefault" : "true",
"sourceId":"{{sourceId2}}"
}
}'

Step 3: Get the shopper's payment options

Get the shopper's payment options using: GET https://{{dispatchHost}}/v1/shoppers/me/payment-options/
Response body
curl --location --request POST 'https://api.digitalriver.com/v1/shoppers/me/payment-options/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API_key>' \
--data-raw '{
"paymentOptions": {
"uri": "https://dispatch-test.digitalriver.com/v1/shoppers/me/payment-options",
"paymentOption": [
{
"uri": "https://dispatch-test.digitalriver.com/v1/shoppers/me/payment-options/15578475589",
"nickName": "Credit Card",
"isDefault": "false"
},
{
"uri": "https://dispatch-test.digitalriver.com/v1/shoppers/me/payment-options/15578475689",
"nickName": "PayPal",
"isDefault": "true"
}
]
}
}'

Display a customer's sources

The data contained in the sources array can be used to display a customer's saved payment methods on your website or app. To do this, parse the response and extract the values in the creditCard, owner, and address hash tables. You can then use these values to present the card's brand name, last four digits, expiration date, and the customer's billing information.