Currently, I have this code block which is the back-end for my Stripe setup. On the callback function, I'm setting a variable equal to the amount that gets charged to the user's card. I then want to send this value into another route file so that I can res.send() the amount into the browser.
When I try to do this, the variable somehow gets set to undefined from point a to point b.
router.post('/charge', function(req, res, next) {
var token = req.body.stripeToken;
var chargeAmount = req.body.amount[0];
var charge = stripe.charges.create({
amount: chargeAmount,
currency: "usd",
source: token
}, function(err, charge) {
if(err) {
return console.log(err);
}
module.exports.theAmount = charge.amount;
res.redirect('/users/dashboard');
});
});
module.exports = router;
Here's the code from the route file that I'm trying to get the charge amount into:
var stripeFile = require('stripe');
router.get('/dashboard', isLoggedIn, function(req, res, next) {
var messages = req.flash('error');
res.render('users/dashboard', {messages: messages, hasErrors: messages.length > 0});
console.log(stripeFile.theAmount);
});
via kolbykskk
No comments:
Post a Comment