Skip to content

Instantly share code, notes, and snippets.

@simonho288
Created July 2, 2020 20:41
Show Gist options
  • Select an option

  • Save simonho288/ff92fcdca977107adbdfd02e88a3641f to your computer and use it in GitHub Desktop.

Select an option

Save simonho288/ff92fcdca977107adbdfd02e88a3641f to your computer and use it in GitHub Desktop.
router.get('/charge/:token', (req, res) => {
let token = req.params.token
console.assert(token)
const amount = CHARGE_AMOUNT * 100
stripe.charges.create({
amount: amount,
currency: 'usd',
source: token,
description: 'Stripe experiment testing charge'
}, (err, charge) => {
if (err) {
res.redirect('/stripe/payment-failure?err_msg=' + err.message)
} else {
console.log('charge', charge)
if (charge.outcome && charge.outcome.risk_level != 'normal') {
res.redirect('/stripe/payment-warning?charge_id=' + charge.id + '&msg=' + charge.outcome.seller_message)
} else {
res.redirect('/stripe/payment-success/' + charge.id)
}
}
})
})
router.post('/charge', (req, res) => {
let token = req.body.stripeToken
console.assert(token)
const amount = CHARGE_AMOUNT * 100
stripe.charges.create({
amount: amount,
currency: 'usd',
source: token,
description: 'Stripe experiment testing charge'
}, (err, charge) => {
if (err) {
res.redirect('/stripe/payment-failure?err_msg=' + err.message)
} else {
console.log('Charged successful')
console.log('charge', charge)
res.redirect('/stripe/payment-success/' + charge.id)
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment