From 6a157b81c9bfd083f3ce61a56a5effeee4981e06 Mon Sep 17 00:00:00 2001 From: Emily Date: Fri, 25 Apr 2025 19:20:13 +0200 Subject: [PATCH] fix --- dashboard/components/FirstInteraction.vue | 2 +- dashboard/pages/payment_ok.vue | 2 +- dashboard/server/api/pay/create.post.ts | 38 ++++++++----------- .../server/services/PaymentServiceHelper.ts | 5 ++- payments/src/routers/PaymentRouter.ts | 2 +- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/dashboard/components/FirstInteraction.vue b/dashboard/components/FirstInteraction.vue index 99a9d59..5aa6fcd 100644 --- a/dashboard/components/FirstInteraction.vue +++ b/dashboard/components/FirstInteraction.vue @@ -203,7 +203,7 @@ function reloadPage() {
diff --git a/dashboard/pages/payment_ok.vue b/dashboard/pages/payment_ok.vue index ce2a699..b29fa4d 100644 --- a/dashboard/pages/payment_ok.vue +++ b/dashboard/pages/payment_ok.vue @@ -17,7 +17,7 @@ definePageMeta({ layout: 'none' });
- We hope Lilyx can help you make better metrics-driven decision to help your business. + We hope Litlyx can help you make better metrics-driven decision to help your business.
diff --git a/dashboard/server/api/pay/create.post.ts b/dashboard/server/api/pay/create.post.ts index 9dcf0bd..256b039 100644 --- a/dashboard/server/api/pay/create.post.ts +++ b/dashboard/server/api/pay/create.post.ts @@ -1,38 +1,32 @@ import { getPlanFromId } from "@data/PLANS"; +import { PaymentServiceHelper } from "~/server/services/PaymentServiceHelper"; // import StripeService from '~/server/services/StripeService'; export default defineEventHandler(async event => { - const data = await getRequestDataOld(event, { requireSchema: false, allowGuests: false, allowLitlyx: false }); + const data = await getRequestData(event, [], []); if (!data) return; - const { project, pid } = data; + const { project, pid, user } = 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 [ok, res] = await PaymentServiceHelper.create_payment(user.id, PLAN.ID); - // const checkout = await StripeService.createPayment( - // StripeService.testMode ? PLAN.PRICE_TEST : PLAN.PRICE, - // 'https://dashboard.litlyx.com/payment_ok', - // pid, - // project.customer_id - // ); + if (!ok) { + console.error('Cannot create payment', { plan: PLAN }); + return setResponseStatus(event, 400, res.message ?? 'Cannot create payment'); + } - // if (!checkout) { - // console.error('Cannot create payment', { plan: PLAN }); - // return setResponseStatus(event, 400, 'Cannot create payment'); - // } - - // return checkout.url; - return ''; + return res.url; }); \ No newline at end of file diff --git a/dashboard/server/services/PaymentServiceHelper.ts b/dashboard/server/services/PaymentServiceHelper.ts index 5067db2..1bd2fbb 100644 --- a/dashboard/server/services/PaymentServiceHelper.ts +++ b/dashboard/server/services/PaymentServiceHelper.ts @@ -8,7 +8,7 @@ type PaymentServiceResponse = Promise | ErrorResponse> export class PaymentServiceHelper { - static BASE_URL = 'https://test-payments.litlyx.com/payment'; + static BASE_URL = 'https://payments.litlyx.com/payment'; private static async send(endpoint: string, body: Record): PaymentServiceResponse { try { @@ -22,6 +22,9 @@ export class PaymentServiceHelper { }) return [true, res]; } catch (ex: any) { + console.log('---') + console.log(ex.response?._data); + console.log('---') console.error(ex); return [false, ex]; } diff --git a/payments/src/routers/PaymentRouter.ts b/payments/src/routers/PaymentRouter.ts index ff599b6..600d52f 100644 --- a/payments/src/routers/PaymentRouter.ts +++ b/payments/src/routers/PaymentRouter.ts @@ -41,7 +41,7 @@ export const ZBodyCreatePayment = z.object({ plan_id: z.number() }); -paymentRouter.post('/create', json(), async (req, res) => { +paymentRouter.post('/create_payment', json(), async (req, res) => { try { const createPaymentData = ZBodyCreatePayment.parse(req.body);