PaymentRequestComponent

PaymentRequestComponent

This class represents a Payment Request component produced by braintree-web/payment-request.create. Instances of this class have methods for initializing a Payment Request.

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 PaymentRequestComponent(options)

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

Parameters:
Name Type Description
options object

The Payment Request Component create options.

Source:

Methods

createSupportedPaymentMethodsConfiguration(type, overridesopt) → {object}

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

Parameters:
Name Type Attributes Description
type string

The supported payment method type. Possible values are basicCard and payWithGoogle. If no type is provided, the function will throw an error. If the type provided is not an enabled payemnt method for the merchant account , the function will throw an error.

overrides object <optional>

The configuration overrides for the data property on the supported payment methods objects. If not passed in, the default configuration for the specified type will be provided. If a property is not provided, the value from the default configruation will be used.

Source:
Examples

Getting the default configuration for a specified type

var configuration = paymentRequestInstance.createSupportedPaymentMethodsConfiguration('basicCard');

configuration.supportedMethods; // ['basic-card']
configuration.data.supportedNetworks; // ['visa', 'mastercard', 'amex'] <- whatever the supported card networks for the merchant account are

Specifying overrides

var configuration = paymentRequestInstance.createSupportedPaymentMethodsConfiguration('basicCard', {
  supportedNetworks: ['visa'],
  supportedTypes: ['credit', 'debit']
});

configuration.supportedMethods; // ['basic-card']
configuration.data.supportedNetworks; // ['visa']
configuration.data.supportedTypes; // ['credit', 'debit']

teardown(callbackopt) → {Promise|void}

Cleanly remove anything set up by create.

Parameters:
Name Type Attributes Description
callback callback <optional>

Called on completion.

Source:
Examples
paymentRequestInstance.teardown();

With callback

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

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

Tokenizes a Payment Request

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.

supportedPaymentMethods array <optional>

The supported payment methods. If not passed in, the supported payment methods from the merchant account that generated the authorization for the client will be used. For details on this array, see Google's PaymentRequest API documentation.

options object <optional>

Additional payment request 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
paymentRequestInstance.tokenize({
  details: {
    total: {
      label: 'Price',
      amount: {
        currency: 'USD',
        value: '100.00'
      }
    }
  }
}).then(function (payload) {
  // send payload.nonce to server

  // examine the raw response (with card details removed for security) from the payment request
  console.log(payload.details.rawPaymentResponse);
}).catch(function (err) {
  if (err.code === 'PAYMENT_REQUEST_CANCELED') {
    // payment request was canceled by user
  } else {
    // an error occurred while processing
  }
});

Tokenize only Visa cards

var basicCardConfiguration = paymentRequestInstance.createSupportedPaymentMethodsConfiguration('basicCard', {
  supportedNetworks: ['visa']
};

paymentRequestInstance.tokenize({
  supportedPaymentMethods: [basicCardConfiguration],
  details: {
    total: {
      label: 'Price',
      amount: {
        currency: 'USD',
        value: '100.00'
      }
    }
  }
}).then(function (payload) {
  // send payload.nonce to your server
});

Include payment request options

paymentRequestInstance.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
  // collect shipping information from payload
  console.log(payload.details.rawPaymentResponse.shippingAddress);
});