Initialize the EdgePay JS client and Google Pay client:

EdgePay.init({ authKey: 'Your Auth Key' }); //You should get this key from your backend
var googlePayOnLoad = async function () {
    paymentsClient = new google.payments.api.PaymentsClient({ environment: 'TEST' });
}

Check and add the Google Pay button if the browser supports Google Pay:

isReadyToPayRequestResponse = await EdgePay.googlePay.getIsReadyToPayRequest();

var isReadyToPayRequest;
            
if (isReadyToPayRequestResponse.success) {
                
  isReadyToPayRequest = isReadyToPayRequestResponse.isReadyToPayRequest; 
                
  paymentsClient.isReadyToPay(isReadyToPayRequest)                    
    .then(function (response) {                        
        if (response.result) {
         // Add the Google Pay payment button
         // Define the "processGooglePayPayment()" function to be triggered when
         // a customer clicks on the Google Pay button
         const button = paymentsClient.createButton({ onClick: () => processGooglePayPayment() });
         document.getElementById('container').appendChild(button);
       }
     })
     .catch(function (err) {
         console.error(err);
     });
}
else {
  console.log("IsReadyToPayRequest error: ", isReadyToPayRequestResponse.errorResponse);
}

📘

IsReadyToPayRequest Object:

The IsReadyToPayRequest object is generated automatically by the EdgePay SDK so you don't have to set its values manually.

These are the values generated:

  • allowedAuthMethods: Both methods by default (PAN_ONLY and CRYPTOGRAM_3DS)
  • allowedCardNetworks: All networks enabled in the Merchant portal for your merchant
  • gateway: Our gateway name "globalelectronictechnology"
  • gatewayMerchantId: Your merchant ID
{ "type": "CARD",     
   "parameters": {        
     "allowedAuthMethods": ["PAN_ONLY", "CRYPTOGRAM_3DS"],        
     "allowedCardNetworks": ["AMEX", "DISCOVER", "JCB", "MASTERCARD", "VISA"]      
   }
}