3
votes

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)
2
Can you try doing console.log(btuserID) on the line before the gateway.customer.find, just to make sure btuserID is the user id you expect it to be?Chris Diver
yes I did that and it is 207 without quotation.Muhammad Shahzad
I work at Braintree. Customer IDs are stored as strings, so you could try converting btuserID to a string before passing it to find. Based on the error you are getting, however, there may be another issue. Please reach out to braintree support (perhaps providing more of your server-side code) for further assistance.cdeist
I was integrating node.js with braintree subscription. Braintree provided good documentation. However, it lacks of a guide for implementing a complete flow for implementing single payment/subscription and it took me the whole day to figure it out. Hence, I have wrote a guide to help whoever want to use braintree single payment/subscription for their services here enormers.com/blog/…Mark Thien
Good work, Thanks for your sharing.Muhammad Shahzad

2 Answers

5
votes

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

2
votes

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