node.js – Braintree customer.find()无法使用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,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));

我怀疑你会看到类型是一个数字,如果是这样,那么尝试下面的建议.

将您的分配更改为此以将数字转换为字符串.

btuserID = data.userId.toString();

如果您查看braintree Node.js库的源代码,您将看到它首先尝试修剪字符串.如果你对一个数字执行此操作,您可能会失败.

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

相关文章

这篇文章主要介绍“基于nodejs的ssh2怎么实现自动化部署”的...
本文小编为大家详细介绍“nodejs怎么实现目录不存在自动创建...
这篇“如何把nodejs数据传到前端”文章的知识点大部分人都不...
本文小编为大家详细介绍“nodejs如何实现定时删除文件”,内...
这篇文章主要讲解了“nodejs安装模块卡住不动怎么解决”,文...
今天小编给大家分享一下如何检测nodejs有没有安装成功的相关...