From da7e599910d9e3b57c0b5375801d67a55413f69c Mon Sep 17 00:00:00 2001 From: Sean Brydon Date: Tue, 5 Sep 2023 17:18:34 +0100 Subject: [PATCH] Sign up stripe redirect --- apps/web/pages/signup.tsx | 13 ++++++++++++- packages/lib/constants.ts | 11 ++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/web/pages/signup.tsx b/apps/web/pages/signup.tsx index c41025bc99..53a960179f 100644 --- a/apps/web/pages/signup.tsx +++ b/apps/web/pages/signup.tsx @@ -7,6 +7,7 @@ import type { SubmitHandler } from "react-hook-form"; import { FormProvider, useForm } from "react-hook-form"; import { z } from "zod"; +import getStripe from "@calcom/app-store/stripepayment/lib/client"; import { checkPremiumUsername } from "@calcom/features/ee/common/lib/checkPremiumUsername"; import { getOrgFullDomain } from "@calcom/features/ee/organizations/lib/orgDomains"; import { isSAMLLoginEnabled } from "@calcom/features/ee/sso/lib/saml"; @@ -52,7 +53,17 @@ export default function Signup({ prepopulateFormValues, token, orgSlug }: Signup const handleErrors = async (resp: Response) => { if (!resp.ok) { const err = await resp.json(); - throw new Error(err.message); + if (err.checkoutSessionId) { + const stripe = await getStripe(); + if (stripe) { + const { error } = await stripe.redirectToCheckout({ + sessionId: err.checkoutSessionId, + }); + console.warn(error.message); + } + } else { + throw new Error(err.message); + } } }; diff --git a/packages/lib/constants.ts b/packages/lib/constants.ts index 714626527b..651c2b0037 100644 --- a/packages/lib/constants.ts +++ b/packages/lib/constants.ts @@ -33,11 +33,12 @@ export const SENDER_NAME = process.env.NEXT_PUBLIC_SENDGRID_SENDER_NAME || "Cal. export const CAL_URL = new URL(WEBAPP_URL).hostname.endsWith(".vercel.app") ? WEBAPP_URL : WEBSITE_URL; export const IS_CALCOM = - WEBAPP_URL && - (new URL(WEBAPP_URL).hostname.endsWith("cal.com") || - new URL(WEBAPP_URL).hostname.endsWith("cal.dev") || - new URL(WEBAPP_URL).hostname.endsWith("cal.qa") || - new URL(WEBAPP_URL).hostname.endsWith("cal-staging.com")); + true || + (WEBAPP_URL && + (new URL(WEBAPP_URL).hostname.endsWith("cal.com") || + new URL(WEBAPP_URL).hostname.endsWith("cal.dev") || + new URL(WEBAPP_URL).hostname.endsWith("cal.qa") || + new URL(WEBAPP_URL).hostname.endsWith("cal-staging.com"))); export const CONSOLE_URL = new URL(WEBAPP_URL).hostname.endsWith(".cal.dev") ||