Class: TranspayrentGooglePayHelper

TranspayrentGooglePayHelper(environment, config, transaction)

The Transpayrent Helper SDK for Google PayTM abstracts the Google Pay Javascript Client into 2 simple methods:

The Transpayrent SDK handles the secure communication with Transpayrent's Payment Gateway and transmits the Google encrypted payment data and transaction data provided by the Transpayrent Helper SDK for Google Pay.
Generally direct interaction with the helper SDK is unnecessary and the equivalent methods from the Transpayrent SDK called be instead.
Please refer to the following resources for additional details in regard to implementing Google Pay:

Configuration of Google Pay is done dynamically using data provided by the Transpayrent Payment Gateway to automatically handle the following scenarios:

  • Strong consumer authentication (SCA) using 3D Secure for PAN_ONLY authorizations if required
  • Passing the correct gateway and gatewayMerchantId to Google Pay
  • Dynamically enable supported card networks (MasterCard, VISA etc.) for Google Pay based on the configured country

Constructor

new TranspayrentGooglePayHelper(environment, config, transaction)

Creates a new instance of the Transpayrent SDK, which uses the Transpayrent Helper SDK for Google Pay internally to abstract the Google Pay Javascript Client.

Parameters:
Name Type Description
environment String

The Google Pay environment, either PRODUCTION or TEST, that will be used by the helper SDK

config GooglePayConfig

The base configuration for Google Pay.

transaction GooglePayTransaction

The details for the payment transaction that will be authorized using Google Pay

Version:
  • 1.0.0
License:
  • Common Transpayrent API license
Source:
See:
Example

Instantiate the Transpayrent SDK and display the "Buy with Google Pay" button

 <script src="https://storage.googleapis.com/static.[ENVIRONMENT].transpayrent.cloud/v1/swagger-client.js"></script>
 <script src="https://storage.googleapis.com/static.[ENVIRONMENT].transpayrent.cloud/v1/transpayrent.js"></script>
 <script async src="https://pay.google.com/gp/p/js/pay.js" onload="onGooglePayLoaded()"></script>
 <script>
     // SDK configuration
     var transpayrentConfig = {
         merchantId: [UNIQUE MERCHANT ID ASSIGNED BY TRANSPAYRENT],
         sessionId: [ID IN THE RESPONSE FROM "Create Payment Session"],
         accessToken: '[x-transpayrent-access-token HTTP HEADER IN THE RESPONSE FROM "Create Payment Session"]'
     };
     var url = 'https://generator.[ENVIRONMENT].transpayrent.cloud/v1/'+ transpayrentConfig.merchantId +'/system/PAYMENT_GATEWAY/sdk/CLIENT';

     // Instantiate SDK
     var sdk = new Transpayrent(url, transpayrentConfig);

     // List of payment methods supported by Google Pay as returned in the response from "Create Payment Session"
     const paymentMethodIds = [ 103,   // VISA Dankort
                                107,   // Maestro
                                108,   // MasterCard
                                109,   // VISA
                                110    // VISA Electron
                              ];
     // Display the Payment Sheet for Google Pay 
     var config = { buttonColor : 'black',
                    buttonType : 'buy',
                    onClick : () => {
                         const paymentMethodId = 203;                                       // Google Pay
                         var paymentSheetDetails = { merchant_id : transpayrentConfig.merchantId,
                                                     merchant_name : '[MY MERCHANT]',
                                                     country : 208,                         // Denmark
                                                     payment_method_ids : paymentMethodIds,
                                                     amount : { currency : 208,             // DKK
                                                                value : 1000 },
                                                     save : false };
                          sdk.displayPaymentSheet(paymentMethodId, paymentSheetDetails)
                             .then(token => completePayment(paymentMethodId) )
                             .catch(reason => {
                                 document.getElementById('container').style.visibility = 'hidden';
                                 alert('API: '+ reason.api +' failed with HTTP Status Code: '+ reason.status +' and error: '+ reason.messages[0].message +'('+ reason.messages[0].code +')');
                             });
                  } };
     // Display the "Buy with Google Pay" button
     sdk.displayPaymentButton(203, document.getElementById('google-pay-button-container'), paymentMethodIds, config);
 </script>

Methods

displayPaymentButton(container, paymentMethodIds, config, …args)

Initialize Google PaymentsClient after Google-hosted JavaScript has loaded and display the Google Pay payment button after confirmation of the viewer's ability to pay.
It is strongly recommended to use Transpayrent#displayPaymentButton.

Parameters:
Name Type Attributes Description
container *
paymentMethodIds Array.<PAYMENT_METHOD_ID>

List of Payment IDs returned by the Transpayrent Gateway upon initializing the payment transaction

config *
args any <repeatable>
Source:
See:

displayPaymentSheet(resolver, rejecter)

Show Google Pay payment sheet when Google Pay payment button is clicked.
It is strongly recommended to use Transpayrent#displayPaymentSheet.

Parameters:
Name Type Description
resolver function

The resolver function for a promise

rejecter function

The rejecter function for a promise

Source:
See: