> ## Documentation Index
> Fetch the complete documentation index at: https://firmly.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate Google Pay

> Integrate Google Pay with Google's SDK and route the order through Firmly

Integrate Google Pay using Google's Pay SDK. You read a ready-to-use configuration from the Firmly cart, mint a token with the SDK, and post that token to Firmly's complete-order endpoint, which places the order with the merchant.

The server contract is the same on web and Android: read the config, prepare the cart, and call [Complete Google Pay Order](https://firmly.mintlify.site/api-reference/payment/express-checkout/complete-order-google-pay.md). Only the client-side SDK differs.

## Web

### 1. Load the Google Pay SDK

```html theme={null}
<script src="https://pay.google.com/gp/p/js/pay.js" async></script>
```

### 2. Read the configuration from the cart

Firmly returns a ready-to-use configuration on the cart. Find the entry in `payment_method_options` whose `type` is `"GooglePay"`; its `config` **is** a Google [`PaymentDataRequest`](https://developers.google.com/pay/api/web/reference/request-objects#PaymentDataRequest). If there is no such entry, the merchant does not accept Google Pay. An entry can also be present without `config`: the merchant has Google Pay enabled but its tokenization settings are incomplete, so there is no request to hand to the SDK. Treat both cases the same way and do not show the button.

```javascript theme={null}
const entry = cart.payment_method_options.find((o) => o.type === "GooglePay");
const config = entry?.config;
if (!config) return; // no entry, or an entry without config: do not show the button
```

### 3. Check availability and render the button

```javascript theme={null}
const client = new google.payments.api.PaymentsClient({
  environment: "PRODUCTION", // or "TEST" — see Environment below
});

const { result } = await client.isReadyToPay(config);
if (result) {
  const button = client.createButton({ onClick: onGooglePayClicked });
  document.getElementById("google-pay-container").appendChild(button);
}
```

### 4. Mint the token

The token and card network only exist inside the click handler, so the handler passes them on to `completeOrder` (step 6) instead of leaving them for later code to pick up.

```javascript theme={null}
async function onGooglePayClicked() {
  const paymentData = await client.loadPaymentData(config);
  const token = paymentData.paymentMethodData.tokenizationData.token;
  const cardNetwork = paymentData.paymentMethodData.info?.cardNetwork;

  // Step 5: if the sheet collected the address, persist it and select a shipping method here
  // Step 6: place the order with the values minted above
  const order = await completeOrder(token, cardNetwork);
  if (order.urls?.thank_you_page) window.location.href = order.urls.thank_you_page;
}
```

### 5. Prepare the cart

Google Pay completes an already-prepared cart. For a physical-goods order the cart must carry a shipping address and a selected shipping method before completion. If the Google Pay sheet collected the address, persist it with `cart/shipping-info` and select a method with `cart/shipping-method` first, inside the click handler and before calling `completeOrder`.

### 6. Complete the order

```javascript theme={null}
async function completeOrder(token, cardNetwork) {
  const response = await fetch(
    "https://api.firmly.work/api/v1/domains/merchant.example.com/express/google-pay/complete-order",
    {
      method: "POST",
      headers: { "x-firmly-authorization": authToken, "Content-Type": "application/json" },
      body: JSON.stringify({
        attributes: { google_pay_token: token, google_pay_card_network: cardNetwork },
      }),
    }
  );
  const order = await response.json();
  if (!response.ok) throw new Error(order.description || "Google Pay order failed");
  return order;
}
```

See [Complete Google Pay Order](https://firmly.mintlify.site/api-reference/payment/express-checkout/complete-order-google-pay.md) for the full request and response.

> [!NOTE]
>
> Merchants whose `config` names Braintree as the gateway (`allowedPaymentMethods[0].tokenizationSpecification.parameters.gateway` is `"braintree"`) complete the order with a Braintree payment nonce instead of the Google Pay token. See [Braintree merchants (nonce flow)](https://firmly.mintlify.site/api-reference/payment/express-checkout/complete-order-google-pay.md#braintree-merchants-nonce-flow).

### Environment

The sheet environment (`TEST` or `PRODUCTION`) comes from the cart response, at `shop_properties.google_pay.environment`. Read it from there rather than hardcoding it — a test merchant must render the test sheet and a live merchant the live sheet.

## Android

The steps map one to one onto the web flow:

1. Use Google's [Android Google Pay API](https://developers.google.com/pay/api/android/overview) on the client (`PaymentsClient`, `isReadyToPay`, `loadPaymentData`).
2. Read the same `payment_method_options[].config` from the Firmly cart and pass it to the Android `PaymentsClient` — it is the same `PaymentDataRequest`.
3. On a successful payment, read the token from the Android `PaymentData` result.
4. Prepare the cart (`cart/shipping-info`, `cart/shipping-method`) exactly as on web.
5. POST the token to the same endpoint:

```
POST https://api.firmly.work/api/v1/domains/merchant.example.com/express/google-pay/complete-order
{ "attributes": { "google_pay_token": "<token from Android PaymentData>", "google_pay_card_network": "VISA" } }
```

Because the server contract does not change, a native Android client only differs in how it obtains the token from Google; everything on the Firmly side is the same as Web.

## Related

* [Complete Google Pay Order](https://firmly.mintlify.site/api-reference/payment/express-checkout/complete-order-google-pay.md) — the endpoint reference
* [Express Checkout](https://firmly.mintlify.site/api-reference/payment/express-checkout/overview.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.