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

View File

@@ -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'
});
});