Client reference

This reference describes the JavaScript client methods you will use to implement the Google Pay API in your web applications.

Constructor

Initializes the PaymentsClient object. You must call this constructor before calling member methods.

new PaymentsClient(paymentOptions)

Arguments

Property Description
paymentOptions

An object containing key-value pairs of Google Pay API configuration data. See PaymentOptions for the different properties configurable.

Example: {environment:'PRODUCTION'}

Returns

Type Description
google.payments.api.PaymentsClient The PaymentsClient object.

Throws

Type Description
Error

The passed environment property value is not supported.

Object methods

createButton(options)

A convenience method to generate a Google Pay payment button styled with the latest Google Pay branding for insertion into a webpage.

The generated HTMLElement includes dynamically inserted CSS and an SVG image hosted on Google's CDN.

Please reference our Brand guidelines for more information about selecting the appropriate button color and button type for your site's design. Implementing sites may need to alter the dimensions of a returned Google Pay payment button to match similar buttons or checkout elements on the page.

Arguments

Name Description
options

An object containing key-value pairs for a button configuration. See ButtonOptions for configurable properties.

Example: {onClick:onGooglePaymentButtonClicked}

Returns

Type Description
HTMLElement An HTML <button> inside a generic flow content container such as a <div>.

Throws

Type Description
Error

A required property is not set.

isReadyToPay(isReadyToPayRequest)

Determine a shopper's ability to return a form of payment from the Google Pay API.

Arguments

Name Description
isReadyToPayRequest An object containing methods of payment supported by the merchant. See IsReadyToPayRequest for the different properties configurable.

Returns

Type Description
Promise

Resolved: An object containing information about the user's ability to pay. See IsReadyToPayResponse for more information.

Rejected: An error object containing more information about the reason for rejection. See PaymentsError for more information.

Errors

statusCode Description
DEVELOPER_ERROR
  • The passed IsReadyToPayRequest object was improperly formatted, missing the minimum required parameters to determine a user's readiness to pay, or contains an invalid parameter and/or value.
  • The request was initiated from a security context the payment agent or the browser chose not to fulfill. Most commonly an insecure browser context.

loadPaymentData(paymentDataRequest)

Present a Google Pay payment sheet allowing selection of a payment method and optionally configured parameters.

This method should always be called while the browser is processing an activation behavior as a result of a click event. A popup window may be presented to the user to select a payment method or other required data specified in the passed request parameter.

Arguments

Name Description
paymentDataRequest An object containing key-value pairs of full Google Pay API configuration. See PaymentDataRequest for configurable properties.

Returns

Type Description
Promise

Resolved: An object containing the requested shopper data. See PaymentData for more information.

Rejected: An object containing an error code and more information about the reason for rejection. See PaymentsError for more information.

Errors

statusCode Description
CANCELED
  • The current browser or logged-in Google user is not supported.
  • The shopper dismissed the Google Pay payment sheet without authorizing payment.
  • The request was initiated from a security context the payment agent or the browser chose not to fulfill. Most commonly an insecure browser context.
  • The method was called while the Google Pay payment sheet was already showing.
  • The passed PaymentDataRequest object was was rejected by the Google Pay payment sheet. Missing or incomplete PaymentMethodTokenizationSpecification parameters for your gateway or invalid parameter values are a common cause.
DEVELOPER_ERROR The passed PaymentDataRequest object was improperly formatted, missing the minimum required parameters, or contains an invalid parameter and/or value.

prefetchPaymentData(paymentDataRequest)

Prefetch a PaymentDataRequest configuration to improve loadPaymentData execution time on later user interaction. No value is returned.

Prefetch optimizations are currently available on Chrome for Android with other browsers and platforms to follow.

Arguments

Name Description
paymentDataRequest An object containing key-value pairs of full Google Pay API configuration. See PaymentDataRequest for configurable properties. A change in the transactionInfo property will not affect the cached prefetch value.