Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Braintree customer.find() not working using Nodejs

I'm using Braintree nodejs Sdk for one of my project, I have problem to use customer.find() function. origina link is here

when I passed a user id like '207' directly in this way, it's working.

var braintree = require("braintree");
var gateway = require("./bt");

 gateway.customer.find('207', function(err, customer) {              
               console.log("customer:",customer);           
 }); 

but when I tried to pass dynamic id, it's not working;

 btuserID  = data.userId;
 gateway.customer.find(btuserID, function(err, customer) {              
               console.log("customer:",customer);           
           }); 

I think it's argument type is string, so how I can pass argument without double quote?

Complete error:

/home/api/node_modules/loopback-connector-mysql/node_modules/mysql/lib/protocol/Parser.js:82
        throw err;
              ^
TypeError: undefined is not a function
    at CustomerGateway.find (/home/api/node_modules/braintree/lib/braintree/customer_gateway.js:37:20)
like image 468
Muhammad Shahzad Avatar asked Dec 05 '25 03:12

Muhammad Shahzad


2 Answers

If you try

console.log(typeof(btuserID));

I suspect you will see that the type is a Number, if so then try the suggestion below.

Change your assignment to this to convert the number to as string.

 btuserID = data.userId.toString(); 

If you look in the source for the braintree Node.js library, you will see that it tries to trim the string first. You would expect this to fail if you do this on a number.

https://github.com/braintree/braintree_node/blob/master/src/braintree/customer_gateway.coffee

like image 110
Chris Diver Avatar answered Dec 06 '25 16:12

Chris Diver


I run into the same problem today. You just need to do:

gateway.customer.find(JSON.stringify(btuserID), function(err,customer){
               console.log("customer:",customer);           
}); 
like image 29
user3359303 Avatar answered Dec 06 '25 17:12

user3359303