Record Payments Intents

This commit is contained in:
aeroreyna
2022-01-23 20:16:50 -08:00
parent f147bf70fd
commit cb056a078a
3 changed files with 59 additions and 7 deletions

22
dbTools/payments.js Normal file
View File

@@ -0,0 +1,22 @@
const DBName = "EMI_SOCIAL";
postDB = (DB)=>{
DB.paymentsCols = DB.db.db(DBName).collection("payments");
DB.newIntent = (intent) => {
return DB.paymentsCols.insertOne(intent).catch((err)=>{
console.log(err);
return false;
});
}
DB.newResult = (paymentResult) => {
return DB.paymentsCols.insertOne(paymentResult).catch((err)=>{
console.log(err);
return false;
});
}
}
module.exports = postDB;

View File

@@ -5,6 +5,7 @@ const DBName = "EMI_SOCIAL";
const mongoUrl = process.env.MONGO_URL; const mongoUrl = process.env.MONGO_URL;
const postDB = require("./dbTools/post.js"); const postDB = require("./dbTools/post.js");
const profileDB = require("./dbTools/profile.js"); const profileDB = require("./dbTools/profile.js");
const paymentDB = require("./dbTools/payments.js")
const getDB = new Promise((resolve, reject) => { const getDB = new Promise((resolve, reject) => {
@@ -107,6 +108,7 @@ const getDB = new Promise((resolve, reject) => {
postDB(DB); postDB(DB);
profileDB(DB); profileDB(DB);
paymentDB(DB);
resolve(DB); resolve(DB);
}); });

View File

@@ -1,5 +1,5 @@
var express = require('express') var express = require('express');
var router = express.Router() var router = express.Router();
const DB = require("../mongoDB.js"); const DB = require("../mongoDB.js");
//const Payments = require("../payments.js"); //const Payments = require("../payments.js");
@@ -38,11 +38,10 @@ DB.getDB.then((DB) => {
// }); // });
// }); // });
let intent = async (req, res) => {
router.post("/create-payment-intent", async (req, res) => {
const userid = req.body.userid; const userid = req.body.userid;
const price = req.body.price || 500; const price = req.body.price || 500;
console.log(req.body) const description = req.body.description;
// 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({
@@ -53,11 +52,40 @@ DB.getDB.then((DB) => {
], ],
}); });
res.send({ //Register in DB
const intent = {
paymentIntent,
userid,
price,
description
};
DB.newIntent(intent);
return res.send({
clientSecret: paymentIntent.client_secret, clientSecret: paymentIntent.client_secret,
email: await DB.getUsernameByIdCache(req.body.userid), email: await DB.getUsernameByIdCache(userid),
price price
}); });
};
router.post("/create-payment-intent", intent);
router.post("/intent", intent);
router.post("/register", async (req, res) => {
const userid = req.body.userid;
const result = req.body.result;
//Register in DB
const payment = {
result,
userid
};
DB.newResult(payment);
return res.send({
status: 'ok'
});
}); });