mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-13 08:48:38 +01:00
implementing new payment system + rewrite deploy scripts
This commit is contained in:
@@ -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' });
|
||||
|
||||
Reference in New Issue
Block a user