I want use braintree for website paymentgateway, unfortunately when I follow the guideline online, & the code unable to be use in node js. Is anything missing?
Index.js:
//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);
}
});
Error unable pass the node js npm start:
paymentMethodNonce: nonceFromTheClient,
Details in IDE:
ReferenceError: nonceFromTheClient is not defined
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
via Kimson101
No comments:
Post a Comment