Scheduling infrastructure for absolutely everyone.
fix: Updates to HitPay app (#21175)
Muhammad Aiman Sulaiman3895ef002e64
diff --git a/packages/app-store/hitpay/api/callback.ts b/packages/app-store/hitpay/api/callback.tsindex cdf2b1a9e6b..9c9c9e0328b 100644--- a/packages/app-store/hitpay/api/callback.ts+++ b/packages/app-store/hitpay/api/callback.ts@@ -65,6 +65,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)}if (status !== "completed") {+ await prisma.booking.update({+ where: {+ id: payment.bookingId,+ },+ data: {+ status: "CANCELLED",+ },+ });const url = `/${payment.booking.user.username}/${payment.booking.eventType.slug}`;return res.redirect(url);}diff --git a/packages/app-store/hitpay/api/webhook.ts b/packages/app-store/hitpay/api/webhook.tsindex 6cc7f896ab3..eb920c18fc1 100644--- a/packages/app-store/hitpay/api/webhook.ts+++ b/packages/app-store/hitpay/api/webhook.ts@@ -47,6 +47,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)if (req.method !== "POST") {throw new HttpCode({ statusCode: 405, message: "Method Not Allowed" });}+const obj: WebhookReturn = req.body as WebhookReturn;const excluded = { ...obj } as Partial<WebhookReturn>;delete excluded.hmac;diff --git a/packages/app-store/hitpay/lib/PaymentService.ts b/packages/app-store/hitpay/lib/PaymentService.tsindex cd3cfe3ed53..6618f14a087 100644--- a/packages/app-store/hitpay/lib/PaymentService.ts+++ b/packages/app-store/hitpay/lib/PaymentService.ts@@ -50,6 +50,7 @@ export class PaymentService implements IAbstractPaymentService {title: true,startTime: true,endTime: true,+ eventTypeId: true,eventType: {select: {slug: true,@@ -64,11 +65,13 @@ export class PaymentService implements IAbstractPaymentService {throw new Error("Booking or API key not found");}- const { startTime, endTime } = booking;+ const { startTime, endTime, eventTypeId } = booking;const bookingsWithSameTimeSlot = await prisma.booking.findMany({where: {+ eventTypeId,startTime,endTime,+ OR: [{ status: "PENDING" }, { status: "AWAITING_HOST" }],},select: {uid: true,@@ -169,8 +172,24 @@ export class PaymentService implements IAbstractPaymentService {throw new Error("Failed to store Payment data");}return paymentData;- } catch (error) {+ } catch (error: any) {log.error("Payment could not be created", bookingId, safeStringify(error));+ try {+ await prisma.booking.update({+ where: {+ id: bookingId,+ },+ data: {+ status: "CANCELLED",+ },+ });+ } catch (error) {+ throw new Error(ErrorCode.PaymentCreationFailure);+ }++ if (error.message === ErrorCode.BookingSeatsFull || error.message === ErrorCode.NoAvailableUsersFound) {+ throw error;+ }throw new Error(ErrorCode.PaymentCreationFailure);}}diff --git a/packages/app-store/hitpay/lib/types.d.ts b/packages/app-store/hitpay/lib/types.d.tsindex 8f0a9a7267c..443b5af52b0 100644--- a/packages/app-store/hitpay/lib/types.d.ts+++ b/packages/app-store/hitpay/lib/types.d.ts@@ -6,6 +6,7 @@ export type PaidBooking = Prisma.BookingGetPayload<{title: true;startTime: true;endTime: true;+ eventTypeId: true;eventType: {select: {slug: true;