Response objects

This reference describes the Google Pay API response object options to use with your website. Response objects are objects that are returned by the Google Pay API client methods.

IsReadyToPayResponse

This object provides information about a website visitor's ability to provide payment information to the site that requests it.

Property Type Always exists Description
result boolean Yes The current visitor is able to provide payment information to the site that requests it. A visitor's ability to pay may be tied to their web browser's ability to display required components for the specified payment methods. This includes when they log in to a Google Account and provide a payment method.
paymentMethodPresent boolean No

If true, the visitor has one or more payment methods as specified in the allowedPaymentMethods property of the provided IsReadyToPayRequest.

Exists only when existingPaymentMethodRequired was set to true in IsReadyToPayRequest.

If PaymentsClient is initialized with an environment property of TEST a payment method is always considered present.

Example

The following example shows you when the current visitor is able to provide payment information to the site that requests it.

{
  "result": true
}

PaymentData

This is a response object that's returned by Google after a payer approves payment.

Property Type Always exists Description
apiVersion number Yes Major API version. The value in the response matches the value provided in PaymentDataRequest.
apiVersionMinor number Yes Minor API version. The value in the response matches the value provided in PaymentDataRequest.
paymentMethodData PaymentMethodData Yes Data about the selected payment method.
email string No Email address, if emailRequired is set to true in the PaymentDataRequest. If another request has the property set to true there's no effect.
shippingAddress Address No Shipping address, if shippingAddressRequired is set to true in the PaymentDataRequest.

Example

This example response for Google Pay API version 2.0 shows a CARD payment method selected in the Google Pay payment sheet. A payment method token was generated for the example gateway.

{
  "apiVersion": 2,
  "apiVersionMinor": 0,
  "paymentMethodData": {
    "type": "CARD",
    "description": "Visa •••• 1234",
    "info": {
      "cardNetwork": "VISA",
      "cardDetails": "1234"
    },
    "tokenizationData": {
      "type": "PAYMENT_GATEWAY",
      "token": "examplePaymentMethodToken"
    }
  }
}

IntermediatePaymentData

This is object is returned by the Google Pay API onPaymentDataChanged() input when shipping address or shipping options is changed in the payment sheet.

Property Type Necessity Description
callbackTrigger String Optional

Describes the reason for which payment data callback was invoked.

  • INITIALIZE
  • SHIPPING_ADDRESS
  • SHIPPING_OPTION
shippingAddress IntermediateAddress Optional The selected address in the payment sheet.
shippingOptionData SelectionOptionData Optional The selected shipping option in the payment sheet.

Example

This example shows the intermediate payload returned from Google Pay API.

{
  callbackTrigger: "SHIPPING_ADDRESS"
  shippingAddress: {
    administrativeArea: "NY"
    countryCode: "US"
    locality: "New York"
    postalCode: "10011"
  },
  shippingOptionData: {
    id: "shipping-001"
  }
}

PaymentMethodData

This object provides data for a selected payment method.

Property Type Always exists Description
type string Yes PaymentMethod type selected in the Google Pay payment sheet.
description string Yes

User-facing message to describe the payment method that funds this transaction.

info object Yes The value of this property depends on the payment method type returned. For CARD, see CardInfo.
tokenizationData PaymentMethodTokenizationData Yes Payment tokenization data for the selected payment method.

Example

This example response shows how a CARD payment method that's selected in the Google Pay payment sheet generates a payment method token for the example gateway.

{
  "type": "CARD",
  "description": "Visa •••• 1234",
  "info": {
    "cardNetwork": "VISA",
    "cardDetails": "1234"
  },
  "tokenizationData": {
    "type": "PAYMENT_GATEWAY",
    "token": "examplePaymentMethodToken"
  }
}

CardInfo

This object provides information about the selected payment card.

Property Type Always exists Description
cardDetails string Yes The details about the card. This value is commonly the last four digits of the selected payment account number.
cardNetwork string Yes

The payment card network of the selected payment. Returned values match the format of allowedCardNetworks in CardParameters.

This card network value should not be displayed to the buyer. It's used when the details of a buyer's card are needed. For example, if customer support needs this value to identify the card a buyer used for their transaction. For a user-visible description, use the description property of PaymentMethodData instead.

billingAddress Address No The billing address associated with the provided payment method, if billingAddressRequired is set to true in CardParameters.

Example

This example shows a card on the Visa network.

{
  "cardNetwork": "VISA",
  "cardDetails": "1234"
}

PaymentMethodTokenizationData

This object provides tokenization data for the payment method.

