Learn the basics of payment sessions and how to migrate your integration.
A payment session tracks a customer's payment throughout the checkout process. 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 SCA regulations.
Payment sessions allow you to comply with PSD2 and SCA regulations. Digital River automatically collects the required authentication data from the customer's PSD2 transactions when using payment sessions to create credit card sources.
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 numerous data points returned in the cart and ensure it is properly formatted before passing them to the create source method.
When creating a payment source, specify the sessionId in the payload that you pass to the DigitalRiver.js create source method. The data our payment services need to create the source is then retrieved from that session.
We highly recommend using payment sessions when creating a payment source in a cart flow to reduce the complexity of building the DigitalRiver.js payment collection flows and to comply with PSD2 and SCA regulations.
The cart's payment.session.state must be requires_confirmation before you convert that cart to an order.
This state indicates that the cart's payment sources[] are sufficient to fund the transaction. For example, when you attach a chargeableprimary source to a checkout, the amount remaining to contribute drops to zero, and the session's state transitions to requires_confirmation.
Requires source
A cart's payment.session.state can be requires_source for either of the following reasons:
In both of these scenarios, we won't be able to generate a charge amount large enough to cover the checkout's totalAmount. So, the amount remaining to contribute remains greater than zero, and any attempt to create an order is blocked.
Complete
The payment session state typically transitions to complete once the order is created.
Amount contributed and amount remaining to be contributed
Once a primary payment source is attached to a cart, we use it to fully fund the transaction.
But when only secondary payment sources are attached, you need to confirm sufficient funds exist to cover the cart's totalAmount. If this isn't the case, when you convert the cart to an order, you receive the following error:
By comparing values in the cart's payment.session, you can determine how much additional funding, if any, is still required. The amountContributed represents the aggregated amount of all the cart's payment.sources[]. The amountRemainingToBeContributed is how much is needed to fully fund the transaction.
If the amountContributed is equal to the cart's totalAmount or the amountRemainingToBeContributed is zero, then you don't need to request any more payment methods from the customer. This means that once the payment session is in the correct state, and all address requirements are met, you can convert the cart to an order.
But if the amountContributed is less than the cart's totalAmount or the amountRemainingToBeContributed is greater than zero, the customer needs to supply additional payment methods before an order can be successfully created. However, this will only be the case when a primary payment source is not yet attached to the checkout. Once that's done, we use it to fully fund the transaction and amountRemainingToBeContributed drops to zero.
The method also returns the data required to use one-click payment methods like Apple Pay and Google Pay and the data needed to retrieve compliance information via the DigitalRiver.js compliance methods.
Migrating to payment sessions
Although we generally recommend using Drop-in payments to handle payments, you can also migrate your existing integration directly to payment sessions. For the Commerce API, payment sessions must be enabled.
{
"type": "bad_request",
"errors": [
{
"code": "order_submit_failed",
"message": "Payment session status is invalid."
}
]
}
digitalriver.retrieveAvailablePaymentMethods({
"sessionId": "ea03bf6f-84ef-4993-b1e7-b7d5ecf71d1f"
}).then(function(result) {
//do something with the data
});