Google Pay Integration

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Integration of Google Pay on Website

Google Pay on a website is implemented via Google Pay API (web) — a JavaScript library that forms a payment token processed by the payment gateway. Supported in Chrome on Android and desktop, in Chromium-based browsers. Unlike Apple Pay, does not require domain verification.

How the Flow Works

  1. Site calls Google Pay API → browser shows native popup with card selection from Google Wallet
  2. User confirms payment (biometry / PIN)
  3. Google Pay returns encrypted paymentData
  4. Site sends paymentData to its server
  5. Server passes token to payment gateway for debit

Connecting Google Pay API

<script async src="https://pay.google.com/gp/p/js/pay.js"
        onload="onGooglePayLoaded()"></script>

Basic Implementation

const baseRequest = {
  apiVersion: 2,
  apiVersionMinor: 0,
};

const allowedCardNetworks = ['MASTERCARD', 'VISA', 'MIR'];
const allowedCardAuthMethods = ['PAN_ONLY', 'CRYPTOGRAM_3DS'];

const baseCardPaymentMethod = {
  type: 'CARD',
  parameters: {
    allowedAuthMethods: allowedCardAuthMethods,
    allowedCardNetworks,
  },
};

// Tokenization via Stripe
const tokenizationSpecification = {
  type: 'PAYMENT_GATEWAY',
  parameters: {
    gateway:          'stripe',
    'stripe:version': '2023-10-16',
    'stripe:publishableKey': STRIPE_PUBLIC_KEY,
  },
};

const cardPaymentMethod = {
  ...baseCardPaymentMethod,
  tokenizationSpecification,
};

let paymentsClient;

function getGooglePaymentsClient() {
  if (!paymentsClient) {
    paymentsClient = new google.payments.api.PaymentsClient({
      environment: 'PRODUCTION', // or 'TEST'
    });
  }
  return paymentsClient;
}

async function onGooglePayLoaded() {
  const client = getGooglePaymentsClient();
  const { result } = await client.isReadyToPay({
    ...baseRequest,
    allowedPaymentMethods: [baseCardPaymentMethod],
  });

  if (result) {
    renderGooglePayButton();
  }
}

function renderGooglePayButton() {
  const button = getGooglePaymentsClient().createButton({
    onClick: onGooglePayButtonClicked,
    buttonType: 'buy',
    buttonColor: 'black',
    buttonSizeMode: 'fill',
  });
  document.getElementById('gpay-container').appendChild(button);
}

async function onGooglePayButtonClicked() {
  const paymentDataRequest = {
    ...baseRequest,
    allowedPaymentMethods: [cardPaymentMethod],
    transactionInfo: {
      totalPriceStatus: 'FINAL',
      totalPrice:        '14.99',
      currencyCode:      'USD',
      countryCode:       'US',
    },
    merchantInfo: {
      merchantId:   'BCR2DN4TXXXXXXXX', // from Google Pay Business Console
      merchantName: 'My Store',
    },
  };

  try {
    const paymentData = await getGooglePaymentsClient().loadPaymentData(paymentDataRequest);
    await processPayment(paymentData);
  } catch (err) {
    if (err.statusCode !== 'CANCELED') {
      console.error('Google Pay error', err);
    }
  }
}

async function processPayment(paymentData) {
  const token = paymentData.paymentMethodData.tokenizationData.token;

  const response = await fetch('/api/payment/google-pay', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ token, orderId: currentOrderId }),
  });

  const result = await response.json();
  if (result.success) {
    window.location.href = '/payment/success';
  }
}

Server-side Token Processing via Stripe

public function processGooglePay(Request $request): JsonResponse
{
    $token   = $request->input('token');
    $orderId = $request->input('orderId');
    $order   = Order::findOrFail($orderId);

    \Stripe\Stripe::setApiKey(config('services.stripe.secret'));

    try {
        $paymentIntent = \Stripe\PaymentIntent::create([
            'amount'               => (int)($order->total * 100),
            'currency'             => 'usd',
            'payment_method_data'  => [
                'type'  => 'card',
                'card'  => ['token' => json_decode($token)->id],
            ],
            'confirm'              => true,
            'return_url'           => 'https://example.com/payment/complete',
            'metadata'             => ['order_id' => $orderId],
        ]);

        if ($paymentIntent->status === 'succeeded') {
            $order->update(['status' => 'paid', 'transaction_id' => $paymentIntent->id]);
            return response()->json(['success' => true]);
        }
    } catch (\Stripe\Exception\CardException $e) {
        return response()->json(['success' => false, 'error' => $e->getMessage()]);
    }

    return response()->json(['success' => false]);
}

React Component with Google Pay

import { useEffect, useRef } from 'react';

declare const google: any;

export function GooglePayButton({ amount, currency, onSuccess }: {
  amount: string;
  currency: string;
  onSuccess: () => void;
}) {
  const containerRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const script = document.createElement('script');
    script.src = 'https://pay.google.com/gp/p/js/pay.js';
    script.async = true;
    script.onload = initGooglePay;
    document.head.appendChild(script);

    return () => { document.head.removeChild(script); };
  }, []);

  function initGooglePay() {
    const client = new google.payments.api.PaymentsClient({ environment: 'PRODUCTION' });
    const btn = client.createButton({ onClick: () => handlePayment(client, amount, currency, onSuccess) });
    containerRef.current?.appendChild(btn);
  }

  return <div ref={containerRef} />;
}

Registration in Google Pay Business Console

For production use:

  1. Register site in Google Pay Business Console
  2. Pass integration checklist
  3. Obtain merchantId (format BCR2DN4T...)

In test mode (environment: 'TEST'), merchantId is not required, no real charges occur. Test cards are added to Google Pay Sandbox. Google review pass: 1–3 business days.