2023-02-16 22:39:57 +00:00
|
|
|
import { BookingStatus } from "@prisma/client";
|
|
|
|
import type { GetServerSidePropsContext } from "next";
|
2022-07-28 19:58:26 +00:00
|
|
|
import { z } from "zod";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { StripePaymentData } from "@calcom/app-store/stripepayment/lib/server";
|
2022-07-28 19:58:26 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
2022-10-14 16:24:43 +00:00
|
|
|
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
2022-07-28 19:58:26 +00:00
|
|
|
import type { inferSSRProps } from "@calcom/types/inferSSRProps";
|
2021-09-22 18:36:13 +00:00
|
|
|
|
2022-10-10 08:11:47 +00:00
|
|
|
import { ssrInit } from "@server/lib/ssr";
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
export type PaymentPageProps = inferSSRProps<typeof getServerSideProps>;
|
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
const querySchema = z.object({
|
|
|
|
uid: z.string(),
|
|
|
|
});
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
2022-10-10 08:11:47 +00:00
|
|
|
const ssr = await ssrInit(context);
|
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
const { uid } = querySchema.parse(context.query);
|
2021-09-22 18:36:13 +00:00
|
|
|
const rawPayment = await prisma.payment.findFirst({
|
|
|
|
where: {
|
2022-07-28 19:58:26 +00:00
|
|
|
uid,
|
2021-09-22 18:36:13 +00:00
|
|
|
},
|
|
|
|
select: {
|
|
|
|
data: true,
|
|
|
|
success: true,
|
|
|
|
uid: true,
|
|
|
|
refunded: true,
|
|
|
|
bookingId: true,
|
2023-02-08 20:36:22 +00:00
|
|
|
appId: true,
|
2021-09-22 18:36:13 +00:00
|
|
|
booking: {
|
|
|
|
select: {
|
2022-05-11 20:36:38 +00:00
|
|
|
id: true,
|
2022-11-15 19:00:02 +00:00
|
|
|
uid: true,
|
2021-09-22 18:36:13 +00:00
|
|
|
description: true,
|
|
|
|
title: true,
|
|
|
|
startTime: true,
|
|
|
|
attendees: {
|
|
|
|
select: {
|
|
|
|
email: true,
|
|
|
|
name: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
eventTypeId: true,
|
|
|
|
location: true,
|
2023-02-13 12:26:28 +00:00
|
|
|
status: true,
|
|
|
|
rejectionReason: true,
|
|
|
|
cancellationReason: true,
|
2021-09-22 18:36:13 +00:00
|
|
|
eventType: {
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
title: true,
|
|
|
|
description: true,
|
|
|
|
length: true,
|
|
|
|
eventName: true,
|
|
|
|
requiresConfirmation: true,
|
|
|
|
userId: true,
|
2022-10-14 16:24:43 +00:00
|
|
|
metadata: true,
|
2021-09-22 18:36:13 +00:00
|
|
|
users: {
|
|
|
|
select: {
|
|
|
|
name: true,
|
|
|
|
username: true,
|
|
|
|
hideBranding: true,
|
|
|
|
theme: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
team: {
|
|
|
|
select: {
|
|
|
|
name: true,
|
|
|
|
hideBranding: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
price: true,
|
|
|
|
currency: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-05-31 13:40:12 +00:00
|
|
|
if (!rawPayment) return { notFound: true };
|
2021-09-22 18:36:13 +00:00
|
|
|
|
|
|
|
const { data, booking: _booking, ...restPayment } = rawPayment;
|
|
|
|
const payment = {
|
|
|
|
...restPayment,
|
2023-02-08 20:36:22 +00:00
|
|
|
data: data as unknown as StripePaymentData,
|
2021-09-22 18:36:13 +00:00
|
|
|
};
|
|
|
|
|
2022-05-31 13:40:12 +00:00
|
|
|
if (!_booking) return { notFound: true };
|
2021-09-22 18:36:13 +00:00
|
|
|
|
|
|
|
const { startTime, eventType, ...restBooking } = _booking;
|
|
|
|
const booking = {
|
|
|
|
...restBooking,
|
|
|
|
startTime: startTime.toString(),
|
|
|
|
};
|
|
|
|
|
2022-05-31 13:40:12 +00:00
|
|
|
if (!eventType) return { notFound: true };
|
2021-09-22 18:36:13 +00:00
|
|
|
|
|
|
|
const [user] = eventType.users;
|
|
|
|
if (!user) return { notFound: true };
|
|
|
|
|
|
|
|
const profile = {
|
|
|
|
name: eventType.team?.name || user?.name || null,
|
|
|
|
theme: (!eventType.team?.name && user?.theme) || null,
|
|
|
|
hideBranding: eventType.team?.hideBranding || user?.hideBranding || null,
|
|
|
|
};
|
|
|
|
|
2023-02-13 12:26:28 +00:00
|
|
|
if (
|
|
|
|
([BookingStatus.CANCELLED, BookingStatus.REJECTED] as BookingStatus[]).includes(
|
|
|
|
booking.status as BookingStatus
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
return {
|
|
|
|
redirect: {
|
|
|
|
destination: `/booking/${booking.uid}`,
|
|
|
|
permanent: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
user,
|
2022-10-14 16:24:43 +00:00
|
|
|
eventType: {
|
|
|
|
...eventType,
|
|
|
|
metadata: EventTypeMetaDataSchema.parse(eventType.metadata),
|
|
|
|
},
|
2021-09-22 18:36:13 +00:00
|
|
|
booking,
|
2022-10-10 08:11:47 +00:00
|
|
|
trpcState: ssr.dehydrate(),
|
2021-09-22 18:36:13 +00:00
|
|
|
payment,
|
|
|
|
profile,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|