My goal is to generate a transaction sale while generating the customer id so that I could store the customer id to the database
The reason why i need customer id is because so that the same user doesn't need to enter his credit/debit card again
const gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: '',
publicKey: '',
privateKey: ''
});
app.post('/payment', (req, res, next) => {
gateway.transaction.sale({
amount: req.body.amount,
paymentMethodNonce: req.body.nonce,
options: {
submitForSettlement: true
}
}, function (err, result) {
if (err) {
res.json(err)
}
if (result.success) {
console.log('Transaction ID: ' + result.transaction.id);
res.json({
transactionId: result.transaction.id
})
} else {
console.error(result.message);
}
});
});