From 19d00e691c79e2148ace49738a9ddaae29dbc192 Mon Sep 17 00:00:00 2001 From: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Date: Thu, 1 Dec 2022 19:12:06 -0500 Subject: [PATCH] Fix attendees on a booking with seats and payments, navigate to the payment page. (#5788) * Payment booking logic to seats * Pass email to success page from payment page * Fix type error Co-authored-by: Alan --- apps/web/pages/booking/[uid].tsx | 15 ++++++----- .../features/bookings/lib/handleNewBooking.ts | 27 ++++++++++++------- .../ee/payments/components/Payment.tsx | 7 +++-- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/apps/web/pages/booking/[uid].tsx b/apps/web/pages/booking/[uid].tsx index c934cdf337..f893f67569 100644 --- a/apps/web/pages/booking/[uid].tsx +++ b/apps/web/pages/booking/[uid].tsx @@ -881,22 +881,25 @@ const handleSeatsEventTypeOnBooking = ( seatsShowAttendees: boolean | null; [x: string | number | symbol]: unknown; }, - booking: Partial< + bookingInfo: Partial< Prisma.BookingGetPayload<{ include: { attendees: { select: { name: true; email: true } } } }> >, email: string ) => { if (eventType?.seatsPerTimeSlot !== null) { // @TODO: right now bookings with seats doesn't save every description that its entered by every user - delete booking.description; + delete bookingInfo.description; } else { return; } if (!eventType.seatsShowAttendees) { - const attendee = booking?.attendees?.find((a) => a.email === email); - booking["attendees"] = attendee ? [attendee] : []; + const attendee = bookingInfo?.attendees?.find((a) => { + return a.email === email; + }); + + bookingInfo["attendees"] = attendee ? [attendee] : []; } - return; + return bookingInfo; }; export async function getServerSideProps(context: GetServerSidePropsContext) { @@ -1007,7 +1010,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { slug: eventType.team?.slug || eventType.users[0]?.username || null, }; - if (bookingInfo !== null && email) { + if (bookingInfo !== null && email && eventType.seatsPerTimeSlot) { handleSeatsEventTypeOnBooking(eventType, bookingInfo, email); } diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 6951dc36e6..b2b7ee77eb 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -519,16 +519,9 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) { id: true, attendees: true, userId: true, - references: { - select: { - type: true, - uid: true, - meetingId: true, - meetingPassword: true, - meetingUrl: true, - externalCalendarId: true, - }, - }, + references: true, + startTime: true, + user: true, }, }); if (!booking) { @@ -579,6 +572,20 @@ async function handler(req: NextApiRequest & { userId?: number | undefined }) { const eventManager = new EventManager({ ...organizerUser, credentials }); await eventManager.updateCalendarAttendees(evt, booking); + if (!Number.isNaN(stripeAppData.price) && stripeAppData.price > 0 && !!booking) { + const [firstStripeCredential] = organizerUser.credentials.filter( + (cred) => cred.type == "stripe_payment" + ); + + if (!firstStripeCredential) + throw new HttpError({ statusCode: 400, message: "Missing payment credentials" }); + + const payment = await handlePayment(evt, eventType, firstStripeCredential, booking); + + req.statusCode = 201; + return { ...booking, message: "Payment required", paymentUid: payment.uid }; + } + req.statusCode = 201; return booking; } diff --git a/packages/features/ee/payments/components/Payment.tsx b/packages/features/ee/payments/components/Payment.tsx index 39cd3bcd49..c83b09e9e8 100644 --- a/packages/features/ee/payments/components/Payment.tsx +++ b/packages/features/ee/payments/components/Payment.tsx @@ -66,7 +66,7 @@ export default function PaymentComponent(props: Props) { const handleSubmit = async (ev: SyntheticEvent) => { ev.preventDefault(); - if (!stripe || !elements) return; + if (!stripe || !elements || !router.isReady) return; const card = elements.getElement(CardElement); if (!card) return; setState({ status: "processing" }); @@ -81,7 +81,10 @@ export default function PaymentComponent(props: Props) { error: new Error(`Payment failed: ${payload.error.message}`), }); } else { - const params: { [k: string]: any } = {}; + const params: { [k: string]: any } = { + uid: props.bookingUid, + email: router.query.email, + }; if (props.location) { if (props.location.includes("integration")) {