Mark Ku's Blog

Background

For work, I needed to integrate Google Pay into e-commerce sites for the US and Germany.

I've previously shared about Apple Pay on Web + Cybersource

Prerequisites for Integration

  • The website must have an HTTPS environment.
  • A Google Developer account ($25 USD / one-time fee).
  • If not integrating directly with Google Pay, you'll need a payment gateway provider (this article uses Cybersource).
  • The page design must comply with the Google Pay UI guidelines.

Google Pay Payment Flow

When a user clicks the Google Pay button, they can select a credit card. > After selecting a card, the frontend receives a Google Pay Token in the onLoadPaymentData event. This token is then used to call your backend API, which in turn requests order creation from the payment gateway.

Google Pay Setup

First, go to the Google Pay Developer Platform, log in to your Google Developer account > Manage your integration through the console

Google Pay developer page showing payment flow on phone and laptop
Google Pay developer page showing payment flow on phone and laptop

After enabling Google Pay, fill out the 'Business profile'

Google Pay & Wallet Console business profile page showing identity and logo
Google Pay & Wallet Console business profile page showing identity and logo

Google Pay API > Get started

Google Pay API console page with integration overview and illustrations
Google Pay API console page with integration overview and illustrations

Enter the website domain you want to integrate with Google Pay, and select 'Gateway' as the integration type

Google Pay API web integration form with website URL field
Google Pay API web integration form with website URL field

Skip this step for now. After you've implemented the Google Pay page on your site, you'll need to submit screenshots for review according to the requirements. Once Google approves it, you can use the PRODUCTION environment.

Google Pay API integration page with buyflow screenshot upload options
Google Pay API integration page with buyflow screenshot upload options

After submission, modifications will be locked, and a "pending review" notice will be displayed

Google Pay integration pending review notification with stop icon
Google Pay integration pending review notification with stop icon

Now, Let's Move to the Frontend Website

Install the Google Pay Button package

npm i @google-pay/button-react --save

Write the code

  const googlePayProcessResult = (paymentData) => {
    return checkStock()  // 檢查庫存     
      .then((res) => {
        const paymentDataString = paymentData.paymentMethodData.tokenizationData.token;
        const paymentDataBase64 = btoa(paymentDataString);

        let param: IPaymentProcessRequest = { PaymentTokenObject: paymentDataBase64 };
        // call 自己的後端,並透過自己後端和金流商交易
        digitalProcessResult(param).then((res) => {
		  if(res.IsSuccess === true){
		    alert('交易成功')
		  } 		
		});
      });
  };

<GooglePayButton
environment="PRODUCTION" // 審核通過才能使用
buttonType="short"
paymentRequest={{
  apiVersion: 2,
  apiVersionMinor: 0,
  allowedPaymentMethods: [
    {
      type: 'CARD',
      parameters: {
        allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
        allowedCardNetworks: ['MASTERCARD', 'VISA'],
      },
      tokenizationSpecification: {
        type: 'PAYMENT_GATEWAY',
        parameters: {
          gateway: 'cybersource', 
          gatewayMerchantId: 'letgo_account', // cybersource 後台商戶號 ( 非 android 商戶號 )
        },
      },
    },
  ],
  merchantInfo: {
    merchantId: 'ABB121232', // google pay developer merchantId
    merchantName: 'LetGo',
  },
  transactionInfo: {
    totalPriceStatus: 'FINAL',
    totalPriceLabel: 'Total',
    totalPrice: numberFormat(degitalPayPrice, 2),
    currencyCode: 'USD',
    countryCode: 'US',
  },
}}
onLoadPaymentData={googlePayProcessResult}
/>

The Google Pay Merchant ID (merchantInfo.merchantId) is very well hidden. Don't get it wrong; I wasted a lot of time because I entered it incorrectly.

Google Pay console highlighting the hidden Merchant ID field
Google Pay console highlighting the hidden Merchant ID field

Payment Gateway Merchant ID (gatewayMerchantId)

Cybersource UI showing Merchant ID input field outlined in red
Cybersource UI showing Merchant ID input field outlined in red

Once the entire page implementation is complete and approved, you can start accepting payments. (It's quite efficient; you should receive an email within one to two days).

Google Pay email requesting clarification on website product discrepancy
Google Pay email requesting clarification on website product discrepancy

Finally, implement the backend transaction API. Pass the Google Pay Token from the frontend to the Cybersource REST API to process the transaction.

References

Fast checkout on the web with Google Pay Integrating Google Pay on the Web Radial Payments & Fraud Documentation - Google Pay Web Integration How to Integrate GooglePay in React

Author

Mark Ku

擁有 10+ 年經驗的資深軟體工程師,現為 AI 應用 Builder,專注於大型平台架構與簡化複雜系統設計,從電商系統到訂閱與收費平台,結合 AI Agent、AI 整合與自動化開發,打造高效率且可持續演進的產品技術基礎。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

Popular Posts

View all
Mark Ku
··602

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··490

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··333

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··264

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning
Mark Ku
··221

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··215

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Readers also read