From 23c9dc304a4034e59ffb388f4616aa26430fcc38 Mon Sep 17 00:00:00 2001 From: Dhruwang Jariwala <67850763+Dhruwang@users.noreply.github.com> Date: Tue, 19 Nov 2024 16:30:39 +0530 Subject: [PATCH] chore: Billing to new module structure (#4308) --- .../(organization)/billing/loading.tsx | 0 .../settings/(organization)/billing/page.tsx | 3 ++ .../environments/[environmentId]/layout.tsx | 3 -- .../(organization)/billing/layout.tsx | 36 ------------------- .../app/api/billing/stripe-webhook/route.ts | 3 ++ .../ee}/billing/actions.ts | 6 ++-- .../api/lib/checkout-session-completed.ts} | 0 .../ee/billing/api}/lib/constants.ts | 0 .../lib/create-customer-portal-session.ts} | 0 .../billing/api/lib/create-subscription.ts} | 0 .../ee/billing/api/lib/invoice-finalized.ts} | 0 .../api/lib/is-subscription-cancelled.ts} | 0 .../ee/billing/api/lib/stripe-webhook.ts} | 8 ++--- .../lib/subscription-created-or-updated.ts} | 0 .../billing/api/lib/subscription-deleted.ts} | 0 .../ee/billing/api}/route.ts | 2 +- .../ee/billing/components/billing-slider.tsx | 0 .../ee/billing/components/pricing-card.tsx | 12 ++++--- .../ee/billing/components/pricing-table.tsx} | 12 +++---- .../ee}/billing/page.tsx | 12 ++++--- 20 files changed, 34 insertions(+), 63 deletions(-) rename apps/web/app/{(ee)/(billing) => (app)}/environments/[environmentId]/settings/(organization)/billing/loading.tsx (100%) create mode 100644 apps/web/app/(app)/environments/[environmentId]/settings/(organization)/billing/page.tsx delete mode 100644 apps/web/app/(ee)/(billing)/environments/[environmentId]/layout.tsx delete mode 100644 apps/web/app/(ee)/(billing)/environments/[environmentId]/settings/(organization)/billing/layout.tsx create mode 100644 apps/web/app/api/billing/stripe-webhook/route.ts rename apps/web/{app/(ee)/(billing)/environments/[environmentId]/settings/(organization) => modules/ee}/billing/actions.ts (89%) rename apps/web/{app/(ee)/(billing)/api/billing/stripe-webhook/lib/checkoutSessionCompleted.ts => modules/ee/billing/api/lib/checkout-session-completed.ts} (100%) rename apps/web/{app/(ee)/(billing)/api/billing/stripe-webhook => modules/ee/billing/api}/lib/constants.ts (100%) rename apps/web/{app/(ee)/(billing)/api/billing/stripe-webhook/lib/createCustomerPortalSession.ts => modules/ee/billing/api/lib/create-customer-portal-session.ts} (100%) rename apps/web/{app/(ee)/(billing)/api/billing/stripe-webhook/lib/createSubscription.ts => modules/ee/billing/api/lib/create-subscription.ts} (100%) rename apps/web/{app/(ee)/(billing)/api/billing/stripe-webhook/lib/invoiceFinalized.ts => modules/ee/billing/api/lib/invoice-finalized.ts} (100%) rename apps/web/{app/(ee)/(billing)/api/billing/stripe-webhook/lib/isSubscriptionCancelled.ts => modules/ee/billing/api/lib/is-subscription-cancelled.ts} (100%) rename apps/web/{app/(ee)/(billing)/api/billing/stripe-webhook/lib/stripeWebhook.ts => modules/ee/billing/api/lib/stripe-webhook.ts} (75%) rename apps/web/{app/(ee)/(billing)/api/billing/stripe-webhook/lib/subscriptionCreatedOrUpdated.ts => modules/ee/billing/api/lib/subscription-created-or-updated.ts} (100%) rename apps/web/{app/(ee)/(billing)/api/billing/stripe-webhook/lib/subscriptionDeleted.ts => modules/ee/billing/api/lib/subscription-deleted.ts} (100%) rename apps/web/{app/(ee)/(billing)/api/billing/stripe-webhook => modules/ee/billing/api}/route.ts (87%) rename packages/ui/components/BillingSlider/index.tsx => apps/web/modules/ee/billing/components/billing-slider.tsx (100%) rename packages/ui/components/PricingCard/index.tsx => apps/web/modules/ee/billing/components/pricing-card.tsx (94%) rename apps/web/{app/(ee)/(billing)/environments/[environmentId]/settings/(organization)/billing/components/PricingTable.tsx => modules/ee/billing/components/pricing-table.tsx} (95%) rename apps/web/{app/(ee)/(billing)/environments/[environmentId]/settings/(organization) => modules/ee}/billing/page.tsx (93%) diff --git a/apps/web/app/(ee)/(billing)/environments/[environmentId]/settings/(organization)/billing/loading.tsx b/apps/web/app/(app)/environments/[environmentId]/settings/(organization)/billing/loading.tsx similarity index 100% rename from apps/web/app/(ee)/(billing)/environments/[environmentId]/settings/(organization)/billing/loading.tsx rename to apps/web/app/(app)/environments/[environmentId]/settings/(organization)/billing/loading.tsx diff --git a/apps/web/app/(app)/environments/[environmentId]/settings/(organization)/billing/page.tsx b/apps/web/app/(app)/environments/[environmentId]/settings/(organization)/billing/page.tsx new file mode 100644 index 0000000000..95f26340bd --- /dev/null +++ b/apps/web/app/(app)/environments/[environmentId]/settings/(organization)/billing/page.tsx @@ -0,0 +1,3 @@ +import { PricingPage } from "@/modules/ee/billing/page"; + +export default PricingPage; diff --git a/apps/web/app/(ee)/(billing)/environments/[environmentId]/layout.tsx b/apps/web/app/(ee)/(billing)/environments/[environmentId]/layout.tsx deleted file mode 100644 index b264259515..0000000000 --- a/apps/web/app/(ee)/(billing)/environments/[environmentId]/layout.tsx +++ /dev/null @@ -1,3 +0,0 @@ -import EnvLayout from "../../../../(app)/environments/[environmentId]/layout"; - -export default EnvLayout; diff --git a/apps/web/app/(ee)/(billing)/environments/[environmentId]/settings/(organization)/billing/layout.tsx b/apps/web/app/(ee)/(billing)/environments/[environmentId]/settings/(organization)/billing/layout.tsx deleted file mode 100644 index b6a6a550c2..0000000000 --- a/apps/web/app/(ee)/(billing)/environments/[environmentId]/settings/(organization)/billing/layout.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { Metadata } from "next"; -import { getServerSession } from "next-auth"; -import { getTranslations } from "next-intl/server"; -import { notFound } from "next/navigation"; -import { authOptions } from "@formbricks/lib/authOptions"; -import { IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants"; -import { getOrganizationByEnvironmentId } from "@formbricks/lib/organization/service"; - -export const metadata: Metadata = { - title: "Billing", -}; - -const BillingLayout = async (props) => { - const params = await props.params; - - const { children } = props; - - const t = await getTranslations(); - if (!IS_FORMBRICKS_CLOUD) { - notFound(); - } - - const session = await getServerSession(authOptions); - const organization = await getOrganizationByEnvironmentId(params.environmentId); - - if (!session) { - throw new Error(t("common.not_authorized")); - } - if (!organization) { - throw new Error(t("common.organization_not_found")); - } - - return <>{children}>; -}; - -export default BillingLayout; diff --git a/apps/web/app/api/billing/stripe-webhook/route.ts b/apps/web/app/api/billing/stripe-webhook/route.ts new file mode 100644 index 0000000000..7137441edb --- /dev/null +++ b/apps/web/app/api/billing/stripe-webhook/route.ts @@ -0,0 +1,3 @@ +import { POST } from "@/modules/ee/billing/api/route"; + +export { POST }; diff --git a/apps/web/app/(ee)/(billing)/environments/[environmentId]/settings/(organization)/billing/actions.ts b/apps/web/modules/ee/billing/actions.ts similarity index 89% rename from apps/web/app/(ee)/(billing)/environments/[environmentId]/settings/(organization)/billing/actions.ts rename to apps/web/modules/ee/billing/actions.ts index c7b9f57d41..ec62a483e0 100644 --- a/apps/web/app/(ee)/(billing)/environments/[environmentId]/settings/(organization)/billing/actions.ts +++ b/apps/web/modules/ee/billing/actions.ts @@ -1,11 +1,11 @@ "use server"; -import { createCustomerPortalSession } from "@/app/(ee)/(billing)/api/billing/stripe-webhook/lib/createCustomerPortalSession"; -import { createSubscription } from "@/app/(ee)/(billing)/api/billing/stripe-webhook/lib/createSubscription"; -import { isSubscriptionCancelled } from "@/app/(ee)/(billing)/api/billing/stripe-webhook/lib/isSubscriptionCancelled"; import { authenticatedActionClient } from "@/lib/utils/action-client"; import { checkAuthorizationUpdated } from "@/lib/utils/action-client-middleware"; import { getOrganizationIdFromEnvironmentId } from "@/lib/utils/helper"; +import { createCustomerPortalSession } from "@/modules/ee/billing/api/lib/create-customer-portal-session"; +import { createSubscription } from "@/modules/ee/billing/api/lib/create-subscription"; +import { isSubscriptionCancelled } from "@/modules/ee/billing/api/lib/is-subscription-cancelled"; import { z } from "zod"; import { STRIPE_PRICE_LOOKUP_KEYS } from "@formbricks/lib/constants"; import { WEBAPP_URL } from "@formbricks/lib/constants"; diff --git a/apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/checkoutSessionCompleted.ts b/apps/web/modules/ee/billing/api/lib/checkout-session-completed.ts similarity index 100% rename from apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/checkoutSessionCompleted.ts rename to apps/web/modules/ee/billing/api/lib/checkout-session-completed.ts diff --git a/apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/constants.ts b/apps/web/modules/ee/billing/api/lib/constants.ts similarity index 100% rename from apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/constants.ts rename to apps/web/modules/ee/billing/api/lib/constants.ts diff --git a/apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/createCustomerPortalSession.ts b/apps/web/modules/ee/billing/api/lib/create-customer-portal-session.ts similarity index 100% rename from apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/createCustomerPortalSession.ts rename to apps/web/modules/ee/billing/api/lib/create-customer-portal-session.ts diff --git a/apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/createSubscription.ts b/apps/web/modules/ee/billing/api/lib/create-subscription.ts similarity index 100% rename from apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/createSubscription.ts rename to apps/web/modules/ee/billing/api/lib/create-subscription.ts diff --git a/apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/invoiceFinalized.ts b/apps/web/modules/ee/billing/api/lib/invoice-finalized.ts similarity index 100% rename from apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/invoiceFinalized.ts rename to apps/web/modules/ee/billing/api/lib/invoice-finalized.ts diff --git a/apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/isSubscriptionCancelled.ts b/apps/web/modules/ee/billing/api/lib/is-subscription-cancelled.ts similarity index 100% rename from apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/isSubscriptionCancelled.ts rename to apps/web/modules/ee/billing/api/lib/is-subscription-cancelled.ts diff --git a/apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/stripeWebhook.ts b/apps/web/modules/ee/billing/api/lib/stripe-webhook.ts similarity index 75% rename from apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/stripeWebhook.ts rename to apps/web/modules/ee/billing/api/lib/stripe-webhook.ts index f511e9da61..948ce1f3f2 100644 --- a/apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/stripeWebhook.ts +++ b/apps/web/modules/ee/billing/api/lib/stripe-webhook.ts @@ -1,10 +1,10 @@ +import { handleCheckoutSessionCompleted } from "@/modules/ee/billing/api/lib/checkout-session-completed"; +import { handleInvoiceFinalized } from "@/modules/ee/billing/api/lib/invoice-finalized"; +import { handleSubscriptionCreatedOrUpdated } from "@/modules/ee/billing/api/lib/subscription-created-or-updated"; +import { handleSubscriptionDeleted } from "@/modules/ee/billing/api/lib/subscription-deleted"; import Stripe from "stripe"; import { STRIPE_API_VERSION } from "@formbricks/lib/constants"; import { env } from "@formbricks/lib/env"; -import { handleCheckoutSessionCompleted } from "./checkoutSessionCompleted"; -import { handleInvoiceFinalized } from "./invoiceFinalized"; -import { handleSubscriptionCreatedOrUpdated } from "./subscriptionCreatedOrUpdated"; -import { handleSubscriptionDeleted } from "./subscriptionDeleted"; const stripe = new Stripe(env.STRIPE_SECRET_KEY!, { apiVersion: STRIPE_API_VERSION, diff --git a/apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/subscriptionCreatedOrUpdated.ts b/apps/web/modules/ee/billing/api/lib/subscription-created-or-updated.ts similarity index 100% rename from apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/subscriptionCreatedOrUpdated.ts rename to apps/web/modules/ee/billing/api/lib/subscription-created-or-updated.ts diff --git a/apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/subscriptionDeleted.ts b/apps/web/modules/ee/billing/api/lib/subscription-deleted.ts similarity index 100% rename from apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/lib/subscriptionDeleted.ts rename to apps/web/modules/ee/billing/api/lib/subscription-deleted.ts diff --git a/apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/route.ts b/apps/web/modules/ee/billing/api/route.ts similarity index 87% rename from apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/route.ts rename to apps/web/modules/ee/billing/api/route.ts index 3808e1e1a9..823ecab216 100644 --- a/apps/web/app/(ee)/(billing)/api/billing/stripe-webhook/route.ts +++ b/apps/web/modules/ee/billing/api/route.ts @@ -1,6 +1,6 @@ import { responses } from "@/app/lib/api/response"; +import { webhookHandler } from "@/modules/ee/billing/api/lib/stripe-webhook"; import { headers } from "next/headers"; -import { webhookHandler } from "./lib/stripeWebhook"; export const POST = async (request: Request) => { const body = await request.text(); diff --git a/packages/ui/components/BillingSlider/index.tsx b/apps/web/modules/ee/billing/components/billing-slider.tsx similarity index 100% rename from packages/ui/components/BillingSlider/index.tsx rename to apps/web/modules/ee/billing/components/billing-slider.tsx diff --git a/packages/ui/components/PricingCard/index.tsx b/apps/web/modules/ee/billing/components/pricing-card.tsx similarity index 94% rename from packages/ui/components/PricingCard/index.tsx rename to apps/web/modules/ee/billing/components/pricing-card.tsx index 5418a0e2fe..4230f4a6fa 100644 --- a/packages/ui/components/PricingCard/index.tsx +++ b/apps/web/modules/ee/billing/components/pricing-card.tsx @@ -3,9 +3,9 @@ import { useTranslations } from "next-intl"; import { useMemo, useState } from "react"; import { cn } from "@formbricks/lib/cn"; import { TOrganization, TOrganizationBillingPeriod } from "@formbricks/types/organizations"; -import { Badge } from "../Badge"; -import { Button } from "../Button"; -import { ConfirmationModal } from "../ConfirmationModal"; +import { Badge } from "@formbricks/ui/components/Badge"; +import { Button } from "@formbricks/ui/components/Button"; +import { ConfirmationModal } from "@formbricks/ui/components/ConfirmationModal"; interface PricingCardProps { plan: { @@ -139,7 +139,11 @@ export const PricingCard = ({ plan.featured ? "text-slate-900" : "text-slate-800", "text-4xl font-bold tracking-tight" )}> - {planPeriod === "monthly" ? t(plan.price.monthly) : t(plan.price.yearly)} + {plan.id !== productFeatureKeys.ENTERPRISE + ? planPeriod === "monthly" + ? plan.price.monthly + : plan.price.yearly + : t(plan.price.monthly)}
{plan.name !== "Enterprise" && (