Are you interested in attending a Google Pay launchathon in your city? Let us know!

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

isReadyToPay(request)

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

Arguments

Property Description
request

An object containing key-value pairs of methods of payments supported by the merchant. See IsReadyToPayRequest for the different properties configurable.

Example: {allowedPaymentMethods:['CARD']}

Returns

Type Description
Promise

Resolved: An object containing a result property set to a boolean indicating payment readiness. Example: {result: true}

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

Errors

statusCode Description
DEVELOPER_ERROR

The passed IsReadyToPay 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.

loadPaymentData(request)

Present a payments dialog to a Google user allowing selection of a payment method and optionally configured parameters.

Arguments

Property Description
request 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 payment chooser without authorizing payment.
  • The request was initiated from a security context the payment agent or the browser chose not to fulfill.
  • The method was called while a payments chooser was already showing.
  • The passed PaymentDataRequest object was was rejected by the payments chooser. Missing or incomplete PaymentMethodTokenization parameters for your gateway or invalid parameter values are a common cause. Device logs may contain a more detailed error message.
DEVELOPER_ERROR The passed PaymentDataRequest object was improperly formatted, missing the minimum required parameters, or contains an invalid parameter and/or value.

prefetchPaymentData(request)

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

Arguments

Property Description
request 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.

Send feedback about...

Google Pay API