Skip to content

Instantly share code, notes, and snippets.

@Franckapik
Created August 27, 2019 19:42
Show Gist options
  • Save Franckapik/34876ea57372f8d95e051093d733fddc to your computer and use it in GitHub Desktop.
Save Franckapik/34876ea57372f8d95e051093d733fddc to your computer and use it in GitHub Desktop.
const makeTransaction = (amount, nonceFromTheClient) => {
gateway.transaction.sale({
amount: amount,
paymentMethodNonce: nonceFromTheClient,
options: {
submitForSettlement: true
}
}, function(err, result) {
if (result.success) {
logger.info('[Braintree] Nouvelle transaction: %s', result.transaction.id);
knex('commande')
.insert({
userid: req.sessionID,
status: result.transaction.status,
mode: result.transaction.paymentInstrumentType,
amount: result.transaction.amount,
cardtype: result.transaction.creditCard.cardType,
number: result.transaction.creditCard.maskedNumber,
expirationdate: result.transaction.creditCard.expirationDate,
transactionid: result.transaction.id
})
.returning('transactionid')
.then(transactionid => {
logger.info('[Braintree db] Transaction enregistrée: %s', transactionid);
res.send(transactionid)
}).catch((error) => logger.error('[Braintree db] Transaction non enregistrée %s', error));
} else {
logger.error('[Braintree] Erreur de transaction: %s', result.message);
res.sendStatus(500);
}
});
};
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment