Google Pay

Accept Google Pay for fast, secure checkout on supported devices.
View as Markdown

Google Pay lets customers pay using cards saved to their Google account with a single tap.

Prerequisites

PaymentKit.js checks Google Pay availability automatically when it initializes — there’s no manual prepare step. You reveal your button once the SDK reports it’s ready (see Show the express button), and the customer’s tap submits the payment.

PaymentKit.js routes Google Pay through whichever processor your account has configured, and each processor relies on a different browser library. PaymentKit does not inject these scripts for you—add the one matching your processor (or both, if you’re unsure which one the backend will select).

Google Pay readiness only succeeds when the checkout session’s account has an express-checkout processor configured with Google Pay enabled. If none is configured, the SDK stays in the not-ready state and your onGooglePayReady callback reports false — so your button never appears.

Add Stripe.js to your page. Google Pay rides Stripe’s Payment Request API:

1<script src="https://js.stripe.com/v3/"></script>

The processor is selected by the backend, so if your account can route to either processor, include both scripts. Loading only Stripe.js will cause Google Pay to fail on Airwallex processors with Google Pay API not loaded.

Airwallex processors must also have Google Pay activated in your Airwallex dashboard. Enabling Google Pay in your PaymentKit dashboard alone is not enough — Google Pay must be enabled as a payment method on your Airwallex account before it can be tested or charged. If it isn’t activated on the Airwallex side, the Google Pay sheet will fail to complete even when your PaymentKit configuration and page scripts are correct.

Setup

1<script src="https://unpkg.com/@payment-kit-js/vanilla/dist/cdn/paymentkit.min.js"></script>
2<script>
3 const paymentKit = PaymentKit.default({
4 environment: 'production',
5 secureToken: 'your_secure_token',
6 paymentMethods: [PaymentKit.PaymentMethods.googlePay]
7 });
8</script>

Show the express button

The SDK checks Google Pay availability automatically when it initializes. Use onGooglePayReady to show or hide your express button, and notifyAmountChanged to re-prepare whenever the amount changes.

React to readiness

Register a callback with onGooglePayReady. It fires immediately with the current state, then again on every change. Register as many callbacks as you need — none are overwritten.

1paymentKit.google_pay.onGooglePayReady((isReady) => {
2 googlePayButton.hidden = !isReady;
3});

While the SDK is re-preparing (see below), it reports isReady: false, then true again once it’s ready — so the same callback naturally hides the button during the gap.

Re-prepare after the amount changes

Whenever the cart total changes — a coupon is applied, quantity is updated, shipping is added — call notifyAmountChanged() so the SDK clears the stale session and prepares a fresh one with the new amount. It returns a promise that resolves once Google Pay is ready again.

1await paymentKit.google_pay.notifyAmountChanged();

Your onGooglePayReady callback fires across the re-prepare (false while in flight, then true), so the button hides and reappears on its own. Calling it again while a prepare is already running coalesces the calls — the promise resolves once the latest prepare completes.

onGooglePayReady and notifyAmountChanged are methods on paymentKit.google_pay.

Submit payment

Attach submit to the same button you reveal with onGooglePayReady. In the auto-prepare flow the SDK fills the processor from the checkout session, and Google Pay collects the payer’s details from the sheet — so you don’t pass processorId.

1googlePayButton.addEventListener('click', () => {
2 paymentKit.submit({
3 fields: {},
4 paymentMethod: 'google_pay',
5 options: {
6 customerInfo: {
7 first_name: 'Jane',
8 last_name: 'Smith'
9 }
10 },
11 onSuccess: (result) => {
12 console.log('Transaction ID:', result.id);
13 console.log('Checkout Session:', result.checkoutSessionId);
14 window.location.href = '/success';
15 },
16 onError: (errors) => {
17 if (errors.google_pay === 'Google Pay not available on this device') {
18 // Hide button, show card form instead
19 }
20 }
21 });
22});

Options

OptionTypeDescription
processorIdstringYour processor ID with Google Pay enabled. Auto-filled from the checkout session; required only if you bypass auto-prepare.
customerInfo.first_namestringOptional — Google Pay collects the payer name from the sheet.
customerInfo.last_namestringOptional — Google Pay collects the payer name from the sheet.
mockScenarioGooglePayMockScenarioTesting only. Use "success" or "cancelled" to simulate Google Pay flows without a real device

Browser support

Google Pay works on:

  • Chrome 61+ on Android devices (with a card saved to Google Pay)
  • Chrome 61+ on desktop (with a card saved to Google Pay)
  • Microsoft Edge on desktop (with a card saved to Google Pay)

Depending on your processor, PaymentKit.js routes Google Pay through either Stripe’s Payment Request API (Stripe) or Google’s native Pay API (Airwallex). Both have specific browser requirements. Safari on iOS does not support Google Pay—use Apple Pay instead.

Google Pay isn’t available on all devices. Always provide card payments as a fallback.

Error handling

ErrorCause
Processor ID is requiredNo processor available — the session has no express-checkout processor configured (or none passed when bypassing auto-prepare)
Stripe.js not loaded. Add <script src="https://js.stripe.com/v3/"></script> to your page.Stripe.js script not loaded before initializing Google Pay (Stripe processors)
Google Pay API not loaded. Add <script src="https://pay.google.com/gp/p/js/pay.js"></script> to your page.Google’s pay.js script not loaded before initializing Google Pay (Airwallex processors)
Google Pay not available on this deviceDevice doesn’t support Google Pay or no cards saved
Google Pay cancelled by userCustomer closed the Google Pay sheet
Failed to start Google PayAPI call to start checkout failed
Card setup failedStripe card setup confirmation failed
Payment failedPayment confirmation returned a failure status
Google Pay error: {message}Unexpected error during the payment flow