Javascript 如何在NodeJS中设置Braintree API?
我想使用braintree作为网站paymentgateway,不幸的是,当我在线遵循指南时,代码无法在NodeJS中使用。少了什么吗 Index.js:Javascript 如何在NodeJS中设置Braintree API?,javascript,node.js,express,braintree,Javascript,Node.js,Express,Braintree,我想使用braintree作为网站paymentgateway,不幸的是,当我在线遵循指南时,代码无法在NodeJS中使用。少了什么吗 Index.js: //send token to clients app.get("/client_token", function (req, res) { gateway.clientToken.generate({}, function (err, response) { res.send(response.client
//send token to clients
app.get("/client_token", function (req, res) {
gateway.clientToken.generate({}, function (err, response) {
res.send(response.clientToken);
});
});
//Receive payment from clients
app.post("/checkout", function (req, res) {
var nonceFromTheClient = req.body.payment_method_nonce;
// Use payment method nonce here
});
//Test sandbox
gateway.transaction.sale({
amount: "10.00",
paymentMethodNonce: nonceFromTheClient,
options: {
submitForSettlement: true
}
}, function (err, result) {
if (err) {
console.error(err);
return;
}
if (result.success) {
console.log('Transaction ID: ' + result.transaction.id);
} else {
console.error(result.message);
}
});
错误:无法传递节点js npm start:
支付方式nonce:nonefromtheclient,
IDE中的详细信息:
引用错误:未定义非引用客户端
at Object.<anonymous> (/Users/desmondkam/codecampvn/index.js:37:23)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:160:18)
at node.js:445:3
您的代码是:
gateway.transaction.sale({
amount: "10.00",
paymentMethodNonce: "fake-valid-nonce",
options: {
submitForSettlement: true
}
}, function (err, result) {
});
你已经在路由器中定义了
非EFROM客户端
,这就是为什么你的沙盘中出现了未定义的错误。对了,我明白你的意思了。
gateway.transaction.sale({
amount: "10.00",
paymentMethodNonce: "fake-valid-nonce",
options: {
submitForSettlement: true
}
}, function (err, result) {
});