implementing new payment system + rewrite deploy scripts

This commit is contained in:
Emily
2025-03-28 16:57:57 +01:00
parent 7658dbe85c
commit 7e093251fa
14 changed files with 265 additions and 124 deletions

View File

@@ -3,13 +3,13 @@ import z from 'zod';
import { getPlanFromId } from '../shared/data/PLANS';
import StripeService from '../services/StripeService';
import { sendJson } from '../Utils';
import { ProjectModel } from '../shared/schema/project/ProjectSchema';
import { PremiumModel } from '../shared/schema/PremiumSchema';
export const paymentRouter = Router();
export const ZBodyCreatePayment = z.object({
pid: z.string(),
user_id: z.string(),
plan_id: z.number()
})
@@ -20,17 +20,17 @@ paymentRouter.post('/create', json(), async (req, res) => {
const plan = getPlanFromId(createPaymentData.plan_id);
if (!plan) return sendJson(res, 400, { error: 'plan not found' });
const project = await ProjectModel.findById(createPaymentData.pid);
if (!project) return sendJson(res, 400, { error: 'project not found' });
if (!project.customer_id) return sendJson(res, 400, { error: 'project have no customer_id' });
const premiumData = await PremiumModel.findById(createPaymentData.user_id);
if (!premiumData) return sendJson(res, 400, { error: 'user not found' });
if (!premiumData.customer_id) return sendJson(res, 400, { error: 'user have no customer_id' });
const price = StripeService.testMode ? plan.PRICE_TEST : plan.PRICE;
const checkout = await StripeService.createPayment(
price,
'https://dashboard.litlyx.com/payment_ok',
createPaymentData.pid,
project.customer_id
createPaymentData.user_id,
premiumData.customer_id
);
if (!checkout) return sendJson(res, 400, { error: 'cannot create payment' });