mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 15:58:38 +01:00
add pricing
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { PREMIUM_PLANS, STRIPE_PLANS } from "@data/PREMIUM_LIMITS";
|
||||
import { ProjectModel } from "@schema/ProjectSchema";
|
||||
import { getPlanFromId } from "@data/PREMIUM";
|
||||
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
||||
import StripeService from '~/server/services/StripeService';
|
||||
|
||||
@@ -17,24 +16,22 @@ export default defineEventHandler(async event => {
|
||||
|
||||
const { planId } = body;
|
||||
|
||||
const plan = PREMIUM_PLANS.find(e => e.id == planId);
|
||||
const PLAN = getPlanFromId(planId);
|
||||
|
||||
if (!plan) {
|
||||
if (!PLAN) {
|
||||
console.error('PLAN', planId, 'NOT EXIST');
|
||||
return setResponseStatus(event, 400, 'Plan not exist');
|
||||
}
|
||||
|
||||
const { price } = STRIPE_PLANS[plan.tag];
|
||||
|
||||
const checkout = await StripeService.cretePayment(
|
||||
price,
|
||||
PLAN.PRICE,
|
||||
'https://dashboard.litlyx.com/payment_ok',
|
||||
project_id,
|
||||
project.customer_id
|
||||
);
|
||||
|
||||
if (!checkout) {
|
||||
console.error('Cannot create payment', { plan, price });
|
||||
console.error('Cannot create payment', { plan: PLAN });
|
||||
return setResponseStatus(event, 400, 'Cannot create payment');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
||||
import { Redis } from "~/server/services/CacheService";
|
||||
import StripeService from '~/server/services/StripeService';
|
||||
|
||||
|
||||
@@ -21,17 +22,21 @@ export default defineEventHandler(async event => {
|
||||
|
||||
if (!project.customer_id) return [];
|
||||
|
||||
const invoices = await StripeService.getInvoices(project.customer_id);
|
||||
return await Redis.useCache({ key: `invoices:${project_id}`, exp: 10 }, async () => {
|
||||
|
||||
return invoices?.data.map(e => {
|
||||
const result: InvoiceData = {
|
||||
link: e.invoice_pdf || '',
|
||||
id: e.number || '',
|
||||
date: e.created * 1000,
|
||||
status: e.status || 'NO_STATUS',
|
||||
cost: e.amount_due
|
||||
}
|
||||
return result;
|
||||
})
|
||||
const invoices = await StripeService.getInvoices(project.customer_id);
|
||||
|
||||
return invoices?.data.map(e => {
|
||||
const result: InvoiceData = {
|
||||
link: e.invoice_pdf || '',
|
||||
id: e.number || '',
|
||||
date: e.created * 1000,
|
||||
status: e.status || 'NO_STATUS',
|
||||
cost: e.amount_due
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user