Google Pay elements

Learn how to use Google Pay elements.

Use DigitalRiver.js to create a Google Pay element and interact with Google Pay.‌

Creating a Google Pay element

To create a Google Pay element, you should use the createElement function exposed through the DigitalRiver object.

To create a Google Pay element, you should use the createElement function exposed through the DigitalRiver object.

Example
Example
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"
}
});
var googlepay = digitalriver.createElement('googlepay', paymentRequestData);

Google Pay element styles and customization

Button type

Choose one of the following button types:

Button color

Choose one of the following button colors:

Google Pay element functions

googlepay.canMakePayment();

Example
Example
if(googlepay.canMakePayment()) {
}

googlepay.mount();

Call this function to place the created Google Pay element on your page.

Example
Example
<div id="google-pay"></div>
if(googlepay.canMakePayment()) {
googlepay.mount('google-pay');
}

googlepay.show();

Call this function to show the Google Pay Payment Request interface. This will automatically happen when using the element. If you'd like to trigger using another mechanism, you must call it as part of the user interaction (click handler).

Example
Example
googlepay.show();

googlepay.unmount();

Call this function to remove the Google Pay element from your page. The element may be re-added to your page by calling mount().

Example
Example
googlepay.unmount();

googlepay.destroy();

Call this function to remove the Google Pay element from your page as well as remove its functionality. You cannot re-add the destroyed element to your page via mount().

Example
Example
googlepay.destroy();

googlepay.update();

Call this function to update the Google Pay element's data.

Example
Example
var paymentRequest = digitalriver.paymentRequest({
country: "US",
currency: "USD",
total: {
label: "Order Total",
amount: 100
},
displayItems: lineItems,
shippingOptions: shippingOptions,
style: {
buttonType: "plain",
buttonColor: "dark",
buttonLanguage: "en"
}
});
googlepay.update(paymentRequest);

Google Pay element events — googlepay.on('event', handler);

The Google Pay Element can receive the following events by creating an event listener. Use this function to listen to events that can be used to build and enhance your purchase flow.

Event

Triggered When

ready

The created element is loaded and ready to accept an update request.

click

A shopper clicked the element's button.

cancel

The customer has canceled the experience.

shippingoptionchange

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).

shippingaddresschange

The customer has chosen a different address than was previously selected. You should use this data to re-price your order totals (if applicable).

source

The customer has authorized the payment and a source, and DigitalRiver.js returned its associated data.

Source

The Source event emits when the Customer completes their interaction with the Payment Request interface, and they create a Payment Source. The emitted object will be a Payment Request Response object.

Example
Example
googlepay.on('source', function(result) {
var source = result.source;
//pass the source to your back end for further processing
}

Ready

The Ready event emits when the Google Pay Element has loaded and is available to take an update() call.

Example
Example
googlepay.on('ready', function(event) {
//google pay can accept an update call
}
Example
Example
{
elementType: "googlepay"
}

Click

The Click event emits when the customer clicks a Google Pay Element.

Example
Example
googlepay.on('click', function(event) {
//do stuff
}
Response object
Response object
{
elementType: "googlepay"
}

Cancel

The Cancel event emits when the customer closes the Google Pay Element Payment Request interface.

Example
Example
googlepay.on('shippingoptionchange', function(event) {
var shippingOption = event.shippingOption;
//create a Payment Request Details Update Object
var newDetails = createPaymentRequestDetailsUpdateObject();
event.updateWith(newDetails);
});
Response ojbect
Response ojbect
{
"shippingOption": {
"id": "overnight-shipping",
"label": "Overnight Shipping",
"amount": 100,
"detail": "Get this in 1 business day."
},
"updateWith": function(data) {
callback(data);
}
}

Shipping option change

The Shipping Option Change event emits when the Customer selects a different Shipping Option within the Payment Request interface. The event will emit the following object structure.

Key

Type

Description

updateWith

Function

Calling this function with a Payment Request Details Update object merges your updates into the current Payment Request object.

shippingOption

A Payment Request Details Update object

A Payment Request Shipping Option object contains the details of the customer's chosen Shipping Option.

Example
Example
googlepay.on('shippingaddresschange', function(event) {
var shippingAddress = event.shippingAddress;
//create a Payment Request Details Update Object
var newDetails = createPaymentRequestDetailsUpdateObject();
event.updateWith(newDetails);
});
Response object
Response object
{
shippingAddress: {
"name": "John Smith",
"firstName": "John",
"lastName": "Smith",
"phone": "952-111-1111",
"email": "[email protected]",
"address": {
"line1": "10380 Bren Rd W",
"line2": "string",
"city": "Minnetonka",
"postalCode": "55129",
"state": "MN",
"country": "US"
}
},
"updateWith": function(data) {
callback(data);
}
}

Shipping address change

The Shipping Address Change emits when the Customer selects a different Shipping Address within the Payment Request interface. The event will emit the following object structure.

Key

Type

Description

updateWith

Function

Calling this function with a Payment Request Details Update object merges your updates into the current Payment Request object.

shippingAddress

A Shipping Address object

A Shipping Address object contains the details of the customer's chosen Shipping Option.

Example
Example
googlepay.on('shippingaddresschange', function(event) {
var shippingAddress = event.shippingAddress;
//create a Payment Request Details Update Object
var newDetails = createPaymentRequestDetailsUpdateObject();
event.updateWith(newDetails);
});
Response object
Response object
{
shippingAddress: {
"name": "John Smith",
"firstName": "John",
"lastName": "Smith",
"phone": "952-111-1111",
"email": "[email protected]",
"address": {
"line1": "10380 Bren Rd W",
"line2": "string",
"city": "Minnetonka",
"postalCode": "55129",
"state": "MN",
"country": "US"
}
},
"updateWith": function(data) {
callback(data);
}
}