I created a registration page for the user to have their own account and a login page for them to log in. Now, after the user is logged in, I submit a video tutorial payable with Stripe. What I wanted was after purchasing this course with Stripe. The tutorial automatically unlocks for the user.
here is my code with Stripe. I tested it and it works great.
const postCharge = (req, res) =>{
console.log(req.body);
const email = req.body.stripeEmail
const source = req.body.stripeToken
const savePayment = new Payment({
email: email,
source: source
})
/*** */
savePayment.save((err, userPayment) =>{
if(err) console.log(err);
})
/*** */
stripe.customers.create({
email: email,
source: source
})
.then(customer => stripe.charges.create({
amount: 2500,
currency: "usd",
customer: customer.id
}))
.then(() => res.render('success'))
.catch((error) => console.log(error))
}
I want to save somewhere that user now has access to the tutorial (eg in MongoDB if you are using it)
s soon as he clicks he goes directly to the tutorial now unlocked thanks to the payment
<button class=“btn btn-info my-2 my-sm-0 m-3”> <a class=“nav-link text-white " href=”/Tuto"> Access aux Cours </a> </button>
But his link doesn’t work if he pays