diff --git a/mongoDB.js b/mongoDB.js index 98e5f33..16adc0a 100644 --- a/mongoDB.js +++ b/mongoDB.js @@ -52,9 +52,11 @@ const getDB = new Promise((resolve, reject) => { let usernamesCache = {} DB.getUsernameByIdCache = async (userid)=>{ + if(!userid) return {}; if(usernamesCache[userid]) return usernamesCache[userid]; const _id = new mongo.ObjectID(userid); let user = await DB.usersCol.findOne({ _id }); + if(!user) return ''; usernamesCache[userid] = user.username; return usernamesCache[userid]; } diff --git a/routes/payments.js b/routes/payments.js index b8f8cee..504c85a 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -40,12 +40,13 @@ DB.getDB.then((DB) => { router.post("/create-payment-intent", async (req, res) => { - const { items } = req.body; - console.log("payments", req.body) + const userid = req.body.userid; + const price = req.body.price || 500; + console.log(req.body) // Create a PaymentIntent with the order amount and currency const paymentIntent = await stripe.paymentIntents.create({ - amount: 500, + amount: price, currency: "usd", payment_method_types: [ "card", @@ -54,7 +55,8 @@ DB.getDB.then((DB) => { res.send({ clientSecret: paymentIntent.client_secret, - email: await DB.getUsernameByIdCache(req.body.userid) + email: await DB.getUsernameByIdCache(req.body.userid), + price }); });