Braintree customer.find() 无法使用 Nodejs
Braintree customer.find() not working using Nodejs
我正在为我的一个项目使用 Braintree nodejs Sdk,
我在使用 customer.find()
函数时遇到问题。
origina link is here
当我以这种方式直接传递像“207”这样的用户 ID 时,它起作用了。
var braintree = require("braintree");
var gateway = require("./bt");
gateway.customer.find('207', function(err, customer) {
console.log("customer:",customer);
});
但是当我尝试传递动态 ID 时,它不起作用;
btuserID = data.userId;
gateway.customer.find(btuserID, function(err, customer) {
console.log("customer:",customer);
});
我认为它的参数类型是字符串,那么如何在不使用双引号的情况下传递参数?
完全错误:
/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)
如果你尝试
console.log(typeof(btuserID));
我怀疑您会看到类型是 Number
,如果是这样,请尝试下面的建议。
更改对此的分配以将数字转换为字符串。
btuserID = data.userId.toString();
如果您查看 braintree Node.js 库的源代码,您会发现它首先尝试 trim 字符串。如果您对一个数字执行此操作,您会认为这会失败。
https://github.com/braintree/braintree_node/blob/master/src/braintree/customer_gateway.coffee
我运行今天遇到了同样的问题。
您只需要做:
gateway.customer.find(JSON.stringify(btuserID), function(err,customer){
console.log("customer:",customer);
});
我正在为我的一个项目使用 Braintree nodejs Sdk,
我在使用 customer.find()
函数时遇到问题。
origina link is here
当我以这种方式直接传递像“207”这样的用户 ID 时,它起作用了。
var braintree = require("braintree");
var gateway = require("./bt");
gateway.customer.find('207', function(err, customer) {
console.log("customer:",customer);
});
但是当我尝试传递动态 ID 时,它不起作用;
btuserID = data.userId;
gateway.customer.find(btuserID, function(err, customer) {
console.log("customer:",customer);
});
我认为它的参数类型是字符串,那么如何在不使用双引号的情况下传递参数?
完全错误:
/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)
如果你尝试
console.log(typeof(btuserID));
我怀疑您会看到类型是 Number
,如果是这样,请尝试下面的建议。
更改对此的分配以将数字转换为字符串。
btuserID = data.userId.toString();
如果您查看 braintree Node.js 库的源代码,您会发现它首先尝试 trim 字符串。如果您对一个数字执行此操作,您会认为这会失败。
https://github.com/braintree/braintree_node/blob/master/src/braintree/customer_gateway.coffee
我运行今天遇到了同样的问题。 您只需要做:
gateway.customer.find(JSON.stringify(btuserID), function(err,customer){
console.log("customer:",customer);
});