Google Pay Request Objects

For complete sample code please refer here​

Available dictionary objects

iStatus

1
const iStatus = {
2
success: 100,
3
unsupported: -100,
4
error: -200
5
}
Copied!
Use: iStatus.success

GPEnvironment

1
const GPEnvironment = {
2
test: "TEST",
3
production: "PRODUCTION"
4
}
Copied!
Use: GPEnvironment.test

GPButtonColor

1
const GPButtonColor = {
2
default: "default",
3
black: "black",
4
white: "white"
5
}
Copied!
Use: GPButtonColor.white

GPButtonType

1
const GPButtonType = {
2
buy: "buy",
3
donate: "donate",
4
plain: "plain"
5
}
Copied!
Use: GPButtonType.buy

GPButtonSizeMode

1
const GPButtonSizeMode = {
2
static: "static",
3
fill: "fill"
4
}
Copied!
Use: GPButtonSizeMode.full

GPBillingAddressFormat

1
const GPBillingAddressFormat = {
2
min: "MIN",
3
full: "FULL"
4
}
Copied!
Use: GPBillingAddressFormat.min

Request objects

GooglePayRequest

The Main object that contains all the information necessary to communicate with Google Pay API.
Name
Type
Required
Description
merchantInfo
​MerchantInfo​
No
Describes the Merchant name and website. For more information please click the link
onGPButtonLoaded
String
No
Name of a callback function to be called when Google Pay button is loaded. Accepts an object of type GPButtonLoadedResult.
onGetTransactionInfo
String
Yes
Name of a callback function to be called that returns the final price and tax calculations. Please click here for the sample code
onBeforeProcessPayment
String
No
Name of a callback function to be called when consumer clicked the button but before Google Pay sheet is loaded . Usually used to make validations before the payment. Please click here for the sample code
onProcessPayment
String
Yes
Name of a callback function to be called when Google Payment is authorized for the completion of the transaction. This function accepts a parameter of PaymentResponse. Please click here for the sample code
onPaymentCanceled
String
No
Name of a callback function to be called when Google Pay sheet is closed/canceled without completing the transaction. Please click here for the sample code
environment
String
No
Google Pay Environment. Could be either β€œTESTβ€œ or β€œPRODUCTIONβ€œ. If omitted, defaults to β€œTESTβ€œ
billingParameters
​BillingParameters​
No
Sets Billing parameters, including transactionId. For more information please click the link
shippingParameters
​ShippingParameters​
No
Sets various Shipping Options. For more information please click the link
buttonOptions
​ButtonOptions​
No
Provides Google Pay button customization options. For more information please click the link
Payment Request example
1
initGP: function() {
2
return {
3
merchantInfo: this.merchantInfo,
4
buttonOptions: this.buttonOptions,
5
environment: this.getGPEnvironment(),
6
billingParameters: this.billingParams,
7
shippingParameters: {
8
emailRequired: this.shippingParams.emailRequired,
9
onGetShippingCosts: "gpRequest.shippingParams.onGetShippingCosts",
10
onGetShippingOptions: "gpRequest.shippingParams.onGetShippingOptions"
11
},
12
onGetTransactionInfo: "gpRequest.onGetTransactionInfo",
13
onBeforeProcessPayment: "gpRequest.onBeforeProcessPayment",
14
onProcessPayment: "gpRequest.onProcessPayment",
15
onPaymentCanceled: "gpRequest.onPaymentCanceled",
16
onGPButtonLoaded: "gpRequest.gpButtonLoaded"
17
};
18
}
Copied!
onGPButtonLoaded example
1
gpButtonLoaded: function(resp) {
2
if (!resp) return;
3
if (resp.status === iStatus.success) {
4
showHide("divGpay", true);
5
showHide("lbGPPayload", true);
6
} else if (resp.reason) {
7
alert(resp.reason);
8
}
9
}
Copied!
onGetTransactionInfo example
1
onGetTransactionInfo: function () {
2
let amt = this.getAmount();
3
return {
4
displayItems: [
5
{
6
label: "Subtotal",
7
type: "SUBTOTAL",
8
price: amt.toString(),
9
},
10
{
11
label: "Tax",
12
type: "TAX",
13
price: (0.1 * amt).toString(),
14
}
15
],
16
countryCode: 'US',
17
currencyCode: "USD",
18
totalPriceStatus: "FINAL",
19
totalPrice: (1.1 * amt).toString(),
20
totalPriceLabel: "Total"
21
}
22
}
Copied!
onBeforeProcessPayment callback example
1
onBeforeProcessPayment: function () {
2
return new Promise(function (resolve, reject) {
3
try {
4
//Do some validation here
5
resolve(iStatus.success);
6
} catch (err) {
7
reject(err);
8
}
9
});
10
}
Copied!
onProcessPayment callback example
1
onProcessPayment: function (paymentRequest) {
2
let self = this;
3
return new Promise(function (resolve, reject) {
4
setTimeout(function () {
5
try {
6
console.log("paymentRequest", JSON.stringify(paymentRequest));
7
paymentToken = paymentRequest.paymentData.paymentMethodData.tokenizationData.token;
8
console.log("paymentToken", paymentToken);
9
const amt = (chained([paymentRequest, "transactionInfo", "totalPrice"]) && paymentRequest.transactionInfo.totalPrice) || 0;
10
try {
11
if (amt <= 0)
12
throw "Payment is not authorized. Invalid amount. Amount must be greater than 0";
13
authorizeGPay({ token: paymentToken, amount: amt})
14
.then((resp) => {
15
gpRequest.handleResponse(resp);
16
resolve(resp);
17
})
18
.catch((rej) => {
19
console.error("Payment is not authorized", JSON.stringify(rej));
20
setTimeout(function () { alert("Payment is not authorized. Please check the logs") }, 500);
21
reject(rej);
22
});
23
} catch (err) {
24
const emsg = JSON.stringify(err);
25
console.error(emsg);
26
setTimeout(function () { alert(emsg) }, 500);
27
reject({error: err});
28
}
29
} catch (e) {
30
reject(e);
31
}
32
}, 100); //3000);
33
});
34
}
Copied!
onPaymentCanceled callback example
1
onPaymentCanceled: function(respCanceled) {
2
setTimeout(function () { alert("Payment was canceled") }, 500);
3
}
Copied!

MerchantInfo Object

Name
Type
Required
Description
merchantName
String
Yes
From Google documentation: Merchant name encoded as UTF-8. Merchant name is rendered in the payment sheet. In TEST environment, or if a merchant isn't recognized, a β€œPay Unverified Merchant” message is displayed in the payment sheet.
Merchant Info example
1
merchantInfo: {
2
merchantName: "Example Merchant"
3
}
Copied!

GPButtonLoadedResult Object

Name
Type
Description
status
​iStatus​
There are 3 possible cases:
    Google Pay Button loaded successfully: status = iStatus.success
    Google Pay not supported: status = iStatus.unsupported
    An error occurred while loading Google Pay Button: status = iStatus.error
reason
String
If Google Pay Button failed to load this field will be populated with the reason.

BillingParameters Object

Name
Type
Required
Description
transactionId
String
No
From Google documentation: A unique ID that identifies a transaction attempt. If not provided will be automatically generated by iFields API. Will be sent back on paymentRequest..transactionInfo response object.
allowedAuthMethods
String[]
No
If not provided will be defaulted to ["PAN_ONLY", "CRYPTOGRAM_3DS"] From Google documentation: Fields supported to authenticate a card transaction.
    PAN_ONLY: This authentication method is associated with payment cards stored on file with the user's Google Account. Returned payment data includes personal account number (PAN) with the expiration month and the expiration year.
    CRYPTOGRAM_3DS: This authentication method is associated with cards stored as Android device tokens. Returned payment data includes a 3-D Secure (3DS) cryptogram generated on the device.
allowedCardNetworks
String[]
No
If not provided will be defaulted to ["AMEX", "DISCOVER", "MASTERCARD", "VISA"] From Google documentation: One or more card networks that you support, also supported by the Google Pay API.
    AMEX
    DISCOVER
    INTERAC
    JCB
    MASTERCARD
    VISA
assuranceDetailsRequired
Boolean
No
From Google documentation: Set to true to request assuranceDetails. This object provides information about the validation performed on the returned payment data.
billingAddressRequired
Boolean
No
From Google documentation: Set to true if you require a billing address. A billing address should only be requested if it's required to process the transaction.
billingAddressFormat
No
Has an effect when billingAddressRequired is set to true From Google documentation: Billing address format required to complete the transaction.
    MIN: Name, country code, and postal code (default).
    FULL: Name, street address, locality, region, country code, and postal code.
