hello, I have registered a user connected in his account after payment of a video tutorial that is proposed to him now I want when he connects and he clicks on a button he goes to the video tutorial
here are the codes
const postCharge = async (req, res) =>{
console.log(req.body);
const email = req.body.stripeEmail
const source = req.body.stripeToken
// const name = req.body.name
const savePayment = new Payment({
nomid: req.user.id,
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))
}
/********
**oddly, when I connect with a new user, without buying the tutorial he accessed the page or the button.**
**I think I have a problem with this**
*******/
const getPass = (req, res) =>{
const nomId = req.user.id
Payment.findOne({nomId}, function (err, docs) {
if (err){
console.log(err)
}
else{
res.render('tutorial', {docs: docs})
}
});
}
/PAGE NAVBAR/
<button class="btn btn-info my-2 my-sm-0 m-3">
<a class="nav-link text-white " href="/tutorial/<%= id %>">
Access aux Cours
</a>
</button>