Created
July 2, 2020 20:41
-
-
Save simonho288/ff92fcdca977107adbdfd02e88a3641f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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