---
url: https://simplepay.webmania.cc/en/guide/google-pay.md
description: >-
  A Google Pay button on your own page with SimplePay: renderGooglePayButton in
  the browser, startGooglePay on the server, 3DS (3004) handling, Google Pay &
  Wallet Console setup.
---

# Google Pay

With merchant-hosted Google Pay the customer never leaves for SimplePay's payment page: the Google Pay button is on your page, and the payment goes through SimplePay's `dogooglepay` endpoint.

Two parts:

* **browser**: `renderGooglePayButton` from `simplepay-js-sdk/google-pay`
* **server**: `startGooglePay` from `simplepay-js-sdk`

Fulfil the order from the [IPN](./ipn) here too.

## Setup

1. Create a merchant profile in the [Google Pay & Wallet Console](https://pay.google.com/business/console) and get your checkout domain approved.
2. Send the Google merchant ID to SimplePay.
3. Use your **SimplePay** merchant ID as `gatewayMerchantId`.
4. In the sandbox use Google Pay's `TEST` environment.

Google Pay does not support the `HUF_SZEP` currency.

## Browser: the button

```ts
import { renderGooglePayButton } from 'simplepay-js-sdk/google-pay'

await renderGooglePayButton({
  container: '#google-pay',              // CSS selector or HTMLElement
  merchantId: 'GOOGLE_MERCHANT_ID',
  merchantName: 'Shop Ltd.',
  environment: 'TEST',                   // TEST | PRODUCTION
  gatewayMerchantId: 'SIMPLEPAY_MERCHANT_ID',
  authorizationEndpoint: '/api/google-pay',
  currency: 'HUF',
  total: '1212',                         // shown in the Google Pay sheet
  orderRef: 'order-12',
  countryCode: 'HU',                     // optional, default HU
  allowedCardNetworks: ['VISA', 'MASTERCARD'], // optional, default VISA, MASTERCARD, AMEX
  onResult: (result) => { /* successful response from your server */ },
  onError: (error) => { /* error */ },
})
```

What it does:

1. Loads `https://pay.google.com/gp/p/js/pay.js` (unless already loaded).
2. Asks Google Pay (`isReadyToPay`) whether the browser can pay. If not, it **renders no button** and returns without an error.
3. On click it opens the Google Pay sheet, then `POST`s `{ googlePayToken, orderRef }` to `authorizationEndpoint`. `googlePayToken` is already Base64.
4. `onResult` receives your server's response. If it contains error code `3004` and a `redirectUrl`, the button sends the customer to the 3DS page (`https` only).

Without `onError`, errors are thrown.

## Server: the charge

```ts
import { startGooglePay } from 'simplepay-js-sdk'

// POST /api/google-pay  body: { googlePayToken, orderRef }
const order = await loadOrder(orderRef)       // read the amount on the server!

const response = await startGooglePay({
  orderRef: order.orderRef,
  total: order.total,
  currency: 'HUF',
  customerEmail: order.email,
  language: 'EN',
  googlePayToken,                               // unchanged
  invoice: order.invoice,                       // optional
}, {
  redirectUrl: 'https://example.com/payment/back', // the customer returns here after 3DS
})

return response // return it to the browser
```

::: warning The server decides the amount
SimplePay charges the `total` your server passes to `startGooglePay`. The button's `total` is only what the Google Pay sheet shows. They should match, but always compute from the order on the server.
:::

### 3DS

When the card issuer asks for strong customer authentication, SimplePay returns error code `3004` with a `redirectUrl`. `startGooglePay` then **does not throw**; it returns the response and the button redirects. After 3DS the customer comes back to `redirectUrl` with `r` and `s`, which [`getPaymentResponse`](./back-url) verifies. Without 3DS the customer stays on the page.

### Errors

`startGooglePay` throws when:

* the token is missing: `Missing Google Pay token`
* the currency is `HUF_SZEP`: `Google Pay does not support HUF_SZEP`
* in production the return URL is not `https`
* the response signature is wrong or missing
* SimplePay returns any error code other than `3004` with `redirectUrl`, or `3004` without `redirectUrl`: `SimplePay API error: …`
