diff --git a/packages/trpc/server/routers/viewer/payments.tsx b/packages/trpc/server/routers/viewer/payments.tsx index 6e0210fd4c..54c77e432e 100644 --- a/packages/trpc/server/routers/viewer/payments.tsx +++ b/packages/trpc/server/routers/viewer/payments.tsx @@ -9,6 +9,7 @@ import { getTranslation } from "@calcom/lib/server/i18n"; import sendPayload from "@calcom/lib/server/webhooks/sendPayload"; import { WebhookTriggerEvents } from "@calcom/prisma/enums"; import type { CalendarEvent } from "@calcom/types/Calendar"; +import type { PaymentApp } from "@calcom/types/PaymentService"; import { TRPCError } from "@trpc/server"; @@ -25,7 +26,7 @@ export const paymentsRouter = router({ .mutation(async ({ ctx, input }) => { const { prisma } = ctx; - const booking = await prisma.booking.findFirst({ + const booking = await prisma.booking.findFirstOrThrow({ where: { id: input.bookingId, }, @@ -46,10 +47,6 @@ export const paymentsRouter = router({ const payment = booking.payment[0]; - if (!booking) { - throw new Error("Booking not found"); - } - if (payment.success) { throw new TRPCError({ code: "BAD_REQUEST", @@ -110,9 +107,11 @@ export const paymentsRouter = router({ throw new TRPCError({ code: "BAD_REQUEST", message: "Invalid payment credential" }); } - const paymentApp = await appStore[paymentCredential?.app?.dirName as keyof typeof appStore]; + const paymentApp = (await appStore[ + paymentCredential?.app?.dirName as keyof typeof appStore + ]?.()) as PaymentApp | null; - if (!("lib" in paymentApp && "PaymentService" in paymentApp.lib)) { + if (!(paymentApp && paymentApp.lib && "lib" in paymentApp && "PaymentService" in paymentApp.lib)) { throw new TRPCError({ code: "BAD_REQUEST", message: "Payment service not found" }); }