Record Payments Intents
This commit is contained in:
22
dbTools/payments.js
Normal file
22
dbTools/payments.js
Normal 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;
|
||||
@@ -5,6 +5,7 @@ const DBName = "EMI_SOCIAL";
|
||||
const mongoUrl = process.env.MONGO_URL;
|
||||
const postDB = require("./dbTools/post.js");
|
||||
const profileDB = require("./dbTools/profile.js");
|
||||
const paymentDB = require("./dbTools/payments.js")
|
||||
|
||||
|
||||
const getDB = new Promise((resolve, reject) => {
|
||||
@@ -107,6 +108,7 @@ const getDB = new Promise((resolve, reject) => {
|
||||
|
||||
postDB(DB);
|
||||
profileDB(DB);
|
||||
paymentDB(DB);
|
||||
|
||||
resolve(DB);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var express = require('express')
|
||||
var router = express.Router()
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
const DB = require("../mongoDB.js");
|
||||
//const Payments = require("../payments.js");
|
||||
@@ -37,12 +37,11 @@ DB.getDB.then((DB) => {
|
||||
// status: "ok",
|
||||
// });
|
||||
// });
|
||||
|
||||
|
||||
router.post("/create-payment-intent", async (req, res) => {
|
||||
let intent = async (req, res) => {
|
||||
const userid = req.body.userid;
|
||||
const price = req.body.price || 500;
|
||||
console.log(req.body)
|
||||
const description = req.body.description;
|
||||
|
||||
// Create a PaymentIntent with the order amount and currency
|
||||
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,
|
||||
email: await DB.getUsernameByIdCache(req.body.userid),
|
||||
email: await DB.getUsernameByIdCache(userid),
|
||||
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'
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user