Client

Client

This class is required by many other Braintree components. It serves as the base API layer that communicates with our servers. It is also capable of being used to formulate direct calls to our servers, such as direct credit card tokenization. See Client#request.

Constructor

new Client(configuration)

Do not use this constructor directly. Use braintree.client.create instead.

Parameters:
Name Type Description
configuration Client~configuration

Options

Source:

Methods

getConfiguration() → {Client~configuration}

Returns a copy of the configuration values.

Source:

getVersion() → {String|void}

Returns the Client version.

Source:
Example
var createClient = require('braintree-web/client').create;

createClient({
  authorization: CLIENT_AUTHORIZATION
}, function (createErr, clientInstance) {
  console.log(clientInstance.getVersion()); // Ex: 1.0.0
});

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

Used by other modules to formulate all network requests to the Braintree gateway. It is also capable of being used directly from your own form to tokenize credit card information. However, be sure to satisfy PCI compliance if you use direct card tokenization.

Parameters:
Name Type Attributes Description
options object

Request options:

Properties
Name Type Attributes Default Description
method string

HTTP method, e.g. "get" or "post".

endpoint string

Endpoint path, e.g. "payment_methods".

data object

Data to send with the request.

timeout number <optional>
60000

Set a timeout (in milliseconds) for the request.

callback callback <optional>

The second argument, data, is the returned server data.

Source:
Example

Direct Credit Card Tokenization

var createClient = require('braintree-web/client').create;

createClient({
  authorization: CLIENT_AUTHORIZATION
}, function (createErr, clientInstance) {
  var form = document.getElementById('my-form-id');
  var data = {
    creditCard: {
      number: form['cc-number'].value,
      cvv: form['cc-cvv'].value,
      expirationDate: form['cc-date'].value,
      billingAddress: {
        postalCode: form['cc-postal'].value
      },
      options: {
        validate: false
      }
    }
  };

  // Warning: For a merchant to be eligible for the easiest level of PCI compliance (SAQ A),
  // payment fields cannot be hosted on your checkout page.
  // For an alternative to the following, use Hosted Fields.
  clientInstance.request({
    endpoint: 'payment_methods/credit_cards',
    method: 'post',
    data: data
  }, function (requestErr, response) {
    // More detailed example of handling API errors: https://codepen.io/braintree/pen/MbwjdM
    if (requestErr) { throw new Error(requestErr); }

    console.log('Got nonce:', response.creditCards[0].nonce);
  });
});

Type Definitions

configuration :object

This object is returned by getConfiguration. This information is used extensively by other Braintree modules to properly configure themselves.

Properties:
Name Type Description
client object

The braintree-web/client parameters.

Properties
Name Type Description
authorization string

A tokenizationKey or clientToken.

gatewayConfiguration object

Gateway-supplied configuration.

analyticsMetadata object

Analytics-specific data.

Properties
Name Type Description
sessionId string

Uniquely identifies a browsing session.

sdkVersion string

The braintree.js version.

merchantAppId string

Identifies the merchant's web app.

Source: