I'm using braintree in application. some time ago it worked without any problem. now it doesn't always work and when it doesn't. I get this error on console: ValidationErrorsCollection.
Node.js code
const gateway = new braintree.BraintreeGateway({
environment: braintree.Environment.Sandbox,
merchantId: process.env.BRAINTREE_MERCHANT_ID,
publicKey: process.env.BRAINTREE_PUBLIC_KEY,
privateKey: process.env.BRAINTREE_PRIVATE_KEY
});
exports.generateToken = (req, res) => {
gateway.clientToken.generate({}, function(err, response) {
//Se verdade vamos trazer o token
if(err){
res.status(500).send(err)
}else{
res.send(response)
}
});
};
exports.processPayment = (req, res) => {
let nonceFromTheClient = req.body.paymentMethodNonce
let amountFromTheClient = req.body.amount
//charge
let newTransaction = gateway.transaction.sale({
amount: amountFromTheClient,
paymentMethodNonce: nonceFromTheClient,
options: {
submitForSettlement: true
}
}).then(function (result) {
if (result.success) {
res.json(result);
} else {
console.log(result.errors)
//res.status(500).json(error);
}
}).catch(function (err) {
console.error(err);
});
}
Top comments (0)