Google Pay Request Objects

For complete sample code please refer here

Available dictionary objects

iStatus

const iStatus = {
    success: 100,
    unsupported: -100,
    error: -200
}

Use: iStatus.success

GPEnvironment

const GPEnvironment = {
    test: "TEST",
    production: "PRODUCTION"
}

Use: GPEnvironment.test

GPButtonColor

const GPButtonColor = {
    default: "default",
    black: "black",
    white: "white"
}

Use: GPButtonColor.white

GPButtonType

const GPButtonType = {
    buy: "buy",
    donate: "donate",
    plain: "plain"
}

Use: GPButtonType.buy

GPButtonSizeMode

const GPButtonSizeMode = {
    static: "static",
    fill: "fill"
}

Use: GPButtonSizeMode.fill

GPBillingAddressFormat

const GPBillingAddressFormat = {
    min: "MIN",
    full: "FULL"
}

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

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

No

Sets Billing parameters, including transactionId. For more information please click the link

shippingParameters

No

Sets various Shipping Options. For more information please click the link

buttonOptions

No

Provides Google Pay button customization options. For more information please click the link

Payment Request example

initGP: function() {
    return {
        merchantInfo: this.merchantInfo,
        buttonOptions: this.buttonOptions,
        environment: this.getGPEnvironment(),
        billingParameters: this.billingParams,
        shippingParameters: {
            emailRequired: this.shippingParams.emailRequired,
            onGetShippingCosts: "gpRequest.shippingParams.onGetShippingCosts",
            onGetShippingOptions: "gpRequest.shippingParams.onGetShippingOptions"
        },
        onGetTransactionInfo: "gpRequest.onGetTransactionInfo",
        onBeforeProcessPayment: "gpRequest.onBeforeProcessPayment",
        onProcessPayment: "gpRequest.onProcessPayment",
        onPaymentCanceled: "gpRequest.onPaymentCanceled",
        onGPButtonLoaded: "gpRequest.gpButtonLoaded"
    };
}

onGPButtonLoaded example

gpButtonLoaded: function(resp) {
    if (!resp) return;
    if (resp.status === iStatus.success) {
        showHide("divGpay", true);
        showHide("lbGPPayload", true);
    } else if (resp.reason) {
        alert(resp.reason);
    }
}

onGetTransactionInfo example

onGetTransactionInfo: function () {
    let amt = this.getAmount();
    return {
        displayItems: [
            {
                label: "Subtotal",
                type: "SUBTOTAL",
                price: amt.toString(),
            },
            {
                label: "Tax",
                type: "TAX",
                price: (0.1 * amt).toString(),
            }
        ],
        countryCode: 'US',
        currencyCode: "USD",
        totalPriceStatus: "FINAL",
        totalPrice: (1.1 * amt).toString(),
        totalPriceLabel: "Total"
    }
}

onBeforeProcessPayment callback example

onBeforeProcessPayment: function () {
    return new Promise(function (resolve, reject) {
        try {
            //Do some validation here
            resolve(iStatus.success);
        } catch (err) {
            reject(err);
        }
    });
}

onProcessPayment callback example

onProcessPayment: function (paymentRequest) {
    let self = this;
    return new Promise(function (resolve, reject) {
        setTimeout(function () {
            try {
                console.log("paymentRequest", JSON.stringify(paymentRequest));
                paymentToken = paymentRequest.paymentData.paymentMethodData.tokenizationData.token;
                console.log("paymentToken", paymentToken);
                const amt = (chained([paymentRequest, "transactionInfo", "totalPrice"]) && paymentRequest.transactionInfo.totalPrice) || 0;
                try {
                    if (amt <= 0) 
                        throw "Payment is not authorized. Invalid amount. Amount must be greater than 0";
                    authorizeGPay({ token: paymentToken, amount: amt})
                    .then((resp) => {
                        gpRequest.handleResponse(resp);
                        resolve(resp);
                    })
                    .catch((rej) => {
                        console.error("Payment is not authorized", JSON.stringify(rej));
                        setTimeout(function () { alert("Payment is not authorized. Please check the logs") }, 500);
                        reject(rej);
                    });
                } catch (err) {
                    const emsg = JSON.stringify(err);
                    console.error(emsg);
                    setTimeout(function () { alert(emsg) }, 500);
                    reject({error: err});
                }
            } catch (e) {
                reject(e);
            }
        }, 100); //3000);
    });
}

onPaymentCanceled callback example

onPaymentCanceled: function(respCanceled) {
    setTimeout(function () { alert("Payment was canceled") }, 500);
}

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

merchantInfo: {
    merchantName: "Example Merchant"
}

GPButtonLoadedResult Object

Name

Type

Description

status

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

billingParameters: {
    transactionId: "b65c7435-b57a-407e-a6e0-b166518d5d97",
    allowedAuthMethods: ["PAN_ONLY"],
    allowedCardNetworks: ["VISA", "MASTERCARD"],
    emailRequired: true
    billingAddressRequired: true,
    billingAddressFormat: GPBillingAddressFormat.min,
    phoneNumberRequired: true
}

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

shippingParams: {
    allowedCountryCodes: ['US'],
    onGetShippingCosts: function (shippingData) {
        logDebug({
            label: "onGetShippingCosts",
            data: shippingData
        });
        return {
            "shipping-001": "0.00",
            "shipping-002": "1.99",
            "shipping-003": "10.00"
        }
    },
    onGetShippingOptions: function (shippingData) {
        logDebug({
            label: "onGetShippingOptions",
            data: shippingData
        });
        let selectedOptionid = "shipping-001";
        if (shippingData && shippingData.shippingOptionData && shippingData.shippingOptionData.id !== "shipping_option_unselected") {
            selectedOptionid = shippingData.shippingOptionData.id;
        }
        return {
            defaultSelectedOptionId: selectedOptionid,
            shippingOptions: [
                {
                    "id": "shipping-001",
                    "label": "Free: Standard shipping",
                    "description": "Free Shipping delivered in 5 business days."
                },
                {
                    "id": "shipping-002",
                    "label": "$1.99: Standard shipping",
                    "description": "Standard shipping delivered in 3 business days."
                },
                {
                    "id": "shipping-003",
                    "label": "$10: Express shipping",
                    "description": "Express shipping delivered in 1 business day."
                },
            ]
        };
    }
}

ShippingData Object

Name

Type

Description

shippingAddress

An Address containing countryCode, postalCode, locality(city), administrativeArea(state).

shippingOptionData

An object containing a selected option

ShippingData object example

{
  "shippingAddress": {
    "countryCode": "US",
    "postalCode": "10601",
    "locality": "White Plains",
    "administrativeArea": "NY"
  },
  "shippingOptionData": {
    "id": "shipping-001"
  }
}

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

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

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

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

buttonOptions: {
    buttonColor: GPButtonColor.white,
    buttonType: GPButtonType.buy,
    buttonSizeMode: GPButtonSizeMode.full
}

Last updated