mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
fix dashboard + payments
This commit is contained in:
@@ -1,38 +1,38 @@
|
||||
import { getPlanFromId } from "@data/PREMIUM";
|
||||
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
||||
import StripeService from '~/server/services/StripeService';
|
||||
// import StripeService from '~/server/services/StripeService';
|
||||
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const data = await getRequestDataOld(event, { requireSchema: false, allowGuests: false, allowLitlyx: false });
|
||||
if (!data) return;
|
||||
// const data = await getRequestDataOld(event, { requireSchema: false, allowGuests: false, allowLitlyx: false });
|
||||
// if (!data) return;
|
||||
|
||||
const { project, pid } = data;
|
||||
// const { project, pid } = data;
|
||||
|
||||
const body = await readBody(event);
|
||||
// const body = await readBody(event);
|
||||
|
||||
const { planId } = body;
|
||||
// const { planId } = body;
|
||||
|
||||
const PLAN = getPlanFromId(planId);
|
||||
// const PLAN = getPlanFromId(planId);
|
||||
|
||||
if (!PLAN) {
|
||||
console.error('PLAN', planId, 'NOT EXIST');
|
||||
return setResponseStatus(event, 400, 'Plan not exist');
|
||||
}
|
||||
// if (!PLAN) {
|
||||
// console.error('PLAN', planId, 'NOT EXIST');
|
||||
// return setResponseStatus(event, 400, 'Plan not exist');
|
||||
// }
|
||||
|
||||
const intent = await StripeService.createOnetimePayment(
|
||||
StripeService.testMode ? PLAN.PRICE_TEST : PLAN.PRICE,
|
||||
'https://dashboard.litlyx.com/payment_ok',
|
||||
pid,
|
||||
project.customer_id
|
||||
)
|
||||
// const intent = await StripeService.createOnetimePayment(
|
||||
// StripeService.testMode ? PLAN.PRICE_TEST : PLAN.PRICE,
|
||||
// 'https://dashboard.litlyx.com/payment_ok',
|
||||
// pid,
|
||||
// project.customer_id
|
||||
// )
|
||||
|
||||
if (!intent) {
|
||||
console.error('Cannot create Intent', { plan: PLAN });
|
||||
return setResponseStatus(event, 400, 'Cannot create intent');
|
||||
}
|
||||
// if (!intent) {
|
||||
// console.error('Cannot create Intent', { plan: PLAN });
|
||||
// return setResponseStatus(event, 400, 'Cannot create intent');
|
||||
// }
|
||||
|
||||
return intent.url;
|
||||
// return intent.url;
|
||||
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getPlanFromId } from "@data/PREMIUM";
|
||||
import StripeService from '~/server/services/StripeService';
|
||||
// import StripeService from '~/server/services/StripeService';
|
||||
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
@@ -9,29 +9,30 @@ export default defineEventHandler(async event => {
|
||||
|
||||
const { project, pid } = data;
|
||||
|
||||
const body = await readBody(event);
|
||||
// const body = await readBody(event);
|
||||
|
||||
const { planId } = body;
|
||||
// const { planId } = body;
|
||||
|
||||
const PLAN = getPlanFromId(planId);
|
||||
// const PLAN = getPlanFromId(planId);
|
||||
|
||||
if (!PLAN) {
|
||||
console.error('PLAN', planId, 'NOT EXIST');
|
||||
return setResponseStatus(event, 400, 'Plan not exist');
|
||||
}
|
||||
// if (!PLAN) {
|
||||
// console.error('PLAN', planId, 'NOT EXIST');
|
||||
// return setResponseStatus(event, 400, 'Plan not exist');
|
||||
// }
|
||||
|
||||
const checkout = await StripeService.createPayment(
|
||||
StripeService.testMode ? PLAN.PRICE_TEST : PLAN.PRICE,
|
||||
'https://dashboard.litlyx.com/payment_ok',
|
||||
pid,
|
||||
project.customer_id
|
||||
);
|
||||
// const checkout = await StripeService.createPayment(
|
||||
// StripeService.testMode ? PLAN.PRICE_TEST : PLAN.PRICE,
|
||||
// 'https://dashboard.litlyx.com/payment_ok',
|
||||
// pid,
|
||||
// project.customer_id
|
||||
// );
|
||||
|
||||
if (!checkout) {
|
||||
console.error('Cannot create payment', { plan: PLAN });
|
||||
return setResponseStatus(event, 400, 'Cannot create payment');
|
||||
}
|
||||
// if (!checkout) {
|
||||
// console.error('Cannot create payment', { plan: PLAN });
|
||||
// return setResponseStatus(event, 400, 'Cannot create payment');
|
||||
// }
|
||||
|
||||
return checkout.url;
|
||||
// return checkout.url;
|
||||
return '';
|
||||
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
import StripeService from '~/server/services/StripeService';
|
||||
import { PaymentServiceHelper } from '~/server/services/PaymentServiceHelper';
|
||||
import { PremiumModel } from '~/shared/schema/PremiumSchema';
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
@@ -10,9 +10,9 @@ export default defineEventHandler(async event => {
|
||||
const premium = await PremiumModel.findOne({ user_id: data.user.id })
|
||||
if (!premium) return;
|
||||
|
||||
const customer = await StripeService.getCustomer(premium.customer_id);
|
||||
if (customer?.deleted) return;
|
||||
const [ok, customerInfoOrError] = await PaymentServiceHelper.customer_info(data.user.id);
|
||||
if (!ok) throw customerInfoOrError;
|
||||
|
||||
return customer?.address;
|
||||
return customerInfoOrError;
|
||||
|
||||
});
|
||||
@@ -1,9 +1,7 @@
|
||||
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
||||
import { Redis } from "~/server/services/CacheService";
|
||||
import StripeService from '~/server/services/StripeService';
|
||||
import { PaymentServiceHelper } from "~/server/services/PaymentServiceHelper";
|
||||
import { PremiumModel } from "~/shared/schema/PremiumSchema";
|
||||
|
||||
|
||||
export type InvoiceData = {
|
||||
date: number,
|
||||
cost: number,
|
||||
@@ -21,11 +19,14 @@ export default defineEventHandler(async event => {
|
||||
|
||||
const premium = await PremiumModel.findOne({ user_id: data.user.id });
|
||||
if (!premium) return [];
|
||||
|
||||
const invoices = await StripeService.getInvoices(premium.customer_id);
|
||||
if (!invoices) return [];
|
||||
|
||||
return invoices?.data.map(e => {
|
||||
const [ok, invoicesOrError] = await PaymentServiceHelper.invoices_list(data.user.id);
|
||||
if (!ok) {
|
||||
console.error(invoicesOrError);
|
||||
return [];
|
||||
}
|
||||
|
||||
return invoicesOrError.invoices.map(e => {
|
||||
const result: InvoiceData = {
|
||||
link: e.invoice_pdf || '',
|
||||
id: e.number || '',
|
||||
@@ -36,7 +37,6 @@ export default defineEventHandler(async event => {
|
||||
return result;
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getPlanFromId, PREMIUM_PLAN } from "@data/PREMIUM";
|
||||
import { canTryAppsumoCode, checkAppsumoCode, useAppsumoCode, useTryAppsumoCode } from "~/server/services/AppsumoService";
|
||||
import StripeService from '~/server/services/StripeService';
|
||||
|
||||
|
||||
function getPlanToActivate(current_plan_id: number) {
|
||||
if (current_plan_id === PREMIUM_PLAN.FREE.ID) {
|
||||
@@ -38,13 +38,13 @@ export default defineEventHandler(async event => {
|
||||
const valid = await checkAppsumoCode(code);
|
||||
if (!valid) return setResponseStatus(event, 400, 'Code not valid');
|
||||
|
||||
const currentPlan = getPlanFromId(project.premium_type);
|
||||
if (!currentPlan) return setResponseStatus(event, 400, 'Current plan not found');
|
||||
const planToActivate = getPlanToActivate(currentPlan.ID);
|
||||
if (!planToActivate) return setResponseStatus(event, 400, 'Cannot use code on current plan');
|
||||
// const currentPlan = getPlanFromId(project.premium_type);
|
||||
// if (!currentPlan) return setResponseStatus(event, 400, 'Current plan not found');
|
||||
// const planToActivate = getPlanToActivate(currentPlan.ID);
|
||||
// if (!planToActivate) return setResponseStatus(event, 400, 'Cannot use code on current plan');
|
||||
|
||||
await StripeService.createSubscription(project.customer_id, planToActivate.ID);
|
||||
// await StripeService.createSubscription(project.customer_id, planToActivate.ID);
|
||||
|
||||
await useAppsumoCode(pid, code);
|
||||
// await useAppsumoCode(pid, code);
|
||||
|
||||
});
|
||||
@@ -1,19 +1,17 @@
|
||||
import { getUserProjectFromId } from "~/server/LIVE_DEMO_DATA";
|
||||
import StripeService from '~/server/services/StripeService';
|
||||
|
||||
import { PaymentServiceHelper } from '~/server/services/PaymentServiceHelper';
|
||||
import { PremiumModel } from '~/shared/schema/PremiumSchema';
|
||||
|
||||
export default defineEventHandler(async event => {
|
||||
|
||||
const data = await getRequestData(event, []);
|
||||
if (!data) return;
|
||||
|
||||
const { project } = data;
|
||||
|
||||
if (!project.customer_id) return setResponseStatus(event, 400, 'Project has no customer_id');
|
||||
const premium = await PremiumModel.findOne({ user_id: data.user.id })
|
||||
if (!premium) return;
|
||||
|
||||
const body = await readBody(event);
|
||||
const res = await StripeService.setCustomerInfo(project.customer_id, body);
|
||||
|
||||
return { ok: true, data: res }
|
||||
return await PaymentServiceHelper.update_customer_info(data.user.id, body);
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user