phoneNumberRequired
Boolean
No
Has an effect when billingAddressRequired is set to true From Google documentation: Set to true if a phone number is required to process the transaction.
Billing Parameters example
1
billingParameters: {
2
transactionId: "b65c7435-b57a-407e-a6e0-b166518d5d97",
3
allowedAuthMethods: ["PAN_ONLY"],
4
allowedCardNetworks: ["VISA", "MASTERCARD"],
5
emailRequired: true
6
billingAddressRequired: true,
7
billingAddressFormat: GPBillingAddressFormat.min,
8
phoneNumberRequired: true
9
}
Copied!

ShippingParameters Object

Name
Type
Required
Description
onGetShippingOptions
String
No
When shipping is required you need to provide the name of your function that returns a list of shipping options. For an example - please see below
onGetShippingCosts
String
No
When shipping is required you need to provide the name of your function that returns a list of shipping costs. For an example - please see below
shippingAddressRequired
Boolean
No
From Google documentation: Set to true to request a full shipping address..
emailRequired
Boolean
No
From Google documentation: Set to true to request an email address.
phoneNumberRequired
Boolean
No
From Google documentation: Set to true if a phone number is required for the provided shipping address.
allowedCountryCodes
String[]
No
From Google documentation: ISO 3166-1 alpha-2 country code values of the countries where shipping is allowed. If this object isn't specified, will be defaulted to US only.
Shipping Parameters example
1
shippingParams: {
2
allowedCountryCodes: ['US'],
3
onGetShippingCosts: function (shippingData) {
4
logDebug({
5
label: "onGetShippingCosts",
6
data: shippingData
7
});
8
return {
9
"shipping-001": "0.00",
10
"shipping-002": "1.99",
11
"shipping-003": "10.00"
12
}
13
},
14
onGetShippingOptions: function (shippingData) {
15
logDebug({
16
label: "onGetShippingOptions",
17
data: shippingData
18
});
19
let selectedOptionid = "shipping-001";
20
if (shippingData && shippingData.shippingOptionData && shippingData.shippingOptionData.id !== "shipping_option_unselected") {
21
selectedOptionid = shippingData.shippingOptionData.id;
22
}
23
return {
24
defaultSelectedOptionId: selectedOptionid,
25
shippingOptions: [
26
{
27
"id": "shipping-001",
28
"label": "Free: Standard shipping",
29
"description": "Free Shipping delivered in 5 business days."
30
},
31
{
32
"id": "shipping-002",
33
"label": "$1.99: Standard shipping",
34
"description": "Standard shipping delivered in 3 business days."
35
},
36
{
37
"id": "shipping-003",
38
"label": "$10: Express shipping",
39
"description": "Express shipping delivered in 1 business day."
40
},
41
]
42
};
43
}
44
}
Copied!

ShippingData Object

Name
Type
Description
shippingAddress
​ShippingAddress​
An Address containing countryCode, postalCode, locality(city), administrativeArea(state).
shippingOptionData
​ShippingOptionData​
An object containing a selected option
ShippingData object example
1
{
2
"shippingAddress": {
3
"countryCode": "US",
4
"postalCode": "10601",
5
"locality": "White Plains",
6
"administrativeArea": "NY"
7
},
8
"shippingOptionData": {
9
"id": "shipping-001"
10
}
11
}
Copied!

ShippingAddress Object

Name
Type
Description
postalCode
String
From Google documentation: The postal or ZIP code.
countryCode
String
From Google documentation: ISO 3166-1 alpha-2 country code.
locality
String
From Google documentation: City, town, neighborhood, or suburb.
administrativeArea
String
From Google documentation: A country subdivision, such as a state or province.

ShippingOptionData Object

Name
Type
Description
id
String
id of selected shipping option

ButtonOptions Object

Name
Type
Required
Description
buttonColor
​GPButtonColor​
No
From Google documentation:
    default: A Google-selected default value. Currently black but it may change over time (default).
    black: A black button suitable for use on white or light backgrounds.
    white: A white button suitable for use on colorful backgrounds.
buttonType
​GPButtonType​
No
From Google documentation:
    buy: "Buy with Google Pay" button (default).
    donate: "Donate with Google Pay" button.
    plain: Google Pay button without additional text.
buttonSizeMode
​GPButtonSizeMode​
No
From Google documentation:
    static: Button has a static width and height (default).
    fill: Button size changes to fill the size of its container.
Button Options example
1
buttonOptions: {
2
buttonColor: GPButtonColor.white,
3
buttonType: GPButtonType.buy,
4
buttonSizeMode: GPButtonSizeMode.full
5
}
Copied!
Last modified 15d ago