a3fc17bc75
- Add teamId support to HitPay add.ts installation handler - Update callback.ts to fetch credentials by teamId for team bookings - Update webhook.ts to fetch credentials by teamId for team bookings - Update setup page to accept and handle teamId from query params - Add permission checks using throwIfNotHaveAdminAccessToTeam - Ensure credentials are created with teamId for team installs, userId for user installs Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import type { GetServerSidePropsContext } from "next";
|
|
import { z } from "zod";
|
|
|
|
import { throwIfNotHaveAdminAccessToTeam } from "@calcom/app-store/_utils/throwIfNotHaveAdminAccessToTeam";
|
|
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
|
import prisma from "@calcom/prisma";
|
|
|
|
import { hitpayCredentialKeysSchema } from "../../lib/hitpayCredentialKeysSchema";
|
|
|
|
export type IHitPaySetupProps = z.infer<typeof hitpayCredentialKeysSchema>;
|
|
|
|
export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
|
|
const notFound = { notFound: true } as const;
|
|
|
|
if (typeof ctx.params?.slug !== "string") return notFound;
|
|
|
|
const { req, query } = ctx;
|
|
const session = await getServerSession({ req });
|
|
|
|
if (!session?.user?.id) {
|
|
const redirect = { redirect: { permanent: false, destination: "/auth/login" } } as const;
|
|
|
|
return redirect;
|
|
}
|
|
|
|
const teamId = query.teamId ? Number(query.teamId) : null;
|
|
|
|
await throwIfNotHaveAdminAccessToTeam({ teamId, userId: session.user.id });
|
|
const installForObject = teamId ? { teamId } : { userId: session.user.id };
|
|
|
|
const credentials = await prisma.credential.findFirst({
|
|
where: {
|
|
type: "hitpay_payment",
|
|
...installForObject,
|
|
},
|
|
});
|
|
|
|
let props: IHitPaySetupProps = {
|
|
isSandbox: false,
|
|
};
|
|
|
|
if (credentials?.key) {
|
|
const keyParsing = hitpayCredentialKeysSchema.safeParse(credentials.key);
|
|
if (keyParsing.success) {
|
|
props = {
|
|
...props,
|
|
...keyParsing.data,
|
|
};
|
|
}
|
|
}
|
|
|
|
return {
|
|
props,
|
|
};
|
|
};
|