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 tokenziation. 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:
Returns:

configuration

Type
Client~configuration

request(options, callback) → {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 Description
options object

Request options

Properties
Name Type Attributes Default Description
method string

HTTP method. i.e. "get" or "post"

endpoint string

Enpoint path. i.e. "payment_methods"

data object

Data to send with the request

timeout string <optional>
60000

Timeout limit

callback errback

The second argument, data, is the returned server data

Source:
Returns:
Type
void
Example

Direct Credit Card Tokenization

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

createClient({
  authorization: CLIENT_TOKEN
}, function (err, client) {
  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
      }
    }
  };

  client.request({
    endpoint: 'payment_methods/credit_cards',
    method: 'post',
    data: data
  }, function (err, response) {
    if (err) { throw new Error(err); }

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

teardown(callback) → {void}

Cleanly tear down anything set up by create

Parameters:
Name Type Description
callback errorCallback

An errback

Source:
Returns:
Type
void

Type Definitions

configuration

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

Type:
  • Object
Properties:
Name Type Description
client Object

braintree/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: