GooglePayment

GooglePayment

This class represents a Google Payment component produced by braintree-web/google-payment.create. Instances of this class have methods for initializing the Google Pay flow.

Constructor

new GooglePayment(options)

Do not use this constructor directly. Use braintree-web.google-payment.create instead.

Parameters:
Name Type Description
options object

Google Payment create options.

Source:

Methods

createPaymentDataRequest(overrides) → {object|Promise}

Create a configuration object for use in the loadPaymentData method.

Note: Version 1 of the Google Pay Api is deprecated and will become unsupported in a future version. Until then, version 1 will continue to be used by default, and version 1 schema parameters and overrides will remain functional on existing integrations. However, new integrations and all following examples will be presented in the GooglePay version 2 schema. See Google Pay's upgrade guide to see how to update your integration.

If options.googlePayVersion === 2 was set during the initial create call, overrides must match the Google Pay v2 schema to be valid.

Parameters:
Name Type Description
overrides object

The supplied parameters for creating the PaymentDataRequest object. Required parameters are:

Properties
Name Type Description
transactionInfo object

Object according to the Google Pay Transaction Info spec. Optionally, any of the parameters in the PaymentDataRequest parameters can be overridden, but note that it is recommended only to override top level parameters to avoid squashing deeply nested configuration objects. An example can be found below showing how to safely edit these deeply nested objects.

Source:
Examples
var paymentDataRequest = googlePaymentInstance.createPaymentDataRequest({
  merchantInfo: {
    merchantId: 'my-merchant-id-from-google'
  },
  transactionInfo: {
    currencyCode: 'USD',
    totalPriceStatus: 'FINAL',
    totalPrice: '100.00'
  }
});

// Update card payment methods to require billing address
var cardPaymentMethod = paymentDataRequest.allowedPaymentMethods;
cardPaymentMethod.parameters.billingAddressRequired = true;
cardPaymentMethod.parameters.billingAddressParameters = {
  format: 'FULL',
  phoneNumberRequired: true
};

var paymentsClient = new google.payments.api.PaymentsClient({
  environment: 'TEST' // or 'PRODUCTION'
})

paymentsClient.loadPaymentData(paymentDataRequest).then(function (response) {
  // handle response with googlePaymentInstance.parseResponse
  // (see below)
});

With deferred client

googlePaymentInstance.createPaymentDataRequest({
  merchantInfo: {
    merchantId: 'my-merchant-id-from-google'
  },
  transactionInfo: {
    currencyCode: 'USD',
    totalPriceStatus: 'FINAL',
    totalPrice: '100.00'
  }
}).then(function (paymentDataRequest) {
  // Update card payment methods to require billing address
  var cardPaymentMethod = paymentDataRequest.allowedPaymentMethods;
  cardPaymentMethod.parameters.billingAddressRequired = true;
  cardPaymentMethod.parameters.billingAddressParameters = {
    format: 'FULL',
    phoneNumberRequired: true
  };

  var paymentsClient = new google.payments.api.PaymentsClient({
    environment: 'TEST' // or 'PRODUCTION'
  })

  return paymentsClient.loadPaymentData(paymentDataRequest);
}).then(function (response) {
  // handle response with googlePaymentInstance.parseResponse
  // (see below)
});

parseResponse(response, callbackopt) → {Promise|void}

Parse the response from the tokenization.

Parameters:
Name Type Attributes Description
response object

The response back from the Google Pay tokenization.

callback callback <optional>

The second argument, data, is a tokenizePayload. If no callback is provided, parseResponse returns a promise that resolves with a tokenizePayload.

Source:
Examples
with callback
var paymentsClient = new google.payments.api.PaymentsClient({
  environment: 'TEST' // or 'PRODUCTION'
})

paymentsClient.loadPaymentData(paymentDataRequestFromCreatePaymentDataRequest).then(function (response) {
  googlePaymentInstance.parseResponse(response, function (err, data) {
    if (err) {
      // handle errors
    }
    // send parsedResponse.nonce to your server
  });
});
with promise
var paymentsClient = new google.payments.api.PaymentsClient({
  environment: 'TEST' // or 'PRODUCTION'
})

paymentsClient.loadPaymentData(paymentDataRequestFromCreatePaymentDataRequest).then(function (response) {
  return googlePaymentInstance.parseResponse(response);
}).then(function (parsedResponse) {
  // send parsedResponse.nonce to your server
}).catch(function (err) {
  // handle errors
});

teardown(callbackopt) → {Promise|void}

Cleanly tear down anything set up by create.

Parameters:
Name Type Attributes Description
callback callback <optional>

Called once teardown is complete. No data is returned if teardown completes successfully.

Source:
Examples
googlePaymentInstance.teardown();

With callback

googlePaymentInstance.teardown(function () {
  // teardown is complete
});

Type Definitions

tokenizePayload :object

Properties:
Name Type Description
nonce string

The payment method nonce.

details object

Additional account details.

Properties
Name Type Description
cardType string

Type of card, ex: Visa, MasterCard.

lastFour string

Last four digits of card number.

lastTwo string

Last two digits of card number.

isNetworkTokenized boolean

True if the card is network tokenized.

bin string

First six digits of card number.

description string

A human-readable description.

type string

The payment method type, CreditCard or AndroidPayCard.

binData object

Information about the card based on the bin.

Properties
Name Type Description
commercial string

Possible values: 'Yes', 'No', 'Unknown'.

countryOfIssuance string

The country of issuance.

debit string

Possible values: 'Yes', 'No', 'Unknown'.

durbinRegulated string

Possible values: 'Yes', 'No', 'Unknown'.

healthcare string

Possible values: 'Yes', 'No', 'Unknown'.

issuingBank string

The issuing bank.

payroll string

Possible values: 'Yes', 'No', 'Unknown'.

prepaid string

Possible values: 'Yes', 'No', 'Unknown'.

productId string

The product id.

Source: