sao chép trực tiếp từ hướng dẫn Braintree, bạn có thể tạo ra một mã thông báo cho khách hàng với một ID của khách hàng như thế này:Không thể tạo Braintree thẻ khách hàng với ID khách hàng
gateway.clientToken.generate({
customerId: aCustomerId
}, function (err, response) {
clientToken = response.clientToken
});
Tôi tuyên bố var aCustomerId = "customer"
nhưng Node.js kết thúc với các lỗi
new TypeError('first argument must be a string or Buffer')
Khi tôi cố gắng tạo mã thông báo mà không có customerId, mọi thứ hoạt động tốt (mặc dù tôi không bao giờ nhận được mã thông báo khách hàng mới nhưng đó là một câu hỏi khác).
EDIT: Đây là mã thử nghiệm hoàn chỉnh theo yêu cầu:
var http = require('http'),
url=require('url'),
fs=require('fs'),
braintree=require('braintree');
var clientToken;
var gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: "xxx", //Real ID and Keys removed
publicKey: "xxx",
privateKey: "xxx"
});
gateway.clientToken.generate({
customerId: "aCustomerId" //I've tried declaring this outside this block
}, function (err, response) {
clientToken = response.clientToken
});
http.createServer(function(req,res){
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(clientToken);
res.end("<p>This is the end</p>");
}).listen(8000, '127.0.0.1');
bạn có thể cung cấp một chút bối cảnh nhiều hơn xung quanh mã bạn đang sử dụng? –