Google Pay

Take a Google Pay payment

Usage

Code playground

index.html

Payments

Returned by Square.payments(appId, locationId).

Use this object to instantiate Payment methods. Learn more on the Payments page.

Methods

payments.js
JS
JavaScript

const payments = Square.payments(appId, locationId);

GooglePay

The Google Pay Payment Method.

Google Pay supports taking payments via credit cards. Utilizing the PaymentRequest object, you can handle Shipping Option selection, as well as collect Shipping and Billing addresses.

Methods

googlePay.js
JS
JavaScript

const paymentRequest = payments.paymentRequest({

  countryCode: 'US',

  currencyCode: 'USD',

  total: {

    amount: '5.79',

    label: 'Total'

  },

});



const googlePay = await payments.googlePay(paymentRequest);

await googlePay.attach('#googlePay');



const googlePayButtonTarget = document.getElementById('googlePay');

googlePayButtonTarget.onclick = async () => {

  const tokenResult = await googlePay.tokenize();



  // Pass `tokenResult.token` to your server, and then call the /v2/payments API

  // to complete the payment

}