 5625cf226b
			
		
	
	
		5625cf226b
		
			
		
	
	
	
	
		
			
			* downgrade func * fix security hole lol * fix query conditions * - set to trial not free - auto create stripe customer if missing - fix production check * Extracts downgrade logic to script, fixes ts-node conflicts with prisma * Adds trialEndsAt field to users * Updates trial/downgrade logic * Typo * Legibility fixes * Update team-billing.ts * Legibility improvements * Updates illegal logic * WIP * WIP migrating stripe to package * Update website * Import fixes * Import fixes * Fixes to downgrade script * Check for premium usernames before downgrading * Fixed formatting * Delete deploy-env.sh * Locks dayjs to 1.10.6 * Type fixes * Seems like we're stuck with dayjs 1.10.4 * Script fixes * Adds first name to dump * Loop fix Co-authored-by: Jamie <ijamespine@me.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
		
			
				
	
	
		
			104 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			104 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { GetServerSidePropsContext } from "next";
 | |
| 
 | |
| import { PaymentData } from "@calcom/stripe/server";
 | |
| 
 | |
| import { asStringOrThrow } from "@lib/asStringOrNull";
 | |
| import prisma from "@lib/prisma";
 | |
| import { inferSSRProps } from "@lib/types/inferSSRProps";
 | |
| 
 | |
| export type PaymentPageProps = inferSSRProps<typeof getServerSideProps>;
 | |
| 
 | |
| export const getServerSideProps = async (context: GetServerSidePropsContext) => {
 | |
|   const rawPayment = await prisma.payment.findFirst({
 | |
|     where: {
 | |
|       uid: asStringOrThrow(context.query.uid),
 | |
|     },
 | |
|     select: {
 | |
|       data: true,
 | |
|       success: true,
 | |
|       uid: true,
 | |
|       refunded: true,
 | |
|       bookingId: true,
 | |
|       booking: {
 | |
|         select: {
 | |
|           description: true,
 | |
|           title: true,
 | |
|           startTime: true,
 | |
|           attendees: {
 | |
|             select: {
 | |
|               email: true,
 | |
|               name: true,
 | |
|             },
 | |
|           },
 | |
|           eventTypeId: true,
 | |
|           location: true,
 | |
|           eventType: {
 | |
|             select: {
 | |
|               id: true,
 | |
|               title: true,
 | |
|               description: true,
 | |
|               length: true,
 | |
|               eventName: true,
 | |
|               requiresConfirmation: true,
 | |
|               userId: true,
 | |
|               users: {
 | |
|                 select: {
 | |
|                   name: true,
 | |
|                   username: true,
 | |
|                   hideBranding: true,
 | |
|                   plan: true,
 | |
|                   theme: true,
 | |
|                 },
 | |
|               },
 | |
|               team: {
 | |
|                 select: {
 | |
|                   name: true,
 | |
|                   hideBranding: true,
 | |
|                 },
 | |
|               },
 | |
|               price: true,
 | |
|               currency: true,
 | |
|             },
 | |
|           },
 | |
|         },
 | |
|       },
 | |
|     },
 | |
|   });
 | |
| 
 | |
|   if (!rawPayment) throw Error("Payment not found");
 | |
| 
 | |
|   const { data, booking: _booking, ...restPayment } = rawPayment;
 | |
|   const payment = {
 | |
|     ...restPayment,
 | |
|     data: data as unknown as PaymentData,
 | |
|   };
 | |
| 
 | |
|   if (!_booking) throw Error("Booking not found");
 | |
| 
 | |
|   const { startTime, eventType, ...restBooking } = _booking;
 | |
|   const booking = {
 | |
|     ...restBooking,
 | |
|     startTime: startTime.toString(),
 | |
|   };
 | |
| 
 | |
|   if (!eventType) throw Error("Event not found");
 | |
| 
 | |
|   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,
 | |
|   };
 | |
| 
 | |
|   return {
 | |
|     props: {
 | |
|       user,
 | |
|       eventType,
 | |
|       booking,
 | |
|       payment,
 | |
|       profile,
 | |
|     },
 | |
|   };
 | |
| };
 |