diff --git a/apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx b/apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx index db79b7b600..950da96920 100644 --- a/apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx +++ b/apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx @@ -5,6 +5,7 @@ import type { RefCallback } from "react"; import { useEffect, useMemo, useState } from "react"; import { getPremiumPlanPriceValue } from "@calcom/app-store/stripepayment/lib/utils"; +import { WEBAPP_URL } from "@calcom/lib/constants"; import { fetchUsername } from "@calcom/lib/fetchUsername"; import hasKeyInMetadata from "@calcom/lib/hasKeyInMetadata"; import { useLocale } from "@calcom/lib/hooks/useLocale"; @@ -116,7 +117,7 @@ const PremiumTextfield = (props: ICustomUsernameProps) => { const paymentLink = `/api/integrations/stripepayment/subscription?intentUsername=${ inputUsernameValue || usernameFromStripe - }&action=${usernameChangeCondition}&callbackUrl=${router.asPath}`; + }&action=${usernameChangeCondition}&callbackUrl=${WEBAPP_URL}${router.asPath}`; const ActionButtons = () => { if (paymentRequired) { diff --git a/apps/web/components/ui/UsernameAvailability/UsernameTextfield.tsx b/apps/web/components/ui/UsernameAvailability/UsernameTextfield.tsx index 3b7541c7eb..05871030c7 100644 --- a/apps/web/components/ui/UsernameAvailability/UsernameTextfield.tsx +++ b/apps/web/components/ui/UsernameAvailability/UsernameTextfield.tsx @@ -135,7 +135,7 @@ const UsernameTextfield = (props: ICustomUsernameProps & Partial {currentUsername !== inputUsernameValue && (
- + {usernameIsAvailable ? : <>}
diff --git a/packages/trpc/server/routers/loggedInViewer/stripeCustomer.handler.ts b/packages/trpc/server/routers/loggedInViewer/stripeCustomer.handler.ts index 857e865387..15a8cc8944 100644 --- a/packages/trpc/server/routers/loggedInViewer/stripeCustomer.handler.ts +++ b/packages/trpc/server/routers/loggedInViewer/stripeCustomer.handler.ts @@ -30,12 +30,29 @@ export const stripeCustomerHandler = async ({ ctx }: StripeCustomerOptions) => { } const metadata = userMetadata.parse(user.metadata); - - if (!metadata?.stripeCustomerId) { - throw new TRPCError({ code: "BAD_REQUEST", message: "No stripe customer id" }); + let stripeCustomerId = metadata?.stripeCustomerId; + if (!stripeCustomerId) { + // Create stripe customer + const customer = await stripe.customers.create({ + metadata: { + userId: userId.toString(), + }, + }); + await prisma.user.update({ + where: { + id: userId, + }, + data: { + metadata: { + ...metadata, + stripeCustomerId: customer.id, + }, + }, + }); + stripeCustomerId = customer.id; } + // Fetch stripe customer - const stripeCustomerId = metadata?.stripeCustomerId; const customer = await stripe.customers.retrieve(stripeCustomerId); if (customer.deleted) { throw new TRPCError({ code: "BAD_REQUEST", message: "No stripe customer found" });