Google Pay

Google Pay™ lets your customers pay with the press of a button — using payment methods saved to their Google Account.

Customer payment data is end-to-end encrypted from Google’s servers to your payment processor.

Google Pay works with your existing payments processing stack and can be implemented with a few lines of code.

Web integration using Google Pay API

Please review following documentations before continuing:

Load required libraries

1
<script src="https://pay.google.com/gp/p/js/pay.js"></script>

Set tokenizationSpecification and card networks as follows:

1
2
3
4
5
6
7
8
9
10
const tokenizationSpecification = {
  type: 'PAYMENT_GATEWAY',
  parameters: {
    'gateway': 'paylane',
    'gatewayMerchantId': 'YOUR_PUBLIC_API_KEY'
  }
};

const allowedCardNetworks = ['MASTERCARD', 'VISA'];
const allowedCardAuthMethods = ['PAN_ONLY', 'CRYPTOGRAM_3DS'];
You can see your PUBLIC_API_KEY in Merchant Panel under Admin Console > Integration.

Web integration using PayLane JS Client

Load required libraries

1
2
<script src="https://pay.google.com/gp/p/js/pay.js"></script>
<script src="https://js.paylane.com/v1"></script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// set up PayLane JS client
PayLane.setPublicApiKey('MY_PUBLIC_API_KEY');

// set up Google Pay with production Account
PayLane.googlePay.init({ environment: 'PRODUCTION',  googleMerchantId: 'ID FROM GOOGLE'});

// prepare basic transaction data
const TRANSACTION = {
  currencyCode: "USD",
  totalPrice: "1.00"
};

// check whether Google pay is available
PayLane.googlePay
  .isReadyToPay()
  .then(function(response) {
    if (response.result) {
      // proceed
      showGooglePayBtn();
    } else {
      console.warn("Google Pay is not available");
    }
  })
  .catch(function(err) {
    // handle errors here
    console.error(err);
  });

const showGooglePayBtn = function() {
  // create Google Pay button
  const button = PayLane.googlePay.createButton({
    onClick: onGooglePaymentButtonClicked
  });

  // append button
  document.getElementById('container').appendChild(button);
};

const onGooglePaymentButtonClicked = function() {
  PayLane.googlePay
    .loadPayment(TRANSACTION)
    .then(function(paymentData) {
      // extract and encode payment token
      const token = btoa(paymentData.paymentMethodData.tokenizationData.token);

      // pass required transaction data along with the `token` to your backend
      // application and perform transaction
    })
    .catch(function(err) {
      // handle errors here
      console.error(err);
    });
};

Perform transaction using PayLane Rest Client

Before you start calling any API methods regarding card operations, please make sure that you have properly initiated the PayLane Rest Client. It’s very easy, simply include a proper file and provide your user name and password.

1
2
include_once ('PayLaneRestClient.php');
$client = new PayLaneRestClient('your_login', 'your_password');
1
2
require 'paylane_client'
client = PayLane::Client.new('your_login', 'your_password')
1
2
from client import PayLaneRestClient
client = PayLaneRestClient("your_login", "your_password")

For further details on API integration (error codes, test card numbers etc.), please check the integration & testing section.

Prepare all the data required to perform the transaction as follows.
As you can see, in case of a Google Pay transaction there are three sets of information: sale, customer and card data.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$google_pay_params = [
    'sale'     => [
        'amount'      => 1.00,
        'currency'    => 'USD',
        'description' => 'Product #1'
    ],
    'customer' => [
        'name'         => 'John Doe',
        'email'        => 'john@doe.com',
        'country_code' => 'US',
        'ip'           => '127.0.0.1'
    ],
    'card' => [
        'token' => 'eyJzaWduYXR1cmUiOiJNRVlDSVFDcUE1T0Vpd1ptR29GNlVqUEI3MktBNWtOa2lyUE5WMGN0T1A4Uytwam1qd0loQUo1QjVXa3Vnd1JhNWk3enRUWjE4eHBEWjJXK0hNTjh3a0M2SFFCZ3ZyUWkiLCJwcm90b2NvbFZlcnNpb24iOiJFQ3YxIiwic2lnbmVkTWVzc2FnZSI6IntcImVuY3J5cHRlZE1lc3NhZ2VcIjpcIlJnSGV1UVA4OVFpa1FDZmtLemRia1g3dU4wUE8zSmFDcE5hRHRhQ1ZkQ0ErZFkvL0VyRzZvQ1NZZ3Yyc3dONkdaRmZwd09zL1ZiVTNjcVFLRC81YXRNQVV5STNidnZpOGRxcXlOb0J4aTVkUi9tbS9OZmRJdHpSdEE3YXovSndMTEpreGNOMzRLZHNQV3VhVHhRZ2MyWFBCUkN2TVpLeUQ1VWNuY1U4cktKSEhnSWlNZEMwUnhNU0Uxc1RVWEwxVDk0eURJck9jdlNlcmRYdnpLZGhUOUQxcUl0azA2VW5uc2dhRHFWdGg0SHMyY1hTUFVJYlNIc25ydlRsZGg2dGlkOTF2WWZRYldYeElqQUF1ZFRQME8xR25oTnJjYXo5WjBxeUVWUEVQQnVzc29kWU1pL1JQa3VNREh6TU1sUUV2Mms3SXBtdDZJZGVnd0t5L21VYlFNeld1NDdzc2Jmb2xWbW1vOGRrTlJhYmo5Z0dtQWwrL1ErelY1MUNPeG5CSWhBUHU2NUMwZ3RuTi8yZWJMNnZNdWQxbE5xRXV0WVd4alpGRWY4Q2ZkZ3lQM3M5WXdYWXdoenRTTi9ycGhCV1hpWmNOT29Ea2xxWWEvSVphT2o0TnVnNVdLU3hka2pVazhmSTJiNlV2ZEIwbHMrakpuenZRdStzUndlWHZoNmRRa2JuazhGS3VKeVdkZGl2c3NJcjlJZW1Jc3JFOUE5T3FlSnpWOVRjSThRb01ZWmNiQUZkcUlBRjhWTUJLSjMwU28yYyt4SnU5b21FUy9QbFVXU1hJdXltL1hXMldhd1xcdTAwM2RcXHUwMDNkXCIsXCJlcGhlbWVyYWxQdWJsaWNLZXlcIjpcIkJGZzZoNWZkQ0RIbWFNODlNN0VKOVdyWHVkZWh3bzFrci8rWmdNZDJiUE5NNmhHVVZRZVp2VHRZSm5ua1dGY2JVODZteXU0WmduM2VyL05pMUNwVFk1RVxcdTAwM2RcIixcInRhZ1wiOlwiY3NzcXNmcnJpSDRwSzlUQmJPRWpSMDc2Slc2YWNKL3JEQ3JHTUpaLzFaa1xcdTAwM2RcIn0ifQ==',
     ],
    'back_url'   => [
         'http://example-url.com'
     ],
];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
google_pay_params = {
    'sale' => {
        'amount'      => 1.00,
        'currency'    => 'USD',
        'description' => 'Product #1',
    },
    'customer' => {
        'name'         => 'John Doe',
        'email'        => 'john@doe.com',
        'country_code' => 'US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t4SnU5b21FUy9QbFVXU1hJdXltL1hXMldhd1xcdTAwM2RcXHUwMDNkXCIsXCJlcGhlbWVyYWxQdWJsaWNLZXlcIjpcIkJGZzZoNWZkQ0RIbWFNODlNN0VKOVdyWHVkZWh3bzFrci8rWmdNZDJiUE5NNmhHVVZRZVp2VHRZSm5ua1dGY2JVODZteXU0WmduM2VyL05pMUNwVFk1RVxcdTAwM2RcIixcInRhZ1wiOlwiY3NzcXNmcnJpSDRwSzlUQmJPRWpSMDc2Slc2YWNKL3JEQ3JHTUpaLzFaa1xcdTAwM2RcIn0ifQ=='
    }
    'back_url'   => {
         'http://example-url.com'
    },
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
google_pay_params = {
  'sale' : {
    'amount'      : 1.00,
    'currency'    : 'USD',
    'description' : 'Product #1'
  },
  'customer' : {
    'name'         : 'John Doe',
    'email'        : 'john@doe.com',
    'country_code' : 'US',
    'ip'           : '127.0.0.1'
  },
  'card' : {
    'token' : 'eyJzaWduYXR1cmUiOiJNRVlDSVFDcUE1T0Vpd1ptR29GNlVqUEI3MktBNWtOa2lyUE5WMGN0T1A4Uytwam1qd0loQUo1QjVXa3Vnd1JhNWk3enRUWjE4eHBEWjJXK0hNTjh3a0M2SFFCZ3ZyUWkiLCJwcm90b2NvbFZlcnNpb24iOiJFQ3YxIiwic2lnbmVkTWVzc2FnZSI6IntcImVuY3J5cHRlZE1lc3NhZ2VcIjpcIlJnSGV1UVA4OVFpa1FDZmtLemRia1g3dU4wUE8zSmFDcE5hRHRhQ1ZkQ0ErZFkvL0VyRzZvQ1NZZ3Yyc3dONkdaRmZwd09zL1ZiVTNjcVFLRC81YXRNQVV5STNidnZpOGRxcXlOb0J4aTVkUi9tbS9OZmRJdHpSdEE3YXovSndMTEpreGNOMzRLZHNQV3VhVHhRZ2MyWFBCUkN2TVpLeUQ1VWNuY1U4cktKSEhnSWlNZEMwUnhNU0Uxc1RVWEwxVDk0eURJck9jdlNlcmRYdnpLZGhUOUQxcUl0azA2VW5uc2dhRHFWdGg0SHMyY1hTUFVJYlNIc25ydlRsZGg2dGlkOTF2WWZRYldYeElqQUF1ZFRQME8xR25oTnJjYXo5WjBxeUVWUEVQQnVzc29kWU1pL1JQa3VNREh6TU1sUUV2Mms3SXBtdDZJZGVnd0t5L21VYlFNeld1NDdzc2Jmb2xWbW1vOGRrTlJhYmo5Z0dtQWwrL1ErelY1MUNPeG5CSWhBUHU2NUMwZ3RuTi8yZWJMNnZNdWQxbE5xRXV0WVd4alpGRWY4Q2ZkZ3lQM3M5WXdYWXdoenRTTi9ycGhCV1hpWmNOT29Ea2xxWWEvSVphT2o0TnVnNVdLU3hka2pVazhmSTJiNlV2ZEIwbHMrakpuenZRdStzUndlWHZoNmRRa2JuazhGS3VKeVdkZGl2c3NJcjlJZW1Jc3JFOUE5T3FlSnpWOVRjSThRb01ZWmNiQUZkcUlBRjhWTUJLSjMwU28yYyt4SnU5b21FUy9QbFVXU1hJdXltL1hXMldhd1xcdTAwM2RcXHUwMDNkXCIsXCJlcGhlbWVyYWxQdWJsaWNLZXlcIjpcIkJGZzZoNWZkQ0RIbWFNODlNN0VKOVdyWHVkZWh3bzFrci8rWmdNZDJiUE5NNmhHVVZRZVp2VHRZSm5ua1dGY2JVODZteXU0WmduM2VyL05pMUNwVFk1RVxcdTAwM2RcIixcInRhZ1wiOlwiY3NzcXNmcnJpSDRwSzlUQmJPRWpSMDc2Slc2YWNKL3JEQ3JHTUpaLzFaa1xcdTAwM2RcIn0ifQ=='
  }
"back_url"  :   'http://example-url.com'
}

Now simply perform the transaction using the googlePaySale or googlePayAuthorization method.


Retrieving the transaction ID number (or error details, if anything goes wrong) is also very simple and can be done as presented below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
try {
    $status = $client->googlePaySale($google_pay_params);
} catch (Exception $e) {
    // handle exceptions here
}

// checking transaction status example (optional):
if ($client->isSuccess()) {
    echo "Success, id_sale: {$status['id_sale']} \n";
} else {
    die("Error ID: {$status['error']['id_error']}, \n".
        "Error number: {$status['error']['error_number']}, \n".
        "Error description: {$status['error']['error_description']}");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
begin
    status = client.google_pay_sale(google_pay_params)
rescue PayLane::ClientError => e
    # handle exceptions here
end

# checking transaction status example (optional):
if client.success?
    puts "Success, id_sale: #{status["id_sale"]}"
else
    puts "Error ID: #{status["error"]["id_error"]}, \n"\
         "Error number: #{status["error"]["error_number"]}, \n"\
         "Error description: #{status["error"]["error_description"]}"
    exit
end
1
2
3
4
5
6
7
8
9
10
11
12
try:
    status = client.google_pay_sale(google_pay_params)
except Exception, e:
    # handle exceptions here

# checking transaction status example (optional):
if client.is_success():
    print 'Success, id_sale: %s' % status['id_sale']
else:
    sys.exit('Error ID: ' + str(status["error"]["id_error"]) + '\n' \
             'Error number: ' + str(status["error"]["error_number"]) + '\n' \
             'Error description: ' + str(status["error"]["error_description"]))

You can find all the structures’ descriptions in the REST Function Reference manual.