fix: Updates to HitPay app (#21175)
* reapplied my changes after syncing with upstream * fix: changed raw error to sanitized error * fix: added try/catch to create catch
This commit is contained in:
1 parent
afc28503a5
commit
3895ef002e
4 files changed
+31
-2
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -6,6 +6,7 @@ export type PaidBooking = Prisma.BookingGetPayload<{
|
||||
title: true;
|
||||
startTime: true;
|
||||
endTime: true;
|
||||
eventTypeId: true;
|
||||
eventType: {
|
||||
select: {
|
||||
slug: true;
|
||||
|
||||
Reference in new issue
Block a user