Airwallex JS
Airwallex logoAirwallex logo

Google Pay Button Element

Copy for LLMView as Markdown
The Google Pay™ Element allows you to offer Google Pay checkout option on your website. Shoppers can click the Google Pay button and pay using facial or fingerprint recognition.

createElement('googlePayButton', options?)

Use this function to create an instance of an individual Element.

Parameters

type

required'googlePayButton'
The type of element you are creating.

options

optionalGooglePayButtonOptions
Options for creating googlePayButton Element.

amount

requiredAmount

Indicate the amount and currency of the Payment Intent. If the mode is set to 'recurring' and intent_id omitted, amount should be {value: '0', currency: 'Replace with payment currency'}.

countryCode

requiredstring
The two-letter ISO-3166 country code.

allowCreditCards

optionalboolean
Whether a credit card may be used for this transaction.
Default: true

allowedAuthMethods

optionalCardAuthMethod[]
Allowed authentication methods.
Default: ['PAN_ONLY', 'CRYPTOGRAM_3DS']

allowedCardNetworks

optional('MASTERCARD' | 'MAESTRO' | 'VISA' | 'AMEX' | 'DISCOVER' | 'JCB')[]
One or more card networks that you support.

allowPrepaidCards

optionalboolean
Whether a prepaid card may be used for this transaction.
Default: true

appearance

optionalGooglePayButtonAppearance
Customize the appearance of the Google Pay button.

assuranceDetailsRequired

optionalboolean
Set to true if you need information about the validation performed on the returned payment data.
Default: false

authFormContainer

optionalstring
The container id of the authentication form used in 3D Secure authentication.

authorizationType

optional'pre_auth' | 'final_auth'

The authorization type for the card payment. Options include: "pre_auth", "final_auth". Set it to "pre_auth" if you want to place a hold on your customer's card for more than 7 days, i.e., extend the authorization time window. Currently it's only available when the card brand is Visa or Mastercard. autoCapture will be automatically set to false if you enable pre_auth.

Default: 'final_auth'

autoCapture

optionalboolean

Whether the amount should be captured automatically upon successful payment authorization. Set it to false if you want to place a hold on the payment method and capture the funds sometime later.

Default: true

billingAddressParameters

optionalBillingAddressParameters
Optional billing address parameters for the returned billing address.

billingAddressRequired

optionalboolean
Whether a billing address is required from the shopper.
Default: false

buttonColor

optionalenum
Specifies the button color of the Google Pay button.
Default: 'default'

buttonSizeMode

optionalenum

Determines how the button's size should change relative to the button's parent element.

Default: 'static'

buttonType

optionalenum
Specifies the text to be displayed within the Google Pay button.

callbackIntents

optionalCallbackIntent[]

List of callbacks that the developer intents to handle. Upon selection by the shopper, these intents can be used to update the request with new data based on that selection (For exmaple, if a shipping option is selected, the developer could update the transactionInfo with new totalPrice and diplayItems).

checkoutOption

optionalCheckoutOption
The options for checkout.

client_secret

optionalstring

The client_secret of the Payment Intent when Payment Intent is provided. Otherwise, this should be the client_secret of the Customer object. Leave it empty if intent_id and customer_id are not provided.

customer_id

optionalstring

The ID of the Customer used in registered user checkout. Refer to Airwallex Client API This field is required when mode is 'recurring'.

displayItems

optionalDisplayItem[]
Description of a cart item.

emailRequired

optionalboolean
Whether the shopper must provide their email.
Default: false

error

optionalPaymentDataError

Error displayed to the shopper for erroneous payment data. For example, you can update error when user selects the wrong shipping option. Note: This field is currently available for web only.

existingPaymentMethodRequired

optionalboolean
Whether the shopper must use an existing payment method.
Default: false

gatewayMerchantId

optionalstring
The merchant account ID in Airwallex. It is required for Google Pay Express Checkout Element.

intent_id

optionalstring

The ID of the Payment Intent you would like to checkout. Refer to Airwallex Client API

merchantInfo

optionalobject
Detailed information about the merchant.

mode

optional'payment' | 'recurring'
The checkout mode for the shopper.

offerInfo

optionalOfferInfo

Offers available for redemption that can be used with the current order.

payment_consent

optionalPaymentConsentOptions
Options for PaymentConsent.

paymentDataCallbacks

optionalPaymentDataCallbacks

Defines callback methods for handling changed payment data and payment authorized events.

shippingAddressParameters

optionalShippingAddressParameters
Optional shipping address parameters for the returned shipping address.

shippingAddressRequired

optionalboolean
Whether a shipping address is required from the shopper.
Default: false

shippingOptionParameters

