Managing sources
Learn how to manage sources.
Commerce API has two broad categories of payment sources: primary and secondary.
After you create a payment source for both categories, you can attach it to a cart so we can use it to generate a one-time charge. You can also detach sources from carts.
If the primary source supports reusability, save it to a customer's account. For shoppers with multiple saved payment sources[]
, we also provide you the ability to set the default one.
You can combine primary and secondary sources, but how you sequence their application depends on whether or not the primary source is reusable.
And when building your payment flows, the DigitalRiver object exposes methods for authenticating and updating sources that can be useful in purchase and account management scenarios.
When building your payment workflows, you should know the differences between primary and secondary payment sources and how they affect the payment session.
Primary payment sources
Primary payment sources come from traditional payment methods such as credit cards, Google Pay, and Pay Wire Transfers. Most customers use a primary source when purchasing, but a cart can only contain one primary source.
Primary sources created from payment methods that support reusability may be able to be associated with a customer and then reused in future transactions.
Alternatively, you can attach a primary source to a cart, thereby enabling Digital River to submit a charge authorization request after you submit the cart.
Secondary payment sources
Secondary payment sources are typically used to supplement a primary source.
Commerce API currently only supports thecustomerCredit
type as a supported secondary source.
You can successfully submit an order entirely with secondary sources, but you must ensure the payment session state is valid and the amount contributed is sufficient.
You cannot edit the amount
value for a secondary source. To change the amount
value for the secondary source:
Create a new secondary source with the correct amount.
If needed, attach the primary source to the cart.
Attach the secondary source to the cart first. The primary source will cover the remaining amount. If you attach the primary source first, the primary source will cover the entire amount, and the secondary source will be ignored when the order is submitted.
Secondary sources do not support reusability. Therefore, they cannot be saved to a customer's account. They should only be attached to a cart to create a one-time charge when that cart is converted to an order.
Creating payment sources
We provide multiple options for creating primary sources and creating secondary sources.
Creating primary sources
You create primary sources with your public API key using Drop-in payments or DigitalRiver.js with elements. Once the source is chargeable
, you should either attach the source to a cart or save the source to a customer's account.
Creating secondary sources
You create secondary sources through the Sources API by sending your confidential API key in a POST/sources
request.
When defining the request, you retrieve the payment session identifier from the cart you're building. The amount
is optional, except when the type
is customerCredit
. The type
is required, and we currently only support customerCredit
. You must also send an empty hash table whose name matches the type
.
The owner
hash table is optional and can be used to meet our billing address requirements. You can provide the owner's information, including the address, when creating a secondary source.
We recommend not providing an owner object with the secondary source. This ensures that the wrong address is not applied to the cart, which will trigger a payment auth failed error.
The upstreamId
parameter is useful for mapping the source to your credit management system.
A 201 OK
response returns a unique source in a chargeable
state. You should attach it to a cart so that we can use it to generate a one-time charge.
Combining primary and secondary payment sources
You can associate a primary payment source with only one secondary payment source.
In the Cart API, the following payment methods support the use of customerCredit
: Credit Cards, Google Pay, Klarna, PayPal Express Checkout, PayPal Credit, PayPal Billing Agreement, and Wire Transfer.
We currently only support customerCredit
as a secondary source.
Attaching multiple payment sources to the cart
You can only associate one primary source with a cart. If there's a primary source in the cart and you try to attach a different primary source, remove all attached sources or remove the attached primary payment source directly from the cart, then attach new sources.
Always apply the secondary sources first when using multiple sources in a cart. Apply the primary source last.
For a list of payment methods that support reusability, refer to the Supported payment methods.
Choose one of the best practices below to attach two sources to a cart.
Best practice 1: Use /apply-payment-method
Use the following steps for both authenticated shoppers and anonymous shoppers.
Send the
POST /apply-payment-method
request to attach a secondary source.Send the
POST /apply-payment-method
request to attach a primary source.
Best practice 2: Use /apply-payment-method and /apply-shopper
Use the following steps only for authenticated shoppers.
Send the POST /apply-payment-method request to attach a secondary source
Send the
POST /apply-shopper
request to attach the primary source. The default payment option saved to the shopper will be applied to the cart when applying a shopper. Note that the shopper can only save the primary source to their account.
Address information
When you attach a source to the cart using the POST /apply-payment-method
The system will not use the address if the cart already has address information. It will use the existing address in the cart. If the cart does not have the address information, the system will copy the address from the source
to the cart.
This behavior applies to both primary and secondary sources. This is why we recommend not including the owner information when you create a secondary source.
When you attach a source to a shopper using POST /payment-options
, the system will save the source's payment information and address to the shopper's payment options and associate the address with the payment. When you apply a shopper to a cart using POST /apply-shopper
, the system will apply the shopper's default payment method and copy the address associated with the payment method to the card, regardless of whether the cart has an address available.
Amount contributed from each payment source
After applying the payment source to the cart, the amount contributed by the payment source appears in the amountContributed
field for the paymentMethod
object in the /cart, /submit-cart, and /order responses.
Amount contribution of the entire order
The paymentSession
object shows the following information for an entire order:
amountContributed
: indicates the accumulated contributed amount of the attached payment sources.amountRemainingToBeContributed
: indicates the gap amount required to fulfill the order. If the value is not zero, the shopper should pay the remaining cost to cover the order's total amount.
Detaching payment sources from a cart
Use one of the following options to remove all attached sources directly from a cart.
DELETE v1/shoppers/me/carts/active/apply-payment-method
removes a payment source from the cart. Use this option and include the source ID in the payload to remove payment sources individually.DELETE v1/shoppers/me/carts/active/payment
removes all attached sources directly from the cart
When finished, you can attach new sources to the cart.
Refunds
The system will first refund the primary payment source if a customer requests a refund. Once the system fully refunds the primary source, the system will use the secondary payment source to refund the remaining value.
For example, a customer purchased a line item quantity of 10 for $1000. They used $600 from their primary payment source (a credit card) and $400 from their secondary (store credit) to pay for the order. If the customer requests a refund of $400, the system refunds $400 to their credit card. If the customer requests a refund of $700, the system refunds $600 to their credit card and $100 to their store credit.
Charging a single-use payment source
Your storefront may be configured so that customers are not required to create an account or sign in to purchase. In this case, after you submit the guest customer's payment details, DigitalRiver.js with elements will create a Source and return the sourceId
.You can then use a POST /apply-payment-method
request to set the sourceId
attribute.
Since the Source is not attached to a Shopper, this payment method object cannot be reused for future purchases, and once used, its state becomes consumed
.
Switching the default payment source
Registered customers may have multiple saved payment methods associated with their accounts. These Source objects are stored in the sources
array of the Payment Options resource.
The first source you attach to a customer becomes its default, sets isDefault
as true
, and assigns to the customer's sourceId
attribute. If you'd like to assign a different default payment source, submit a POST /payment-options/{id}
request where {id}
is the new default payment method and set isDefault
to true
.
Last updated