webgoogle-paytest-environments

How to integrate Google Pay on web with DIRECT type (TEST Environment)


How to do Google Pay integration with DIRECT type? I can't get what to do in this case. Is it possible at all to integrate Google Pay Test Environment with this type? Is it possible to work with test keys for tokenization?

Google provides guide for integration where only PAYMENT_GATEWAY type is described. Please help with some tips.


Solution

  • First, you will need to create a Business Profile to act as a merchant. This will give you a Merchant ID that will later be used in the PaymentDataRequest object.

    You can sign up here (it's free and quick) https://pay.google.com/business/console/home/

    Next, you will need to generate a new key pair using OpenSSL, and add it to your Google Business profile. Please see this link for more details on how to that. https://developers.google.com/pay/api/web/guides/resources/payment-data-cryptography#key-rotation

    Set the type in your tokenizationSpecification to "DIRECT". You will also need to add the below two parameters. Note that the publicKey is the public key you generated earlier and added to your business profile.

    const tokenizationSpecification = {
      "type": "DIRECT",
      "parameters": {
        "protocolVersion": "ECv2",
        "publicKey": "BOdoXP1aiNp.....kh3JUhiSZKHYF2Y="
      }
    }
    

    For testing, make sure you are using the 'TEST' environment. See here

    function getGooglePaymentsClient() {
        if ( paymentsClient === null ) {
            paymentsClient = new google.payments.api.PaymentsClient({
                environment: 'TEST',
                paymentDataCallbacks: {
                    onPaymentAuthorized: onPaymentAuthorized
                }
            });
        }
        return paymentsClient;
    }