Skip to main content
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. Only the client-side SDK differs.

Web

1. Load the Google Pay SDK

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. 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.

3. Check availability and render the 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.

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

See Complete Google Pay Order for the full request and response.
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).

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 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:
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.