Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- });
- //payment route
- router.post('/billing/:plan_name', function(req, res, next) {
- var plan = req.params.plan_name;
- var stripeToken = req.body.stripeToken;
- console.log(stripeToken);
- if (!stripeToken) {
- req.flash('errors', { msg: 'Please provide a valid card.' });
- return res.redirect('/awesome');
- }
- User.findById({ _id: req.user._id}, function(err, user) {
- if (err) return next(err);
- stripe.customers.create({
- source: stripeToken, // obtained with Stripe.js
- plan: plan,
- email: user.email
- }).then(function(customer) {
- user.stripe.plan = customer.plan;
- user.stripe.customerId = customer.id;
- console.log(customer);
- user.save(function(err) {
- console.log("Success");
- if (err) return next(err);
- return next(null);
- });
- }).catch(function(err) {
- // Deal with an error
- });
- return res.redirect('/');
- });
- });
- router.post('/billing/catch_paid_invoice', function(req, res) {
- // Here you parse JSON data from Stripe
- }):
- If today's date <= user.active_until
- allow them access
- Else
- show them an account expired message
- if event type is "invoice.payment_succeeded"
- then update user.active_until to be equal to today's date + 1 month
Add Comment
Please, Sign In to add comment