Google Pay

You can initiate commercial payments on behalf of your merchants using Google Pay on your frontend. Currently, this flow is for web-based platforms only. If you plan to build a mobile app, please mention it to your account manager.

Google Pay commercial payments are settled after 3 days of payment initiation.

Flow:

Integration can be split into two parts – wallet validation together with payment sheet creation and payment initiation.

  1. When your end-user selects to pay by Google Pay, you will need to load the Google Pay API JS Library in your frontend. Sample below:
<script
  async
  src="https://pay.google.com/gp/p/js/pay.js"
  onload="console.log('TODO: add onload function')">
</script>
  1. After the Google Pay API JavaScript library loads, initialize a PaymentsClient object. In merchantInfo add your merchant name registered in Google and merchant ID received (in a non-prod environment it’s any string between 12 and 18 symbols) after production access is approved. In a non-prod environment dummy payment methods are returned that are suitable to reference the structure of a payment response. In this environment, a selected payment method isn’t capable of a transaction. Please see the sample below:
const paymentsClient =
    new google.payments.api.PaymentsClient({{
  environment: "TEST",
  merchantInfo: {
    merchantName: "Example Merchant",
    merchantId: "12345678901234567890"
  },});

Tip! Google recommends only initializing paymentsClient once. Use the same instance when you invoke all of the other APIs, like CreateButton, IsReadyToPay, PrefetchPaymentData, and LoadPaymentData.

  1. Then, you’ll need to call isReadyToPay() to determine if the Google Pay API is supported by the current device and browser for your specified payment methods. Add the payment methods you allow to your base request object. In tokenizationSpecification add:
"tokenizationSpecification": {
"type": "PAYMENT_GATEWAY",
"parameters": {
"gateway": "checkoutltd",
"gatewayMerchantId": "pk_gvvpjipxznauq67fhtegsnao7q#"
}

  At ConnectPay, we support both VISA and MASTERCARD. See the following code sample:

const baseRequest = {
    apiVersion: 2,
    apiVersionMinor: 0,
  };
const allowedCardNetworks = ['MASTERCARD', 'VISA'];
const allowedCardAuthMethods = ['PAN_ONLY','CRYPTOGRAM_3DS'];
const baseCardPaymentMethod = {
    type: 'CARD',
    parameters: {
      allowedAuthMethods: allowedCardAuthMethods,
      allowedCardNetworks: allowedCardNetworks,
      assuranceDetailsRequired: true,
    },
    tokenizationSpecification: {
    type: PAYMENT_GATEWAY,
    parameters: {
      gateway: example,
      gatewayMerchantId: exampleGatewayMerchantId
    }
    }
  };

const isReadyToPayRequest = Object.assign({}, baseRequest);isReadyToPayRequest.allowedPaymentMethods = [baseCardPaymentMethod];

paymentsClient.isReadyToPay(isReadyToPayRequest)
    .then(function(response) {
      if (response.result) {
        // add a Google Pay payment button
      }
    })
    .catch(function(err) {
      // show error in developer console for debugging
      console.error(err);
    });
  1. Then PaymentDataRequest should be created. To create a PaymentDataRequest object, complete the following steps:
const paymentDataRequest = Object.assign({}, baseRequest);
  • Add the payment methods supported by your app, such as any configuration of additional data that’s expected in the response. See the following code sample:
paymentDataRequest.allowedPaymentMethods = [cardPaymentMethod];
  • Define a total price and currency for a shopper to authorize. You must include the countryCodetotalPrice, and merchantName parameters to meet SCA requirements. See the following code sample:
paymentDataRequest.transactionInfo = {
  totalPriceStatus: 'FINAL',
  totalPrice: '123.45',
  currencyCode: 'EUR',
  countryCode: 'LT'
};
  • Provide a user-visible merchant name, and use Google TEST merchantId value when in TEST environment. See the following code sample of a user-visible merchant name:
paymentDataRequest.merchantInfo = {
  merchantName: 'Example Merchant'
  merchantId: '12345678901234567890'
};
  1. Then payment sheet initialization should start. To register an event handler for user gestures, complete the following steps:
  • Register a click event handler for the purchase button. The event handler calls loadPaymentData() immediately after it interacts with the Google Pay, payment button.
  • After a Google user grants permission for your site to receive information about the user’s selected form of payment and optional contact data, handle the response from the Google Pay API.

Note! In a TEST environment, a payment response includes summary data about the selected payment method that’s suitable for display on a confirmation page. The payment response doesn’t include a payment method that’s capable of a transaction.

paymentsClient.loadPaymentData(paymentDataRequest).then(function(paymentData){
  // if using gateway tokenization, pass this token without modification
  paymentToken = paymentData.paymentMethodData.tokenizationData.token;
}).catch(function(err){
  // show error in developer console for debugging
  console.error(err);
});

  1. After status is successful, you will need to show your end-user result page specifically mentioning that this payment was initiated by Google Pay method.

Splitting one payment for multiple
sub-merchants

Access token and brand information

Single payments

Payment details

Notifications

Scroll to Top