Braintree = Npm.require('braintree');

BrainTreeConnect = function (key) {
  var BraintreeObj;
  var resources = {
    address : ['create', 'delete', 'find', 'update'],
    clientToken : ['generate'],
    customer : ['create', 'delete', 'find', 'search', 'update'],
    merchantAccount : ['create', 'find', 'update'],
    paymentMethod : ['create', 'delete', 'find', 'update'],
    paymentMethodNonce : ['create', 'find'],
    plan : ['all'],
    subscription : ['cancel', 'create', 'find', 'search', 'update'],
    transaction : ['cancelRelease', 'cloneTransaction', 'find', 'holdInEscrow', 'refund', 'releaseFromEscrow', 'sale', 'search', 'submitForSettlement', 'void']
  };

  BraintreeObj = Braintree.connect(key);

  _.each(resources, function (resource, key){
    _.each(resource, function (funcName){
      var func = BraintreeObj[key][funcName];
      BraintreeObj[key][funcName] = Meteor.wrapAsync(func, BraintreeObj[key]);
    });
  });

  return BraintreeObj;
};

BrainTreeConnect.Environment = Braintree.Environment;

Braintree = Npm.require('braintree');

BrainTreeConnect = function (key) {
  var BraintreeObj;
  var resources = {
    address : ['create', 'delete', 'find', 'update'],
    clientToken : ['generate'],
    customer : ['create', 'delete', 'find', 'search', 'update'],
    merchantAccount : ['create', 'find', 'update'],
    paymentMethod : ['create', 'delete', 'find', 'update'],
    paymentMethodNonce : ['create', 'find'],
    plan : ['all'],
    subscription : ['cancel', 'create', 'find', 'search', 'update'],
    transaction : ['cancelRelease', 'cloneTransaction', 'find', 'holdInEscrow', 'refund', 'releaseFromEscrow', 'sale', 'search', 'submitForSettlement', 'void']
  };

  BraintreeObj = Braintree.connect(key);

  _.each(resources, function (resource, key){
    _.each(resource, function (funcName){
      var func = BraintreeObj[key][funcName];
      BraintreeObj[key][funcName] = Meteor.wrapAsync(func, BraintreeObj[key]);
    });
  });

  return BraintreeObj;
};

Revert "Link Braintree.Environment to BrainTreeConnect.Environment"
Revert "Link Braintree.Environment to BrainTreeConnect.Environment"

This reverts commit 98160276ff59b33359a91faf891d436ce26d6e2f.
