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 Pay with Google flow.

Note: This component is currently in beta and the API may include breaking changes when upgrading. Please review the Changelog for upgrade steps whenever you upgrade the version of braintree-web.

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

createSupportedPaymentMethodsConfiguration(overridesopt) → {object}

Create an object to pass into the tokenize method to specify a custom configuration. If no overrides are provided, the default configuration will be used in tokenize.

Parameters:
Name Type Attributes Description
overrides object <optional>

The configuration overrides for the data property on the supported payment methods objects. This object will be merged with the default configuration object based on the settings in the Braintree Gateway. If no object is passed in, the default configuration object will be returned.

Source:
Examples

Getting the default configuration for a specified type

var configuration = googlePaymentInstance.createSupportedPaymentMethodsConfiguration();

configuration.supportedMethods; // ['https://google.com/pay']

configuration.data.allowedCardNetworks; // ['AMEX', 'DISCOVER', 'MASTERCARD', 'VISA'] <- whatever the supported card networks for the merchant account are

Specifying overrides

var configuration = googlePaymentInstance.createSupportedPaymentMethodsConfiguration({
  merchantName: 'My Custom Merchant Account Name',
  allowedCardNetworks: ['VISA']
});

configuration.data.merchantName; // 'My Custom Merchant Account Name'
configuration.data.allowedCardNetworks; // ['VISA']

tokenize(configuration, callbackopt) → {Promise|void}

Initializes a Pay with Google flow and provides a nonce payload.

Parameters:
Name Type Attributes Description
configuration object

The payment details.

Properties
Name Type Attributes Description
details object

The payment details. For details on this object, see Google's PaymentRequest API documentation.

options object <optional>

Additional Pay with Google options. For details on this object, see Google's PaymentRequest API documentation.

Note: requestShipping is not supported by Braintree at this time.

callback callback <optional>

The second argument, data, is a paymentPayload. If no callback is provided, tokenize returns a function that resolves with a paymentPayload.

Source:
Examples
googlePaymentInstance.tokenize({
  details: {
    total: {
      label: 'Price',
      amount: {
        currency: 'USD',
        value: '100.00'
      }
    }
  }
}).then(function (payload) {
  // send payload.nonce to server
}).catch(function (err) {
  if (err.code === 'PAYMENT_REQUEST_CANCELED') {
    // Pay with Google payment request was canceled by user
  } else {
    // an error occurred while processing
  }
});

Include additional payment request options

googlePaymentInstance.tokenize({
  details: {
    total: {
      label: 'Price',
      amount: {
        currency: 'USD',
        value: '100.00'
      }
    }
  },
  options: {
    requestPayerName: true,
    requestPayerPhone: true,
    requestPayerEmail: true
  }
}).then(function (payload) {
  // Send payload.nonce to your server

  // Examine additional info in the raw payment response
  console.log(payload.details.rawPaymentResponse);
});

Include custom supported payment method object

googlePaymentInstance.tokenize({
  supportedPaymentMethods: googlePaymentInstance.createSupportedPaymentMethodsConfiguration({merchantName: 'Custom Name'}),
  details: {
    total: {
      label: 'Price',
      amount: {
        currency: 'USD',
        value: '100.00'
      }
    }
  },
  options: {
    requestPayerName: true,
    requestPayerPhone: true,
    requestPayerEmail: true
  }
}).then(function (payload) {
  // Send payload.nonce to your server

  // Examine additional info in the raw payment response
  console.log(payload.details.rawPaymentResponse);
});