chore: move billing page under ee route (#3251)

Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
This commit is contained in:
Dhruwang Jariwala
2024-10-08 19:20:58 +05:30
committed by GitHub
parent 2bfea919fe
commit ba0adbfad3
17 changed files with 78 additions and 11 deletions

View File

@@ -2,7 +2,7 @@ Copyright (c) 2024 Formbricks GmbH
Portions of this software are licensed as follows:
- All content that resides under the "packages/ee/" directory of this repository, if that directory exists, is licensed under the license defined in "packages/ee/LICENSE".
- All content that resides under the "packages/ee/" & "apps/web/app/(ee)" directories of this repository, if these directories exist, is licensed under the license defined in "packages/ee/LICENSE".
- All content that resides under the "packages/js/", "packages/react-native/" and "packages/api/" directories of this repository, if that directories exist, is licensed under the "MIT" license as defined in the "LICENSE" files of these packages.
- All third party components incorporated into the Formbricks Software are licensed under the original license provided by the owner of the applicable component.
- Content outside of the above mentioned directories or restrictions above is available under the "AGPLv3" license as defined below.

View File

@@ -1,10 +1,10 @@
import Stripe from "stripe";
import { STRIPE_API_VERSION } from "@formbricks/lib/constants";
import { env } from "@formbricks/lib/env";
import { handleCheckoutSessionCompleted } from "../handlers/checkout-session-completed";
import { handleInvoiceFinalized } from "../handlers/invoice-finalized";
import { handleSubscriptionCreatedOrUpdated } from "../handlers/subscription-created-or-updated";
import { handleSubscriptionDeleted } from "../handlers/subscription-deleted";
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,

View File

@@ -1,6 +1,6 @@
import { responses } from "@/app/lib/api/response";
import { headers } from "next/headers";
import { webhookHandler } from "@formbricks/ee/billing/api/stripe-webhook";
import { webhookHandler } from "./lib/stripeWebhook";
export const POST = async (request: Request) => {
const body = await request.text();

View File

@@ -0,0 +1,67 @@
import { FormbricksClient } from "@/app/(app)/components/FormbricksClient";
import { EnvironmentLayout } from "@/app/(app)/environments/[environmentId]/components/EnvironmentLayout";
import EnvironmentStorageHandler from "@/app/(app)/environments/[environmentId]/components/EnvironmentStorageHandler";
import { PosthogIdentify } from "@/app/(app)/environments/[environmentId]/components/PosthogIdentify";
import { ResponseFilterProvider } from "@/app/(app)/environments/[environmentId]/components/ResponseFilterContext";
import { getServerSession } from "next-auth";
import { notFound, redirect } from "next/navigation";
import { authOptions } from "@formbricks/lib/authOptions";
import { hasUserEnvironmentAccess } from "@formbricks/lib/environment/auth";
import { getMembershipByUserIdOrganizationId } from "@formbricks/lib/membership/service";
import { getOrganizationByEnvironmentId } from "@formbricks/lib/organization/service";
import { getProductByEnvironmentId } from "@formbricks/lib/product/service";
import { getUser } from "@formbricks/lib/user/service";
import { AuthorizationError } from "@formbricks/types/errors";
import { ToasterClient } from "@formbricks/ui/components/ToasterClient";
const EnvLayout = async ({ children, params }) => {
const session = await getServerSession(authOptions);
if (!session || !session.user) {
return redirect(`/auth/login`);
}
const user = await getUser(session.user.id);
if (!user) {
throw new Error("User not found");
}
const hasAccess = await hasUserEnvironmentAccess(session.user.id, params.environmentId);
if (!hasAccess) {
throw new AuthorizationError("Not authorized");
}
const organization = await getOrganizationByEnvironmentId(params.environmentId);
if (!organization) {
throw new Error("Organization not found");
}
const product = await getProductByEnvironmentId(params.environmentId);
if (!product) {
throw new Error("Product not found");
}
const membership = await getMembershipByUserIdOrganizationId(session.user.id, organization.id);
if (!membership) return notFound();
return (
<>
<ResponseFilterProvider>
<PosthogIdentify
session={session}
user={user}
environmentId={params.environmentId}
organizationId={organization.id}
organizationName={organization.name}
organizationBilling={organization.billing}
/>
<FormbricksClient session={session} userEmail={user.email} />
<ToasterClient />
<EnvironmentStorageHandler environmentId={params.environmentId} />
<EnvironmentLayout environmentId={params.environmentId} session={session}>
{children}
</EnvironmentLayout>
</ResponseFilterProvider>
</>
);
};
export default EnvLayout;

View File

@@ -1,9 +1,9 @@
"use server";
import { createCustomerPortalSession } from "@/app/(ee)/api/billing/stripe-webhook/lib/createCustomerPortalSession";
import { createSubscription } from "@/app/(ee)/api/billing/stripe-webhook/lib/createSubscription";
import { isSubscriptionCancelled } from "@/app/(ee)/api/billing/stripe-webhook/lib/isSubscriptionCancelled";
import { z } from "zod";
import { createCustomerPortalSession } from "@formbricks/ee/billing/lib/create-customer-portal-session";
import { createSubscription } from "@formbricks/ee/billing/lib/create-subscription";
import { isSubscriptionCancelled } from "@formbricks/ee/billing/lib/is-subscription-cancelled";
import { authenticatedActionClient } from "@formbricks/lib/actionClient";
import { checkAuthorization } from "@formbricks/lib/actionClient/utils";
import { STRIPE_PRICE_LOOKUP_KEYS } from "@formbricks/lib/constants";

View File

@@ -1,14 +1,14 @@
"use client";
import { CLOUD_PRICING_DATA } from "@/app/(ee)/api/billing/stripe-webhook/lib/constants";
import {
isSubscriptionCancelledAction,
manageSubscriptionAction,
upgradePlanAction,
} from "@/app/(app)/environments/[environmentId]/settings/(organization)/billing/actions";
} from "@/app/(ee)/environments/[environmentId]/settings/(organization)/billing/actions";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
import toast from "react-hot-toast";
import { CLOUD_PRICING_DATA } from "@formbricks/ee/billing/lib/constants";
import { cn } from "@formbricks/lib/cn";
import { capitalizeFirstLetter } from "@formbricks/lib/utils/strings";
import { TOrganization, TOrganizationBillingPeriod } from "@formbricks/types/organizations";