I've implemented a braintree using its documentation but, facing this error in the terminal. it's showing that braintree.connect is not a function, but in the documentation it has been provided hard coded.
var gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: "useYourMerchantId",
publicKey: "useYourPublicKey",
privateKey: "useYourPrivateKey"
});
Here is my code!
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);
}
});
}
They have changed the process and I think forgot to update their official documentation. Here is the new way to initialise Braintree in nodejs mentioned on their github repo.
var gateway = new braintree.BraintreeGateway({
environment: braintree.Environment.Sandbox,
merchantId: 'your_merchant_id',
publicKey: 'your_public_key',
privateKey: 'your_private_key'
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With