Using the source identifier

Learn how a Source identifier can be used to charge a single-use Source, attach a Source to a Customer, or select a different default payment method.

The sourceId attribute in the Checkout resource and the sources[].id attribute in the Customer resource uniquely identify a Source object. The following sections describe common scenarios in which you might use these identifier values.

Charging a single-use source

Your storefront may be configured so that customers are not required to create an account or sign-in to make a purchase. In this case, after you submit the guest customer's payment details, DigitalRiver.js will create a Source and return the sourceId . You can then use an update Checkout request to set the sourceId attribute.

cURL
cURL
curl --location --request POST 'https://api.digitalriver.com/checkouts/177642590336' \
--header 'Authorization: <API_key>' \
--header 'Content-Type: text/plain' \
--data-raw '{
"sourceId": "7a3ce24c-5e18-4b8d-a667-d64a513ed33f"
}'

Since the Source is not attached to a Customer, this payment method object cannot be re-used for future purchases and once charged, its state becomes consumed.

Attaching a source to a customer

The Digital River API gives you the ability to save payment sources associated with a customer for later reuse. After you submit a customer's payment details, DigitalRiver.js will create a Source and return a sourceId. You can then use that sourceId to attach the Source to a Customer.

curl --location --request POST 'https://api.digitalriver.com/customers/08161945/sources/7a3ce24c-5e18-4b8d-a667-d64a513ed33f' \
--header 'Authorization: Bearer <API_key> \

You should only attach a Source whose underlying payment method supports re-usability. Otherwise the reusable value remains false and the customer can't apply that Source to future orders.

Detaching a source from a customer

If you'd like to delete a Source associated with a Customer, you can detach the object. When you do so, the state of the Source switches to consumed and it cannot be used to create any future charges.

Switching the default payment source

Registered customers may have multiple saved payment methods associated with their account. These Source objects are stored in the sources array of the Customer resource.

The first Source attached to a Customer becomes the default payment method and its identifier is assigned to the defaultSourceId attribute. If you'd like to assign a different, already attached Source as the default, simply submit an update Customer request and specify the preferred defaultSourceId.