Configuring Google Pay
Learn how to configure Google Pay for DigitalRiver.js with Elements.
If you're using DigitalRiver.js with Elements, you can create a Google Pay payment method for your app or website in two easy steps:
Step 1: Create a Google Pay source using Digital River.js
To create a Google Pay payment source, follow the instructions for creating a Google Pay element.
Create a Google Pay element
After setting up your library per the DigitalRiver.js reference guide, create a Google Pay element with any customizations you would like to apply.
var paymentRequestData = digitalriver.paymentRequest({
country: "US",
currency: "USD",
total: {
label: "Order Total",
amount: 100
},
displayItems: lineItems,
shippingOptions: shippingOptions,
style: {
buttonType: "plain",
buttonColor: "dark",
buttonLanguage: "en"
},
"sessionId": "9f180964-9da4-43ac-b8e0-ae54d832b03c"
});
var googlepay = digitalriver.createElement('googlepay', paymentRequestData);Configure the Google Pay element to handle events
The Google Pay element will surface events, which will give you more information to facilitate what is happening within the Google Pay experience.
These events include:
The created element is loaded and ready to accept an update request.
A shopper clicked the element's button.
The customer has canceled the experience.
The customer has chosen a different shipping option than was previously selected. You should use this data to re-price your order totals (if applicable).
The customer has chosen a different address than was previously selected. You should use this data to re-price your order totals (if applicable).
The customer has authorized the payment and a source, and DigitalRiver.js returned associated data.
The Shipping Address Changed and Shipping Method Changed events require a response with updated details to present to the Shopper. This system expects the response to be a Payment Request Details Update object.
Place the elements on the page
The following example shows how to place the elements on the page. For more information on placing elements on a page, see Google Pay example.
Receive the source event and use the source
Google Pay example
The source event will surface a Source plus other details provided from Google Pay, such as the shopper's billing address, shipping address, and contact information, in the response.
Step 2: Use the authorized source
Once authorized, you can use the source by attaching it to a checkout or a customer for multiple uses.
Option 1. Attach the source to a cart
Option 2. Attach the source to a customer
Google Pay example
The following example shows how to place a Google Pay element on your page. Use this in conjunction with the DigitalRiver.js reference guide to build your solution.
Testing Google Pay
See Testing standard payment methods for testing instructions.
Last updated