USBankAccount

USBankAccount

This class represents a US Bank Account component. Instances of this class can tokenize raw bank details or present a bank login. You cannot use this constructor directly. Use braintree.us-bank-account.create instead.

Constructor

new USBankAccount(options)

Parameters:
Name Type Description
options object

See us-bank-account.create.

Source:

Methods

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
usBankAccountInstance.teardown();

With callback

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

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

Tokenizes bank information to return a payment method nonce. You can tokenize bank details by providing information like account and routing numbers. You can also tokenize with a bank login UI that prompts the customer to log into their bank account.

Parameters:
Name Type Attributes Description
options object

All tokenization options for the US Bank Account component.

Properties
Name Type Attributes Description
mandateText string

A string for proof of customer authorization. For example, 'I authorize Braintree to debit my bank account on behalf of My Online Store.'.

bankDetails object <optional>

Bank detail information (such as account and routing numbers). bankDetails or bankLogin option must be provided.

Properties
Name Type Attributes Description
routingNumber string

The customer's bank routing number, such as '307075259'.

accountNumber string

The customer's bank account number, such as '999999999'.

accountType string

The customer's bank account type. Must be 'checking' or 'savings'.

ownershipType string

The customer's bank account ownership type. Must be 'personal' or 'business'.

firstName string <optional>

The customer's first name. Required when account ownership type is personal.

lastName string <optional>

The customer's last name. Required when account ownership type is personal.

businessName string <optional>

The customer's business name. Required when account ownership type is business.

billingAddress object

The customer's billing address.

Properties
Name Type Attributes Description
streetAddress string

The street address for the customer's billing address, such as '123 Fake St'.

extendedAddress string <optional>

The extended street address for the customer's billing address, such as 'Apartment B'.

locality string

The locality for the customer's billing address. This is typically a city, such as 'San Francisco'.

region string

The region for the customer's billing address. This is typically a state, such as 'CA'.

postalCode string

The postal code for the customer's billing address. This is typically a ZIP code, such as '94119'.

bankLogin object <optional>

Bank login information. bankLogin or bankDetails option must be provided.

Properties
Name Type Attributes Description
displayName string

Display name for the bank login UI, such as 'My Store'.

ownershipType string

The customer's bank account ownership type. Must be 'personal' or 'business'.

firstName string <optional>

The customer's first name. Required when account ownership type is personal.

lastName string <optional>

The customer's last name. Required when account ownership type is personal.

businessName string <optional>

The customer's business name. Required when account ownership type is business.

billingAddress object

The customer's billing address.

Properties
Name Type Attributes Description
streetAddress string

The street address for the customer's billing address, such as '123 Fake St'.

extendedAddress string <optional>

The extended street address for the customer's billing address, such as 'Apartment B'.

locality string

The locality for the customer's billing address. This is typically a city, such as 'San Francisco'.

region string

The region for the customer's billing address. This is typically a state, such as 'CA'.

postalCode string

The postal code for the customer's billing address. This is typically a ZIP code, such as '94119'.

callback callback <optional>

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

Source:
Examples

Tokenizing raw bank details

var routingNumberInput = document.querySelector('input[name="routing-number"]');
var accountNumberInput = document.querySelector('input[name="account-number"]');
var accountTypeInput = document.querySelector('input[name="account-type"]:checked');
var ownershipTypeInput = document.querySelector('input[name="ownership-type"]:checked');
var firstNameInput = document.querySelector('input[name="first-name"]');
var lastNameInput = document.querySelector('input[name="last-name"]');
var businessNameInput = document.querySelector('input[name="business-name"]');
var billingAddressStreetInput = document.querySelector('input[name="street-address"]');
var billingAddressExtendedInput = document.querySelector('input[name="extended-address"]');
var billingAddressLocalityInput = document.querySelector('input[name="locality"]');
var billingAddressRegionSelect = document.querySelector('select[name="region"]');
var billingAddressPostalInput = document.querySelector('input[name="postal-code"]');

submitButton.addEventListener('click', function (event) {
  var bankDetails = {
    routingNumber: routingNumberInput.value,
    accountNumber: accountNumberInput.value,
    accountType: accountTypeInput.value,
    ownershipType: ownershipTypeInput.value,
    billingAddress: {
      streetAddress: billingAddressStreetInput.value,
      extendedAddress: billingAddressExtendedInput.value,
      locality: billingAddressLocalityInput.value,
      region: billingAddressRegionSelect.value,
      postalCode: billingAddressPostalInput.value
    }
  };

  if (bankDetails.ownershipType === 'personal') {
    bankDetails.firstName = firstNameInput.value;
    bankDetails.lastName = lastNameInput.value;
  } else {
    bankDetails.businessName = businessNameInput.value;
  }

  event.preventDefault();

  usBankAccountInstance.tokenize({
    bankDetails: bankDetails,
    mandateText: 'I authorize Braintree to debit my bank account on behalf of My Online Store.'
  }, function (tokenizeErr, tokenizedPayload) {
    if (tokenizeErr) {
      console.error('There was an error tokenizing the bank details.');
      return;
    }

    // Send tokenizePayload.nonce to your server here!
  });
});

Tokenizing with bank login UI

var ownershipTypeInput = document.querySelector('input[name="ownership-type"]:checked');
var firstNameInput = document.querySelector('input[name="first-name"]');
var lastNameInput = document.querySelector('input[name="last-name"]');
var businessNameInput = document.querySelector('input[name="business-name"]');
var billingAddressStreetInput = document.querySelector('input[name="street-address"]');
var billingAddressExtendedInput = document.querySelector('input[name="extended-address"]');
var billingAddressLocalityInput = document.querySelector('input[name="locality"]');
var billingAddressRegionSelect = document.querySelector('select[name="region"]');
var billingAddressPostalInput = document.querySelector('input[name="postal-code"]');

bankLoginButton.addEventListener('click', function (event) {
  var bankLogin = {
    displayName: 'My Online Store',
    ownershipType: ownershipTypeInput.value,
    billingAddress: {
      streetAddress: billingAddressStreetInput.value,
      extendedAddress: billingAddressExtendedInput.value,
      locality: billingAddressLocalityInput.value,
      region: billingAddressRegionSelect.value,
      postalCode: billingAddressPostalInput.value
    }
  }
  event.preventDefault();

  if (bankLogin.ownershipType === 'personal') {
    bankLogin.firstName = firstNameInput.value;
    bankLogin.lastName = lastNameInput.value;
  } else {
    bankLogin.businessName = businessNameInput.value;
  }

  usBankAccountInstance.tokenize({
    bankLogin: bankLogin,
    mandateText: 'I authorize Braintree to debit my bank account on behalf of My Online Store.'
  }, function (tokenizeErr, tokenizedPayload) {
    if (tokenizeErr) {
      console.error('There was an error tokenizing the bank details.');
      return;
    }

    // Send tokenizePayload.nonce to your server here!
  });
});

Type Definitions

tokenizePayload :object

Properties:
Name Type Description
nonce string

The payment method nonce.

type string

The payment method type, always us_bank_account.

details object

Additional account details. Currently empty.

Source: