我已经根据Braintree的文档实现了它,但在终端上遇到了这个错误。 它显示braintree.connect不是一个函数,但在文档中已经提供了硬编码。
var gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: "useYourMerchantId",
publicKey: "useYourPublicKey",
privateKey: "useYourPrivateKey"
});
这是我的代码!
const { response } = require("express");
var gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: "useYourMerchantId",
publicKey: "useYourPublicKey",
privateKey: "useYourPrivateKey"
});
exports.getToken = (req,res) => {
gateway.clientToken.generate({}, function (err, response) {
if(err){
res.status(500).json(err)
}else{
res.send(response)
}
});
}
exports.processPayment = (req,res) => {
let nonceFromTheClient = req.body.paymentMethodNonce
let amountFromTheClient = req.body.amount
gateway.transaction.sale({
amount: amountFromTheClient,
paymentMethodNonce: nonceFromTheClient,
options: {
submitForSettlement: true
}
}, function (err, result) {
if (err) {
res.status(500).json(error)
}else{
res.json(result);
}
});
}