custom amount payments
This commit is contained in:
@@ -52,9 +52,11 @@ const getDB = new Promise((resolve, reject) => {
|
|||||||
|
|
||||||
let usernamesCache = {}
|
let usernamesCache = {}
|
||||||
DB.getUsernameByIdCache = async (userid)=>{
|
DB.getUsernameByIdCache = async (userid)=>{
|
||||||
|
if(!userid) return {};
|
||||||
if(usernamesCache[userid]) return usernamesCache[userid];
|
if(usernamesCache[userid]) return usernamesCache[userid];
|
||||||
const _id = new mongo.ObjectID(userid);
|
const _id = new mongo.ObjectID(userid);
|
||||||
let user = await DB.usersCol.findOne({ _id });
|
let user = await DB.usersCol.findOne({ _id });
|
||||||
|
if(!user) return '';
|
||||||
usernamesCache[userid] = user.username;
|
usernamesCache[userid] = user.username;
|
||||||
return usernamesCache[userid];
|
return usernamesCache[userid];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,12 +40,13 @@ DB.getDB.then((DB) => {
|
|||||||
|
|
||||||
|
|
||||||
router.post("/create-payment-intent", async (req, res) => {
|
router.post("/create-payment-intent", async (req, res) => {
|
||||||
const { items } = req.body;
|
const userid = req.body.userid;
|
||||||
console.log("payments", req.body)
|
const price = req.body.price || 500;
|
||||||
|
console.log(req.body)
|
||||||
|
|
||||||
// Create a PaymentIntent with the order amount and currency
|
// Create a PaymentIntent with the order amount and currency
|
||||||
const paymentIntent = await stripe.paymentIntents.create({
|
const paymentIntent = await stripe.paymentIntents.create({
|
||||||
amount: 500,
|
amount: price,
|
||||||
currency: "usd",
|
currency: "usd",
|
||||||
payment_method_types: [
|
payment_method_types: [
|
||||||
"card",
|
"card",
|
||||||
@@ -54,7 +55,8 @@ DB.getDB.then((DB) => {
|
|||||||
|
|
||||||
res.send({
|
res.send({
|
||||||
clientSecret: paymentIntent.client_secret,
|
clientSecret: paymentIntent.client_secret,
|
||||||
email: await DB.getUsernameByIdCache(req.body.userid)
|
email: await DB.getUsernameByIdCache(req.body.userid),
|
||||||
|
price
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user