From 72cc95a0d7f058290818da4802b239c4d50e77e5 Mon Sep 17 00:00:00 2001 From: Sean Brydon Date: Tue, 5 Sep 2023 16:23:35 +0100 Subject: [PATCH] Skip if env has no price ID --- apps/web/pages/api/auth/signup.ts | 7 +++++-- packages/features/auth/lib/signup/signupUtils.ts | 11 ++++++++--- packages/features/auth/lib/signup/teamInviteUtils.ts | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/apps/web/pages/api/auth/signup.ts b/apps/web/pages/api/auth/signup.ts index c70109dc43..7dfe122ea8 100644 --- a/apps/web/pages/api/auth/signup.ts +++ b/apps/web/pages/api/auth/signup.ts @@ -16,7 +16,7 @@ import { acceptAllInvitesWithTeamId, findTeam, upsertUsersPasswordAndVerify, - joinOrgAndAcceptChildInivtes, + joinOrgAndAcceptChildInvites, cleanUpInviteToken, } from "@calcom/feature-auth/lib/signup/teamInviteUtils"; import { hashPassword } from "@calcom/features/auth/lib/hashPassword"; @@ -87,7 +87,7 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) { const membership = await acceptAllInvitesWithTeamId(user.id, team.id); closeComUpsertTeamUser(team, user, membership.role); if (team.parentId) { - await joinOrgAndAcceptChildInivtes(user.id, team.parentId); + await joinOrgAndAcceptChildInvites(user.id, team.parentId); } await cleanUpInviteToken(foundToken.id); } @@ -108,6 +108,9 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) { return res.status(201).json({ message: "Created user" }); } catch (e) { + console.log({ + e, + }); if (e instanceof HttpError) { return res.status(e.statusCode).json({ message: e.message }); } diff --git a/packages/features/auth/lib/signup/signupUtils.ts b/packages/features/auth/lib/signup/signupUtils.ts index 187dd93502..c8eeefddc2 100644 --- a/packages/features/auth/lib/signup/signupUtils.ts +++ b/packages/features/auth/lib/signup/signupUtils.ts @@ -1,5 +1,6 @@ import type Stripe from "stripe"; +import { PREMIUM_MONTHLY_PLAN_PRICE } from "@calcom/app-store/stripepayment/lib"; import stripe from "@calcom/app-store/stripepayment/lib/server"; import { getPremiumMonthlyPlanPriceId } from "@calcom/app-store/stripepayment/lib/utils"; import { IS_CALCOM, IS_STRIPE_ENABLED, WEBAPP_URL } from "@calcom/lib/constants"; @@ -67,6 +68,7 @@ export function parseSignupData(data: unknown) { export async function createStripeCustomer({ email, username }: { email: string; username: string }) { // Create the customer in Stripe if (!IS_STRIPE_ENABLED) return; + console.log("Creating Stripe customer"); const customer = await stripe.customers.create({ email, metadata: { @@ -74,7 +76,6 @@ export async function createStripeCustomer({ email, username }: { email: string; username, }, }); - return customer; } @@ -85,8 +86,7 @@ export async function handlePremiumUsernameFlow({ premiumUsernameStatusCode: number; customer?: Stripe.Customer; }) { - if (!IS_CALCOM) return; - if (!IS_STRIPE_ENABLED) return; + if (!IS_STRIPE_ENABLED || !PREMIUM_MONTHLY_PLAN_PRICE || !IS_CALCOM) return; if (!customer) { throw new HttpError({ @@ -95,6 +95,11 @@ export async function handlePremiumUsernameFlow({ }); } + const metadata: { + stripeCustomerId?: string; + checkoutSessionId?: string; + } = {}; + const returnUrl = `${WEBAPP_URL}/api/integrations/stripepayment/paymentCallback?checkoutSessionId={CHECKOUT_SESSION_ID}&callbackUrl=/auth/verify?sessionId={CHECKOUT_SESSION_ID}`; if (premiumUsernameStatusCode === 402) { diff --git a/packages/features/auth/lib/signup/teamInviteUtils.ts b/packages/features/auth/lib/signup/teamInviteUtils.ts index 9edf582ae7..9198f81333 100644 --- a/packages/features/auth/lib/signup/teamInviteUtils.ts +++ b/packages/features/auth/lib/signup/teamInviteUtils.ts @@ -82,7 +82,7 @@ export async function acceptAllInvitesWithTeamId(userId: number, teamId: number) return membership; } -export async function joinOrgAndAcceptChildInivtes(userId: number, orgId: number) { +export async function joinOrgAndAcceptChildInvites(userId: number, orgId: number) { // Join ORG await prisma.user.update({ where: {