optionalShippingOptionParameters

Parameters for shipping option that can be used in this request. Note: This field is currently for web only.

shippingOptionRequired

optionalboolean

Whether a shipping option is required from the shopper.

Note: This field is currently for web only.

Default: false

style

optionalCSSProperties & PopUpStyle
Box style and 3ds popUp style for the GooglePayButton Element.

totalPriceLabel

optionalstring

Total price label of this transaction. The string will be shown as the total price label on the cart modal dialog page. This field is optional, but required if developer wants to show cart information. Otherwise the cart modal dialog will not be rendered.

totalPriceStatus

optionalenum

The status of the total price. If it is a variable subscription, the status should be NOT_CURRENTLY_KNOWN.

Default: 'FINAL'

transactionId

optionalstring

Correlation ID to refer to this transaction.

This field is optional. It is generated by the merchant and used to reference this transaction later, such as for debugging issues when communicating with Google.

Returns

GooglePayButtonElement | null

createElement('googlePayButton', options?)

1import { init, createElement } from '@airwallex/components-sdk';
2
3await init({
4 env: 'prod',
5 enabledElements: ['payments'],
6});
7
8const element = await createElement('googlePayButton', {
9 intent_id: 'replace-with-your-intent-id',
10 client_secret: 'replace-with-your-client-secret',
11 amount: {
12 value: 'replace-with-your-intent-amount',
13 currency: 'replace-with-your-intent-currency',
14 },
15 countryCode: 'replace-with-your-country-code',
16});
17
18element.mount('googlepay-container');

confirmIntent(data)

Call this function when the shopper is ready to make a payment as per the details in the Payment Intent.

Parameters

data

requiredConfirmIntentData

client_secret

requiredstring
The client_secret of the Payment Intent when Payment Intent is provided. Otherwise, this should be the client_secret of the Customer object.

payment_consent

optionalPaymentConsentOptions
Options for PaymentConsent.

Returns

Promise<Intent>

Intent

requiredobject

id

requiredstring
The ID of the Payment Intent.

amount

optionalnumber
Payment amount. This is the order amount you would like to charge your customer.

client_secret

optionalstring
The client_secret of the Payment Intent when Payment Intent is provided. Otherwise, this should be the client_secret of the Customer object.

created_at

optionalstring
The time this Payment Intent was created, in ISO 8601 format.

currency

optionalstring
The three-letter ISO currency code representing the currency of the Payment Intent.

customer_id

optionalstring
The ID of the Customer who intends to pay for the Payment Intent.

customer_payment_consents

optionalobject

customer_payment_methods

optionalobject

merchant_order_id

optionalstring
The merchant's order ID for this payment.

payment_consent_id

optionalstring
The ID of the Payment Consent associated with this Payment Intent.

request_id

optionalstring
Unique request ID specified by the merchant.

status

optionalstring
The status of the Payment Intent (e.g. 'REQUIRES_PAYMENT_METHOD', 'SUCCEEDED').

updated_at

optionalstring
The time this Payment Intent was last updated, in ISO 8601 format.

confirmIntent(data)

1element.confirmIntent({
2 client_secret: 'replace-with-your-client-secret',
3});

createPaymentConsent(data)

Call this function to create a Payment Consent, which represents the agreement between the merchant and shopper of making subsequent payments using the provided payment method.

Parameters

data

requiredParameterObject

client_secret

requiredstring
The client_secret of the Payment Intent when Payment Intent is provided. Otherwise, this should be the client_secret of the Customer object.

Returns

Promise<Consent | undefined>

Consent

requiredobject

client_secret

requiredstring
The client_secret returned when creating a Payment Consent.

created_at

requiredstring
The time this Payment Consent was created.

customer_id

requiredstring
The ID of the Customer who intends to pay for the Payment Intent.

id

requiredstring
The ID of the Payment Consent to be confirmed.

next_triggered_by

required'merchant' | 'customer'
Whether the merchant or customer should trigger subsequent payments.

status

required'PENDING_VERIFICATION' | 'VERIFIED' | 'DISABLED'
The status of the Payment Consent.

updated_at

requiredstring
The time this Payment Consent was last updated.

initial_payment_intent_id

optionalstring
The ID of the initial Payment Intent.

merchant_trigger_reason

optional'scheduled' | 'unscheduled'
Whether subsequent payments are 'scheduled' or 'unscheduled'. Only applicable when next_triggered_by is 'merchant'.
Default: 'unscheduled'

createPaymentConsent(data)

1element.createPaymentConsent({
2 client_secret: 'replace-with-your-client-secret',
3});

destroy()

Destroys the Element instance.

destroy()

1element.destroy();

mount(domElement)

Mounts Element to your HTML DOM.

Parameters

domElement

requiredstring | HTMLElement

Returns

HTMLElement | null

mount(domElement)

1// There are two ways to mount the element:
2// 1. Call with the container DOM id
3element.mount('container-dom-id');
4
5// 2. Find the created DOM in the existing HTML and call with the container DOM element
6const containerElement = document.getElementById('container-dom-id');
7element.mount(containerElement);

on('ready', handler)

This event will be fired when the Google Pay button element is mounted and ready to interact with the user.

Parameters

type

required'ready'
The event name.

handler

required() => void
The callback function that will be called when the event occurs.

on('ready', handler)

1element.on('ready', () => {
2 console.log('Google Pay button is ready');
3 });

on('success', handler)

This event will be fired when payment is successful. It can be used to redirect the user to the success page.

Parameters

type

required'success'
The event name.

handler

requiredfunction

The callback function that will be called when the event occurs.

The handler receives an object with the following properties:

detail

requiredobject

on('success', handler)

1element.on('success', (e) => {
2 const { intent, consent } = e.detail;
3 console.log('Payment is successful', { intent, consent });
4 });

on('error', handler)

This event will be fired when the element encounters an unexpected error.

Parameters

type

required'error'
The event name.

handler

requiredfunction

The callback function that will be called when the event occurs.

The handler receives an object with the following properties:

detail

requiredobject

on('error', handler)

1element.on('error', (e) => {
2 const { error } = e.detail;
3 console.error('There is an error', error);
4 });

on('cancel', handler)

This event will be fired when payment is cancelled.

Parameters

type

required'cancel'
The event name.

handler

required() => void
The callback function that will be called when the event occurs.

on('cancel', handler)

1element.on('cancel', () => {
2 console.log('Payment cancelled');
3 });

on('shippingMethodChange', handler)

This event will be fired when the shipping method changes.

Parameters

type

required'shippingMethodChange'
The event name.

handler

requiredfunction

The callback function that will be called when the event occurs.

The handler receives an object with the following properties:

detail

requiredobject

on('shippingMethodChange', handler)

1element.on('shippingMethodChange', (e) => {
2 const { intermediatePaymentData } = e.detail;
3 console.log('Shipping method changed', intermediatePaymentData);
4 });

on('shippingAddressChange', handler)

This event will be fired when the shipping address changes.

Parameters

type

required'shippingAddressChange'
The event name.

handler

requiredfunction

The callback function that will be called when the event occurs.

The handler receives an object with the following properties:

detail

requiredobject

on('shippingAddressChange', handler)

1element.on('shippingAddressChange', (e) => {
2 const { intermediatePaymentData } = e.detail;
3 console.log('Shipping address changed', intermediatePaymentData);
4 });

on('click', handler)

This event will be fired when the user clicks the Google Pay button.

Parameters

type

required'click'
The event name.

handler

required() => void
The callback function that will be called when the event occurs.

on('click', handler)

1element.on('click', () => {
2 console.log('Google Pay button clicked');
3 });

on('authorized', handler)

This event will be fired when the user authorizes the payment.

Parameters

type

required'authorized'
The event name.

handler

requiredfunction

The callback function that will be called when the event occurs.

The handler receives an object with the following properties:

detail

requiredobject

on('authorized', handler)

1element.on('authorized', (e) => {
2 const { paymentData } = e.detail;
3 console.log('Payment authorized', paymentData);
4 });

unmount()

Unmounts the Element. Note that the Element instance will remain.

unmount()

1element.unmount();

update(options?, initOptions?)

Call this function to update Element options after creating the Element.

Parameters

options

optionalGooglePayButtonElementOptions

allowCreditCards

optionalboolean
Whether a credit card may be used for this transaction.
Default: true

allowedAuthMethods

optionalCardAuthMethod[]
Allowed authentication methods.
Default: ['PAN_ONLY', 'CRYPTOGRAM_3DS']

allowedCardNetworks

optional('MASTERCARD' | 'MAESTRO' | 'VISA' | 'AMEX' | 'DISCOVER' | 'JCB')[]
One or more card networks that you support.

allowPrepaidCards

optionalboolean
Whether a prepaid card may be used for this transaction.
Default: true

amount

optionalAmount

Indicate the amount and currency of the Payment Intent. If the mode is set to 'recurring' and intent_id omitted, amount should be {value: '0', currency: 'Replace with payment currency'}.

appearance

optionalGooglePayButtonAppearance
Customize the appearance of the Google Pay button.

assuranceDetailsRequired

optionalboolean
Set to true if you need information about the validation performed on the returned payment data.
Default: false

authFormContainer

optionalstring
The container id of the authentication form used in 3D Secure authentication.

authorizationType

optional'pre_auth' | 'final_auth'

The authorization type for the card payment. Options include: "pre_auth", "final_auth". Set it to "pre_auth" if you want to place a hold on your customer's card for more than 7 days, i.e., extend the authorization time window. Currently it's only available when the card brand is Visa or Mastercard. autoCapture will be automatically set to false if you enable pre_auth.

Default: 'final_auth'

autoCapture

optionalboolean

Whether the amount should be captured automatically upon successful payment authorization. Set it to false if you want to place a hold on the payment method and capture the funds sometime later.

Default: true

billingAddressParameters

optionalBillingAddressParameters
Optional billing address parameters for the returned billing address.

billingAddressRequired

optionalboolean
Whether a billing address is required from the shopper.
Default: false

buttonColor

optionalenum
Specifies the button color of the Google Pay button.
Default: 'default'

buttonSizeMode

optionalenum

Determines how the button's size should change relative to the button's parent element.

Default: 'static'

buttonType

optionalenum
Specifies the text to be displayed within the Google Pay button.

callbackIntents

optionalCallbackIntent[]

List of callbacks that the developer intents to handle. Upon selection by the shopper, these intents can be used to update the request with new data based on that selection (For exmaple, if a shipping option is selected, the developer could update the transactionInfo with new totalPrice and diplayItems).

checkoutOption

optionalCheckoutOption
The options for checkout.

client_secret

optionalstring

The client_secret of the Payment Intent when Payment Intent is provided. Otherwise, this should be the client_secret of the Customer object. Leave it empty if intent_id and customer_id are not provided.

countryCode

optionalstring
The two-letter ISO-3166 country code.

customer_id

optionalstring

The ID of the Customer used in registered user checkout. Refer to Airwallex Client API This field is required when mode is 'recurring'.

displayItems

optionalDisplayItem[]
Description of a cart item.

emailRequired

optionalboolean
Whether the shopper must provide their email.
Default: false

error

optionalPaymentDataError

Error displayed to the shopper for erroneous payment data. For example, you can update error when user selects the wrong shipping option. Note: This field is currently available for web only.

existingPaymentMethodRequired

optionalboolean
Whether the shopper must use an existing payment method.
Default: false

gatewayMerchantId

optionalstring
The merchant account ID in Airwallex. It is required for Google Pay Express Checkout Element.

intent_id

optionalstring

The ID of the Payment Intent you would like to checkout. Refer to Airwallex Client API

merchantInfo

optionalobject
Detailed information about the merchant.

mode

optional'payment' | 'recurring'
The checkout mode for the shopper.

offerInfo

optionalOfferInfo

Offers available for redemption that can be used with the current order.

payment_consent

optionalPaymentConsentOptions
Options for PaymentConsent.

paymentDataCallbacks

optionalPaymentDataCallbacks

Defines callback methods for handling changed payment data and payment authorized events.

shippingAddressParameters

optionalShippingAddressParameters
Optional shipping address parameters for the returned shipping address.

shippingAddressRequired

optionalboolean
Whether a shipping address is required from the shopper.
Default: false

shippingOptionParameters

optionalShippingOptionParameters

Parameters for shipping option that can be used in this request. Note: This field is currently for web only.

shippingOptionRequired

optionalboolean

Whether a shipping option is required from the shopper.

Note: This field is currently for web only.

Default: false

style

optionalCSSProperties & PopUpStyle
Box style and 3ds popUp style for the GooglePayButton Element.

totalPriceLabel

optionalstring

Total price label of this transaction. The string will be shown as the total price label on the cart modal dialog page. This field is optional, but required if developer wants to show cart information. Otherwise the cart modal dialog will not be rendered.

totalPriceStatus

optionalenum

The status of the total price. If it is a variable subscription, the status should be NOT_CURRENTLY_KNOWN.

Default: 'FINAL'

transactionId

optionalstring

Correlation ID to refer to this transaction.

This field is optional. It is generated by the merchant and used to reference this transaction later, such as for debugging issues when communicating with Google.

initOptions

optionalInitOptions

env

optional'demo' | 'prod'
The Airwallex integration environment your site would like to connect with.
Default: 'prod'

fonts

optionalFontOptions[]
Global option to customize font styles of Elements.

locale

optionalenum
The locale for your website. Defaults to the browser's locale; however, if the browser's locale is not supported, it will default to 'en'.

origin

optionalstringDeprecated
This field is no longer used.

update(options?, initOptions?)

1element.update({
2 autoCapture: true,
3}, {
4 locale: 'en',
5});
Was this page helpful?