Property Type Always exists Description
type string Yes The type of tokenization to be applied to the selected payment method. This value matches the type set in PaymentMethodTokenizationSpecification.
token string No

The generated payment method token.

Example

This is an example of a tokenized response prepared for the example gateway.

{
  "type": "PAYMENT_GATEWAY",
  "token": "examplePaymentMethodToken"
}

DisplayItem

Property Type Necessity Description
label String Required The label to be displayed for the given option.
type String Required

Type of displayed line item:

  • LINE_ITEM
  • SUBTOTAL
price String Required The monetary value of the cart item with an optional decimal precision of two decimal places. Negative values are allowed.
status String Optional

The following variables define price variance:

  • FINAL
  • PENDING

Default to FINAL if not provided.

Example

This example shows a list of transaction items that can be shown from the payment sheet.

{
  displayItems: [
    {
      label: "Subtotal",
      type: "SUBTOTAL",
      price: "11.00",
    },
    {
      label: "Tax",
      type: "TAX",
      price: "1.00",
    },
    {
      "label": "Shipping",
      "type": "LINE_ITEM",
      "price": "0", // Won't be displayed since status is PENDING
      "status": "PENDING",
    }
  ]
}

PaymentAuthorizationResult

This object provides information about the payment authorization result.

Property Type Necessity Description
transactionState String Required The state of the transaction is resolved by one of the following merchant results:
  • SUCCESS
  • ERROR
error PaymentDataError Optional The error to be rendered in the payment sheet for the user when it's necessary to retry the payment.

Example

The following example shows the payment result return after a payment is processed:

{
  transactionState: "ERROR",
  error: {
    reason: "PAYMENT_DATA_INVALID",
    message: "Cannot pay with payment credentials",
    intent: "PAYMENT_AUTHORIZATION"
  }
}

PaymentDataError

Property Type Necessity Description
reason String Required

List of predefined error reasons:

  • PAYMENT_DATA_INVALID
  • SHIPPING_ADDRESS_INVALID
  • SHIPPING_ADDRESS_UNSERVICEABLE
  • SHIPPING_OPTION_INVALID
  • OTHER_ERROR
message String Required Error message to the user that's displayed in a dialog.
intent String Required

The intent of the error. This must be one that’s been registered in PaymentDataRequest from the start of the flow.

  • PAYMENT_AUTHORIZATION
  • SHIPPING_ADDRESS
  • SHIPPING_OPTION

Example

This example shows the error intent and message to be rendered in the payment sheet.

{
  error: {
    reason: "SHIPPING_OPTION_INVALID",
    message: "This shipping option is invalid for the given address",
    intent: "SHIPPING_OPTION"
  }
}

Address

This object provides information about a requested postal address. All the properties are strings.

A MIN address format may be returned if billingAddressFormat is set to MIN. A shipping address is returned in the FULL address format. All properties in a MIN formatted response exist in a FULL formatted response.

Property Address format Description
name MIN The full name of the addressee.
postalCode MIN The postal or ZIP code.
countryCode MIN ISO 3166-1 alpha-2 country code.
phoneNumber MIN A telephone number, if phoneNumberRequired is set to true in the PaymentDataRequest.
address1 FULL The first line of the address.
address2 FULL The second line of the address.
address3 FULL The third line of the address.
locality FULL City, town, neighborhood, or suburb.
administrativeArea FULL A country subdivision, such as a state or province.
sortingCode FULL The sorting code.

Example

This is an example address in the United States with multiple lines of street address data.

{
  "name": "John Doe",
  "address1": "c/o Google LLC",
  "address2": "1600 Amphitheatre Pkwy",
  "address3": "Building 40",
  "locality": "Mountain View",
  "administrativeArea": "CA",
  "countryCode": "US",
  "postalCode": "94043",
  "sortingCode": ""
}

IntermediateAddress

Property Type Necessity Description
administrativeArea String Required A country subdivision, such as a state or province.
countryCode String Required ISO 3166-1 alpha-2 country code.
locality String Required City, town, neighborhood, or suburb.
postalCode String Required The redacted postal code based on the country. For Canada and the UK, this contains only the first three characters. For US, this contains the first five digits.

Example

This example shows you the address selected in the payment sheet.

{
  administrativeArea: "NY",
  countryCode: "US",
  locality: "New York",
  postalCode: "10011"
}

SelectionOptionData

Property Type Necessity Description
id String Required Matches with SelectionOption.id

Example

This example shows you the shipping option selected in the payment sheet.

{
  id: "shipping-001"
}