mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 18:30:32 -06:00
chore: Billing to new module structure (#4308)
This commit is contained in:
committed by
GitHub
parent
97377fe8bd
commit
23c9dc304a
@@ -0,0 +1,3 @@
|
||||
import { PricingPage } from "@/modules/ee/billing/page";
|
||||
|
||||
export default PricingPage;
|
||||
@@ -1,3 +0,0 @@
|
||||
import EnvLayout from "../../../../(app)/environments/[environmentId]/layout";
|
||||
|
||||
export default EnvLayout;
|
||||
@@ -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;
|
||||
3
apps/web/app/api/billing/stripe-webhook/route.ts
Normal file
3
apps/web/app/api/billing/stripe-webhook/route.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { POST } from "@/modules/ee/billing/api/route";
|
||||
|
||||
export { POST };
|
||||
@@ -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";
|
||||
@@ -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,
|
||||
@@ -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();
|
||||
@@ -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)}
|
||||
</p>
|
||||
{plan.name !== "Enterprise" && (
|
||||
<div className="text-sm leading-5">
|
||||
@@ -1,11 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { CLOUD_PRICING_DATA } from "@/app/(ee)/(billing)/api/billing/stripe-webhook/lib/constants";
|
||||
import {
|
||||
isSubscriptionCancelledAction,
|
||||
manageSubscriptionAction,
|
||||
upgradePlanAction,
|
||||
} from "@/app/(ee)/(billing)/environments/[environmentId]/settings/(organization)/billing/actions";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
@@ -14,9 +8,11 @@ import { cn } from "@formbricks/lib/cn";
|
||||
import { capitalizeFirstLetter } from "@formbricks/lib/utils/strings";
|
||||
import { TOrganization, TOrganizationBillingPeriod } from "@formbricks/types/organizations";
|
||||
import { Badge } from "@formbricks/ui/components/Badge";
|
||||
import { BillingSlider } from "@formbricks/ui/components/BillingSlider";
|
||||
import { Button } from "@formbricks/ui/components/Button";
|
||||
import { PricingCard } from "@formbricks/ui/components/PricingCard";
|
||||
import { isSubscriptionCancelledAction, manageSubscriptionAction, upgradePlanAction } from "../actions";
|
||||
import { CLOUD_PRICING_DATA } from "../api/lib/constants";
|
||||
import { BillingSlider } from "./billing-slider";
|
||||
import { PricingCard } from "./pricing-card";
|
||||
|
||||
interface PricingTableProps {
|
||||
organization: TOrganization;
|
||||
@@ -2,6 +2,7 @@ import { OrganizationSettingsNavbar } from "@/app/(app)/environments/[environmen
|
||||
import { getRoleManagementPermission } from "@/modules/ee/license-check/lib/utils";
|
||||
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 { PRODUCT_FEATURE_KEYS, STRIPE_PRICE_LOOKUP_KEYS } from "@formbricks/lib/constants";
|
||||
@@ -14,12 +15,17 @@ import {
|
||||
} from "@formbricks/lib/organization/service";
|
||||
import { PageContentWrapper } from "@formbricks/ui/components/PageContentWrapper";
|
||||
import { PageHeader } from "@formbricks/ui/components/PageHeader";
|
||||
import { PricingTable } from "./components/PricingTable";
|
||||
import { PricingTable } from "./components/pricing-table";
|
||||
|
||||
const Page = async (props) => {
|
||||
export const PricingPage = async (props) => {
|
||||
const params = await props.params;
|
||||
const t = await getTranslations();
|
||||
const organization = await getOrganizationByEnvironmentId(params.environmentId);
|
||||
|
||||
if (!IS_FORMBRICKS_CLOUD) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
if (!organization) {
|
||||
throw new Error(t("common.organization_not_found"));
|
||||
}
|
||||
@@ -64,5 +70,3 @@ const Page = async (props) => {
|
||||
</PageContentWrapper>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page;
|
||||
Reference in New Issue
Block a user