A promise-focused wrapper around the Braintree node.js SDK
Last updated 2 years ago by roonie .
ISC · Repository · Original npm · Tarball
$ cnpm install braintree-node 
SYNC missed versions from official npm registry.

#braintree-node - promisifies the braintree node.js SDK with extra helper utilities

##Note: I am in no way affiliated with braintree and this is not the official braintree node.js SDK. If you are looking for the official SDK, visit this link :


  1. Run the following: npm install --save braintree-node

  2. instantiate the gateway, passing in a configuration object. In lieu of braintree.Environment.Sandbox or braintree.Environment.Production, just set the environment property on your configuration object to the string of the environment you want, like so:

var config = {
  environment: 'Production',
  publicKey: yourPublicKey,
  privateKey: yourPrivateKey,
  merchantId: yourMerchantId
var gateway = require('braintree-node')(config);


Most methods take the same parameters as the current Node.js SDK methods, except for the callback. Instead, you can .then off of the gateway methods or yield them if you are using generators (or await, if you're transpiling ES7 down with babel).


var customer = { id: 'roondog', firstName: 'roonie' };
  .then(function(response) {
    // handle successful response...
  .catch(function(error) {
    // handle rejection...



You can create a customer like so:'/createBraintreeUser', function(req, res) {
    .then(function(response) {
      res.json({user: response.customer});
    .catch(function(error) {
      res.status(400).send({error: error});


Create multiple users'/createManyBraintreeUsers', function(req, res) {
  var users = [{id: '123'}, {id: '456'}, {id: '789'}];

###.createTransaction(amount, nonce, options)

Wrapper for, rejects if amount or nonce is undefined. Any options passed in will be set on the options property of the object that takes in the SDK'/checkout', function(req, res) {
  var amount = req.body.amount;
  var nonce = req.body.nonce;
  var options = req.body.paymentOptions;
  gateway.createTransaction(amount, nonce, options)

###.deleteCustomer(id) Deletes the braintree user with the given id.

app.del('/deleteBraintreeUser', function(req, res) {
  var theID = req.body;
    .then(response => {...})
    .catch(error => {...});

###.deleteMultipleCustomers(users) Deletes all braintree users in an array of users. Each object in the array only needs an id property so braintree can find the user to delete.

app.del('/deleteBraintreeUsers', function(req, res) {
  var users = [{id: '123'}, {id: '456'}];


Finds the braintree user with the given id. Resolves with the customer object (unlike most other methods which resolve with the http response from braintree).

app.get('/findBraintreeUser', function(req, res) {
  var theID = req.body;
    .then(function(response) {
      res.json({firstName: response.firstName});
    .catch(function(error) {
      res.status(400).json({error: error});

###.findOneAndUpdate(id, update, upsert) Takes a user object and updates it if it exists, and creates it if upsert is set to true

app.put('/updateOrCreate', function(req, res) {
  // assuming this user does not exist in braintree
  var user = {firstName: 'Bob'};
  gateway.findOneAndUpdate('123', user, true)
  gateway.findCustomer('123'); // => {id: '123', firstName: 'Bob'}


Generates client token

app.get('/token', function(req, res) {
    .then(response => res.json(response.clientToken))
    .catch(error => res.json(error));

###.updateCustomer(id, update) Updates braintree user with the given id and updates any properties on the update object

app.put('/me', function(req, res) {
  var theId = req.user._id;
  gateway.updateCustomer(theId, {firstName: 'prometheus'})
    .then(response => {...})
    .catch(error => {...});


Wrapper for .subscription.create, rejects if planId or nonce is undefined.'/subscribe', function(req, res) {
  var planId = req.body.planId;
  var nonce = req.body.nonce;
  var options = { planId: planId, paymentMethodNonce: nonce };


Finds the customer's subscription with the given id.

app.get('/findSubscription', function(req, res) {
  var theID = req.body;
    .then(function(response) {
      res.json({planId: response.planId});
    .catch(function(error) {
      res.status(400).json({error: error});

###.cancelSubscription(id) Deletes the customer's subscription with the given id.

app.del('/cancelSubscription', function(req, res) {
  var theID = req.body;
    .then(response => {...})
    .catch(error => {...});
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 51
Dependencies (4)
Dev Dependencies (2)

Copyright 2014 - 2018 © |