Log inGet started
Airwallex logo
Home
Online Payments
Treasury
Transactional FX
Payouts
Issuing
Scale
Open Banking
Developer Tools
API Reference
Home
Online Payments
Overview
Starting with paymentsAirwallex platform overviewOnline payments modelPricing model
Integration options
Pay by LinkHosted Payment PageEmbedded Elements
Card ElementSplit Card ElementFull Featured Card ElementRedirect ElementQR Code ElementWeChat Pay ElementApple Pay ElementGoogle Pay Element
Drop-in ElementMobile SDKNative APIPlugins

Google Pay Element

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.

This page describes how to embed a Google Pay Element on your payment page to accept payments.

How it works

The diagram below depicts the information flow in a Google Pay Element integration. Google Pay sequence

Before you begin

Before you implement the integration, consider the following:

Step 1: Set up the server to create a PaymentIntent

When the shopper begins the checkout process, you will need to create a PaymentIntent object to indicate your intent to collect payment from the shopper.

When the checkout page loads, on your server, call Create a PaymentIntent API API with an amount and currency. Always decide how much to charge on the server side, a trusted environment, as opposed to the client. This prevents malicious shoppers from being able to alter the payment amount.

Provide return_url in Create a PaymentIntent API to indicate where Airwallex should redirect the shopper after completing the payment, whether successful or otherwise.

The PaymentIntent’s id and client_secret are returned in the response these parameters let you confirm the payment and update card details on the client, without allowing manipulation of sensitive information, like payment amount.

curl --request POST \
--url 'https://api-demo.airwallex.com/api/v1/pa/payment_intents/create' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your_bearer_token>' \
--data-raw '{
    "request_id": "00e8df19-7087-4209-b50b-067d6a39ee72",
    "amount": 100,
    "currency": "CNY",
    "merchant_order_id": "Merchant_Order_a7f9baf8-884a-4def-ba85-d1f9be83470a",   
    "return_url": "http://www.merchant.com/result"
}' 

Step 2: Initialize Airwallex on your checkout page

First, you will need to import the airwallex-payment-elements SDK and then initialize the package. For details, see Initialize Airwallex JS.

Step 3: Add the Google Pay Element to your checkout page

To embed the Google Pay Element JS into your checkout page, you will need to create an empty container, create the Element and then mount the Element to the container.

Define the payment form

First, create an empty container div with a unique id in your payment form. Ensure that the payment form only contains one Element with this unique id. Airwallex inserts an iframe into this div on mounting the Element.

<div id="googlePayButton"></div>

Create the Google Pay Element

When the payment form has loaded, call createElement(type, options) by specifying the Element type as googlePayButton to create the Element. Ensure that the payment form only contains one Element with googlePayButton id.

const googlePayElement = createElement("googlePayButton", {
  intent_id: 'replace-with-your-intent-id',
  origin: window.location.origin,
  client_secret: 'replace-with-your-client-secret',
  countryCode: 'HK',  // The merchant's two-letter ISO 3166       totalPriceLabel: 'COMPANY, INC.', // Provide a business name for the label field.
  buttonType: 'buy', // Indicate the type of button you want displayed on your payments form. Like 'buy'
  merchantInfo: {
 merchantName: "Example Merchant",
  },
  amount: {
value: intent.amount,
currency: intent.currency,
  },
});

Mount the Google Pay Element

Call mount() with the id of the div to mount the Element to the DOM. This creates the Google Pay button. The Element should only be mounted once in a single payment flow.

element.mount('googlePayButton'); // Injects iframe into the Google Pay Element container

Add onReady event listener to ensure the Element is mounted. Use this event to prepare and load the checkout page.

 const element = mount('root');
element.addEventListener('onReady', (event) => {
  // handle event
});

Google Pay props

You can also pass options in createElement() to overwrite styles and other functions as shown in the following table. For details, see googlePayButton props JS.

Step 4: Handle the response

Add onSuccess and onError event listeners to handle error and success events received from Airwallex.

const element = mount('root');
element.addEventListener('onSuccess', (event) => {
  // Handle event on success
});

element.addEventListener('onError’, (event) => {
  // Handle event on error
});

If no error occurred, display a message that the payment was successful. If payment fails with an error, display the appropriate message to your shopper so they can take action and try again.

Retrieve the payment result

For any actions subsequent to the payment such as shipping goods or sending email receipts, you can retrieve the payment result using the following options:

  • Set up webhooks to receive notifications on whether the payment has succeeded. Airwallex sends payment_intent.succeeded event when a payment succeeds. Listen to these events rather than waiting on a callback from the client. On the client, the shopper could close the browser window or quit the app before the callback executes. For information on how to set up webhooks and listen to events, see Getting started with webhooks

  • On your server, call Retrieve a PaymentIntent API to check the PaymentIntent status.

  • Check Payment Activity screen on your Airwallex web app.

Test your integration

Perform transaction tests in the production environment as described in the go-live checklist to ensure your integration is working correctly.

Additional features

You can add the following features to your Embedded Element integration.

Localization

You can configure the Element to display localized text of the payment fields based on the locale set in init() or loadAirwallex( ). Supported locales are:

  • en (US English)
  • zh (Simplified Chinese)
  • ja (Japanese)
  • ko (Korean)
  • ar (Arabic)
  • fr (French)

FAQ

What are the common error scenarios with Embedded Elements integration?

Some common scenarios include :

ErrorNext steps
Airwallex is not definedCheck if you have initialized Airwallex (Step 2) before using Airwallex functions. If you are using CDN, check if you have changed the bundle version from x.x.x to the latest version in the package.json file. For example, https://checkout.airwallex.com/assets/elements.bundle.min.js is invalid
Access denied, authentication failedCheck if you have replaced your intent id and client_secret in createElement() and optionally confirmPaymentIntent().
The PaymentIntent with ID int_xxxxxxxxx cannot be foundCheck if the environment you initialized Airwallex in, for example, demo or prod, matches the environment you retrieved your intent id and client_secret from. In other words, if you ran init in the demo environment, you must also create your PaymentIntent in the demo environment.
On this page