The customer object is an important component of the Braintree gateway. Use customers to store and organize payment methods. A single customer can have multiple payment methods.

This guide will walk you through the basics. See Customer Request and Customer Response references for complete details.

Create

Use customer.create() to add new customers.

You can create just a customer without an associated payment method, and the operation will be successful if all customer validations pass:

Node.js
gateway.customer.create({
  firstName: "Jen",
  lastName: "Smith",
  company: "Braintree",
  email: "jen@example.com",
  phone: "312.555.1234",
  fax: "614.555.5678",
  website: "www.example.com"
}, function (err, result) {
  result.success;
  // true

  result.customer.id;
  // e.g. 494019
});

Create with payment method

You can also create a customer with an associated payment method:

Node.js
gateway.customer.create({
  firstName: "Charity",
  lastName: "Smith",
  paymentMethodNonce: nonceFromTheClient
}, function (err, result) {
  result.success;
  // true

  result.customer.id;
  // e.g 160923

  result.customer.paymentMethods[0].token;
  // e.g f28wm
});

Success depends on both customer validations and payment method validations, and whether the payment method is verified (if card verification is enabled).

note

Braintree strongly recommends verifying all cards before they are stored in your Vault by enabling card verification for your entire account in the Control Panel. If you choose to manually verify cards, set verifyCard to true.

See the reference and more examples of creating a customer.

Update

Use customer.update() to update an existing customer:

Node.js
gateway.customer.update("theCustomerId", {
  firstName: "New First Name",
  lastName: "New Last Name"
}, function (err, result) {
});

If the customer can't be found, it will return a notFoundError.

See the reference and more examples of updating a customer.

Find

Use customer.find() to find a customer by ID:

Node.js
gateway.customer.find("theCustomerId", function(err, customer) {
});

If the customer can't be found, it will return a notFoundError.

The return value of this call will be a Customer response object.

Delete

Use customer.delete() to delete a customer and its payment methods using the customer's ID:

Node.js
gateway.customer.delete("theCustomerId", function (err) {
  err;
  // null
});

If the customer can't be found, it will return a notFoundError.