Get In Touch
Gurugram
Plot # 1SP, Sector 27, Golf Course Rd, A Block, DLF Phase 1, Sector 27, Gurugram, Haryana 122022, India

Bengaluru
#103, 2nd floor, Unitech Coral Hosa Road, Sarjapur, Bengaluru, Karnataka 560035, India
Work Inquiries
info@creativenexus.in
prabhu@creativenexus.in
rishabh@creativenexus.in
Phone
+91 9999212010
+91 9019321894
+91 98686 57429

How to Integrate Google Pay API in Your Website

Payment Gateway Integration, Google Pay API, Google Pay Integration, Google Pay for Website, Google Pay API

Table of Contents

Are you struggling to integrate Google Pay API into your online store? Well, worry not. Today, in this article, we’ll discuss how to add Google Pay as a payment method to your website. 

Google Pay is currently one of the most popular and widely used payment apps in India. This popularity comes from the long-standing trust in Google and the features that they provide. Google Pay API is easy to use, secure and fast, which makes it a popular choice amongst businesses. You can integrate Google Pay API or Payment Gateway into your website through custom code or plugins in WordPress. So let’s have a look at it.

Introduction to Google Pay

A Google Pay Business or Merchant account allows you to directly accept payment in your Google Pay account from the sales from your website and online store. It also allows you to manage and track your business activities with the inbuilt analytics tools.  Google Pay API is known for its one-click checkout. As Google Pay not only facilitates UPI payment but also pre-fills all the order details, such as address, contact and card information. This way, the customer will have a seamless checkout experience. By integrating Google Pay API with your website, you can also enhance your user experience.

Steps to Integrate Google Pay API in Your Website

Below is the complete process of how you can integrate Google Pay API on your website’s checkout page as a payment option.

1. Create a Google Merchant Account

Before you integrate the API, you’ll need to create a Google Pay for Business account. You can create this by visiting here. You’ll need to submit all the necessary documents in order to get verified and get your API key.

2. Set Up a Google Cloud Project

Now, go to the Google Cloud Console. Create a new project and enable the Google Pay API for your project. This will allow your website to communicate with Google Pay Business services.

3. Configure Google Pay API for Web

To begin the integration, follow these steps:

Include the Google Pay API library in your HTML or web framework:

<script async src=”https://pay.google.com/gp/p/js/pay.js”></script>
Create the Google Pay Button: Add a button to your checkout page with the ID Google Pay button.<div id=”google-pay-button”></div>

4. Add Google Pay API Code

Implement the JavaScript code to handle the Google Pay button click event and make the payment request:

javascript
Copy code
const paymentsClient = new google.payments.api.PaymentsClient({environment: ‘TEST’});const button = paymentsClient.create button({onClick: onGooglePaymentButtonClick})
document.getElementById(‘google-pay-button’).appendChild(button);
function onGooglePaymentButtonClick() {const paymentDataRequest = {

API version: 2,
apiVersionMinor: 0,
allowed payment methods: [{      type: ‘CARD’,parameters: {
 allowedAuthMethods: [‘PAN_ONLY’, ‘CRYPTOGRAM_3DS’],allowed card networks: [‘AMEX’, ‘VISA’, ‘MASTERCARD’]},tokenisation specification: {
type: ‘PAYMENT_GATEWAY’,parameters: {gateway: ‘example’,gatewayMerchantId: ‘your-merchant-id’}}
}],

merchantInfo: {merchant: ‘your-merchant-id’,
merchant name: ‘Example Merchant’ },
transaction info: {totalPriceStatus: ‘FINAL’,
totalPrice: ‘10.00’,
currency code: ‘USD’}};
paymentsClient.loadPaymentData(paymentDataRequest)
.then(function(payment data) {
 // handle payment success})

    .catch(function(err) {
 //Handle payment failure
 });
}

This script will help you create the Google Pay button on your checkout page, after which you can start accepting payments.

5. Test Your Integration

Testing is a critical step in the Google Pay API integration process. You can test in a sandbox environment using test payment methods provided by Google. Ensure all transactions are successful before going live.

How to Add Google Pay API to WordPress Website

For WordPress websites, integrating Google Pay is straightforward with the right plugins. Here’s how:

1. Install a Payment Gateway Plugin

You can easily integrate Google Pay using popular WordPress payment gateway plugins like:

  • WooCommerce Stripe Payment Gateway: A widely-used plugin that supports Google Pay.
  • WP Simple Pay: A lightweight plugin for adding Google Pay without a full eCommerce system.
  • Easy Digital Downloads: This plugin works well for selling digital products and supports Google Pay integration.
  • Stripe Payment Plugin for WooCommerce: If your site is built on WooCommerce, this plugin allows you to integrate Google Pay effortlessly.

2. Enable Google Pay in Plugin Settings

After installing your preferred payment gateway plugin, navigate to the payment settings and enable Google Pay. After that, you’ll be asked for the Google Pay API key, which will link your Google Pay Business account to the payment gateway. 

3. Test the Integration

Test your Google Pay functionality using a test or sandbox environment provided by the plugin or Google Pay’s sandbox.

Security Considerations

Google Pay transactions are highly secure, and tokenisation is used to keep card details safe. However, you must ensure that you have a valid SSL certificate installed on your website. You follow PCI-DSS (Payment Card Industry Data Security Standard) guidelines.

This was all the information about how to integrate your Google Pay payment button into your online store’s checkout page. Google Pay is a widely used and trusted payment platform, and you can leverage their credibility to enhance user experience and increase the trust of consumers in your business.

Leave a Reply

Your email address will not be published. Required fields are marked *

We use cookies to give you the best experience. Cookie Policy