npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

braintree-node

v1.1.2

Published

A promise-focused wrapper around the Braintree node.js SDK

Readme

#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 : https://www.npmjs.com/package/braintree

##Setup

  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);

gateway.createCustomer(...)

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).

Example:

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

#API

###.createCustomer(user)

You can create a customer like so:

app.post('/createBraintreeUser', function(req, res) {
  gateway.createCustomer(req.body)
    .then(function(response) {
      res.json({user: response.customer});
    })
    .catch(function(error) {
      res.status(400).send({error: error});
    });
});

###.createMultipleCustomers(users)

Create multiple users

app.post('/createManyBraintreeUsers', function(req, res) {
  var users = [{id: '123'}, {id: '456'}, {id: '789'}];
  gateway.createMultipleCustomers(users)
    .then(runsWhenAllAreCreated)
    .catch(runsIfAnyOneCustomerFailed);
});

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

Wrapper for .transaction.sale, rejects if amount or nonce is undefined. Any options passed in will be set on the options property of the object that transaction.sale takes in the SDK

app.post('/checkout', function(req, res) {
  var amount = req.body.amount;
  var nonce = req.body.nonce;
  var options = req.body.paymentOptions;
  gateway.createTransaction(amount, nonce, options)
    .then(handleSuccessfulTransaction)
    .catch(handleFailedTransaction);
});

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

app.del('/deleteBraintreeUser', function(req, res) {
  var theID = req.body;
  gateway.deleteCustomer(theID)
    .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'}];
  gateway.deleteMultipleCustomers(users)
    .then(continueAfterAllDeleted)
    .catch(handleFailure);
});

###.findCustomer(id)

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;
  gateway.findCustomer(theID)
    .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)
    .then(handleSuccess)
    .then(handleRejection);
  gateway.findCustomer('123'); // => {id: '123', firstName: 'Bob'}
});

###.generateClientToken()

Generates client token

app.get('/token', function(req, res) {
  gateway.generateClientToken()
    .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 => {...});
})

###.createSubscription(options)

Wrapper for .subscription.create, rejects if planId or nonce is undefined.

app.post('/subscribe', function(req, res) {
  var planId = req.body.planId;
  var nonce = req.body.nonce;
  var options = { planId: planId, paymentMethodNonce: nonce };
  gateway.createTransaction(options)
    .then(handleSuccessfulSubscription)
    .catch(handleFailedSubscription);
});

###.findSubscription(id)

Finds the customer's subscription with the given id.

app.get('/findSubscription', function(req, res) {
  var theID = req.body;
  gateway.findSubscription(theID)
    .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;
  gateway.cancelSubscription(theID)
    .then(response => {...})
    .catch(error => {...});
});