Google Pay Hosted Checkout
Overview
Google Pay Hosted Checkout is our simple integration that enables online Google Pay processing through the Cardknox gateway. This document details the steps necessary to integrate Google Pay Hosted Checkout with your site.
Contents
Server-Side Integration
Server Endpoint Creation
API Integration
Client-Side Integration
Adding Reference to iFields
Adding iFrame and JavaScript objects for the Google Pay button
Enabling Google Pay
Implementing Google Pay Hosted Checkout
Server-Side Integration
Server Endpoint Creation
A server endpoint is needed in order to accept the Google Payload from Hosted Checkout.
Step 1: Create an endpoint and method for API Integration on your server side that takes the Google Payload and makes a call to Cardknox.
API Integration
Below are the steps to integrate Google Pay with the Cardknox API:
Once the consumer confirms the payment, Google Pay API generates a token in the form of a JSON string.
Integration Steps:
Encode that token with Base64 encoding.
Set
xCardNum
field to the encoded token above.Set
xDigitalWalletType
toGooglePay
.Set the remaining required fields:
xAmount
totransactionInfo.totalPrice
- this is the consumer-approved amount from the Google Pay payment sheet.xCommand
- Set to one of the values that start withcc:
likecc:sale
,cc:auth
, etc.xBillFirstName
xBillLastName
xBillStreet
if availablexBillCity
if availablexBillState
if availablexBillZip
For more details, please contact your Cardknox Representative.
Client-Side Integration
Adding Reference to iFields
Find the latest version of iFields here.
Step 1: Add the iFields .js file after the <head> tag on your payment page:
Adding iFrame and JavaScript Objects for Google Pay button
Step 1: Add the following iFrame JS snippet inside the <body> where the Google Pay button is desired.
Make sure you have an attribute
data-ifields-id="igp"
as part of <iframe> tagMake sure you have an attribute
data-ifields-oninit="gpRequest.initGP"
as part of <iframe> tag where “gpRequest.initGP“ is a function name that initializes a Google Pay Object
Step 2: Create JavaScript object that holds all of the properties/methods required to process Google Pay.
Full a full sample code, refer to the iFields document.
Step 3: Implement desired callbacks.
For the list of available callbacks, please refer to Google Pay Object.
The two main functions below need to be implemented (the rest are optional):
onGetTransactionInfo: calculates the total amount based on the charge amount, fees, taxes, shipping costs, etc.
onProcessPayment - a callback that will be called after the consumer pays and Google returns a token with all other requested consumer information like billing address, shipping address, etc. This is where you need to make an ajax call to your server with the Google Payload. The sample for making an ajax call please see below.
Sample Code for making Ajax Call:
For full sample code, please refer to Google Pay Sample Code.
Step 4: Create JavaScript function that will initialize iFields.
Make sure that the iFrame attributedata-ifields-oninit
has the name of this function.
The initGP() function above returns Google Pay Object.
Enable Google Pay
window.ckGooglePay object - controls initialization of Google Pay button.
Method | Call Required | Description |
| Yes | Initializes and enables Google Pay Button. Takes EnableGooglePayParams object |
| Conditional | Updates amount on Google Sheet. |
You can provide either All, One or None of the parameters for enableGooglePay
call.
amountField
specified - in this case, the Google Pay total amount will be automatically updated whenever the amount has changed.amountField
is not specified - in this case, it’s up to you to provide the correct amount for Google Pay. One of the ways to do it is to callwindow.ckGooglePay.updateAmount
manually.iframeField
specified - this value will be used to communicate, with Google Pay button. This option is especially helpful for Angular clients using shadow DOM.iframeField
is not specified - its value will be calculated based ondata-ifields-id
attribute. In this case, it must be set to “igp“:data-ifields-id="igp"
.
EnableGooglePayParams Object
Name | Type | Required | Description |
| String|Object | No | Field containing |
| String|Object | No | Field containing iFrame with Google Pay button. Could be either the name of the field (String) or the field itself (Object) |
Enable Google Pay example
ckGooglePay.enableGooglePay({amountField: 'amount'});
Questions?
Check out the Google Pay FAQ page here.
For additional questions, contact support@cardknox.com
Last updated