mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-11 17:19:33 -06:00
feat: 99 unlimited plan (#2137)
This commit is contained in:
committed by
GitHub
parent
df2cb9e26c
commit
6e2fa40155
@@ -26,9 +26,9 @@ export default async function UnlimitedPage({ params }) {
|
||||
}
|
||||
|
||||
const { status, newPlan, url } = await upgradePlanAction(team.id, params.environmentId, [
|
||||
StripePriceLookupKeys.inAppSurveyUnlimited,
|
||||
StripePriceLookupKeys.linkSurveyUnlimited,
|
||||
StripePriceLookupKeys.userTargetingUnlimited,
|
||||
StripePriceLookupKeys.inAppSurveyUnlimitedPlan90,
|
||||
StripePriceLookupKeys.linkSurveyUnlimitedPlan19,
|
||||
StripePriceLookupKeys.userTargetingUnlimitedPlan90,
|
||||
]);
|
||||
if (status != 200) {
|
||||
throw new Error("Something went wrong");
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { getServerSession } from "next-auth";
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
|
||||
import { StripePriceLookupKeys } from "@formbricks/ee/billing/lib/constants";
|
||||
import { authOptions } from "@formbricks/lib/authOptions";
|
||||
import { IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants";
|
||||
import { getTeamByEnvironmentId } from "@formbricks/lib/team/service";
|
||||
|
||||
import { upgradePlanAction } from "../actions";
|
||||
|
||||
export default async function UnlimitedPage({ params }) {
|
||||
if (!IS_FORMBRICKS_CLOUD) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
const team = await getTeamByEnvironmentId(params.environmentId);
|
||||
|
||||
if (!session) {
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
|
||||
if (!team) {
|
||||
throw new Error("Team not found");
|
||||
}
|
||||
|
||||
const { status, newPlan, url } = await upgradePlanAction(team.id, params.environmentId, [
|
||||
StripePriceLookupKeys.inAppSurveyUnlimitedPlan33,
|
||||
StripePriceLookupKeys.linkSurveyUnlimitedPlan33,
|
||||
StripePriceLookupKeys.userTargetingUnlimitedPlan33,
|
||||
]);
|
||||
if (status != 200) {
|
||||
throw new Error("Something went wrong");
|
||||
}
|
||||
if (newPlan && url) {
|
||||
redirect(url);
|
||||
} else if (!newPlan) {
|
||||
redirect(`/billing-confirmation?environmentId=${params.environmentId}`);
|
||||
} else {
|
||||
throw new Error("Something went wrong");
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,10 @@ export const handleCheckoutSessionCompleted = async (event: Stripe.Event) => {
|
||||
switch (product.name) {
|
||||
case StripeProductNames.inAppSurvey:
|
||||
updatedFeatures.inAppSurvey.status = "active";
|
||||
if (item.price.lookup_key === StripePriceLookupKeys.inAppSurveyUnlimited) {
|
||||
const isInAppSurveyUnlimited =
|
||||
item.price.lookup_key === StripePriceLookupKeys.inAppSurveyUnlimitedPlan90 ||
|
||||
item.price.lookup_key === StripePriceLookupKeys.inAppSurveyUnlimitedPlan33;
|
||||
if (isInAppSurveyUnlimited) {
|
||||
updatedFeatures.inAppSurvey.unlimited = true;
|
||||
} else {
|
||||
const countForTeam = await getMonthlyTeamResponseCount(team.id);
|
||||
@@ -50,14 +53,20 @@ export const handleCheckoutSessionCompleted = async (event: Stripe.Event) => {
|
||||
|
||||
case StripeProductNames.linkSurvey:
|
||||
updatedFeatures.linkSurvey.status = "active";
|
||||
if (item.price.lookup_key === StripePriceLookupKeys.linkSurveyUnlimited) {
|
||||
const isLinkSurveyUnlimited =
|
||||
item.price.lookup_key === StripePriceLookupKeys.linkSurveyUnlimitedPlan19 ||
|
||||
item.price.lookup_key === StripePriceLookupKeys.linkSurveyUnlimitedPlan33;
|
||||
if (isLinkSurveyUnlimited) {
|
||||
updatedFeatures.linkSurvey.unlimited = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case StripeProductNames.userTargeting:
|
||||
updatedFeatures.userTargeting.status = "active";
|
||||
if (item.price.lookup_key === StripePriceLookupKeys.userTargetingUnlimited) {
|
||||
const isUserTargetingUnlimited =
|
||||
item.price.lookup_key === StripePriceLookupKeys.userTargetingUnlimitedPlan90 ||
|
||||
item.price.lookup_key === StripePriceLookupKeys.userTargetingUnlimitedPlan33;
|
||||
if (isUserTargetingUnlimited) {
|
||||
updatedFeatures.userTargeting.unlimited = true;
|
||||
} else {
|
||||
const countForTeam = await getMonthlyActiveTeamPeopleCount(team.id);
|
||||
|
||||
@@ -68,7 +68,9 @@ export const handleSubscriptionUpdatedOrCreated = async (event: Stripe.Event) =>
|
||||
|
||||
switch (product.name) {
|
||||
case StripeProductNames.inAppSurvey:
|
||||
const isInAppSurveyUnlimited = item.price.lookup_key === StripePriceLookupKeys.inAppSurveyUnlimited;
|
||||
const isInAppSurveyUnlimited =
|
||||
item.price.lookup_key === StripePriceLookupKeys.inAppSurveyUnlimitedPlan90 ||
|
||||
item.price.lookup_key === StripePriceLookupKeys.inAppSurveyUnlimitedPlan33;
|
||||
|
||||
// If the current subscription is scheduled to cancel at the end of the period
|
||||
if (stripeSubscriptionObject.cancel_at_period_end) {
|
||||
@@ -105,7 +107,9 @@ export const handleSubscriptionUpdatedOrCreated = async (event: Stripe.Event) =>
|
||||
break;
|
||||
|
||||
case StripeProductNames.linkSurvey:
|
||||
const isLinkSurveyUnlimited = item.price.lookup_key === StripePriceLookupKeys.linkSurveyUnlimited;
|
||||
const isLinkSurveyUnlimited =
|
||||
item.price.lookup_key === StripePriceLookupKeys.linkSurveyUnlimitedPlan19 ||
|
||||
item.price.lookup_key === StripePriceLookupKeys.linkSurveyUnlimitedPlan33;
|
||||
|
||||
if (stripeSubscriptionObject.cancel_at_period_end) {
|
||||
const isLinkSurveyScheduled = await isProductScheduled(
|
||||
@@ -130,7 +134,8 @@ export const handleSubscriptionUpdatedOrCreated = async (event: Stripe.Event) =>
|
||||
|
||||
case StripeProductNames.userTargeting:
|
||||
const isUserTargetingUnlimited =
|
||||
item.price.lookup_key === StripePriceLookupKeys.userTargetingUnlimited;
|
||||
item.price.lookup_key === StripePriceLookupKeys.userTargetingUnlimitedPlan90 ||
|
||||
item.price.lookup_key === StripePriceLookupKeys.userTargetingUnlimitedPlan33;
|
||||
|
||||
if (stripeSubscriptionObject.cancel_at_period_end) {
|
||||
const isUserTargetingScheduled = await isProductScheduled(
|
||||
|
||||
@@ -13,7 +13,11 @@ export enum StripePriceLookupKeys {
|
||||
inAppSurvey = "inAppSurvey",
|
||||
linkSurvey = "linkSurvey",
|
||||
userTargeting = "userTargeting",
|
||||
inAppSurveyUnlimited = "survey-unlimited-03112023",
|
||||
linkSurveyUnlimited = "linkSurvey-unlimited-03112023",
|
||||
userTargetingUnlimited = "userTargeting-unlimited-03112023",
|
||||
inAppSurveyUnlimitedPlan90 = "survey-unlimited-03112023",
|
||||
linkSurveyUnlimitedPlan19 = "linkSurvey-unlimited-03112023",
|
||||
userTargetingUnlimitedPlan90 = "userTargeting-unlimited-03112023",
|
||||
|
||||
inAppSurveyUnlimitedPlan33 = "survey-unlimited-33-27022024",
|
||||
linkSurveyUnlimitedPlan33 = "linkSurvey-unlimited-33-27022024",
|
||||
userTargetingUnlimitedPlan33 = "userTargeting-unlimited-33-27022024",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user