mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-29 09:50:10 -06:00
feat: $199 pricing model for unlimited plans (#1564)
This commit is contained in:
committed by
GitHub
parent
2dc03505fc
commit
6d6987d2bc
@@ -23,8 +23,7 @@ export async function upgradePlanAction(
|
||||
if (!isAuthorized) throw new AuthorizationError("Not authorized");
|
||||
|
||||
const subscriptionSession = await createSubscription(teamId, environmentId, priceLookupKeys);
|
||||
|
||||
return subscriptionSession.url;
|
||||
return subscriptionSession;
|
||||
}
|
||||
|
||||
export async function manageSubscriptionAction(teamId: string, environmentId: string) {
|
||||
|
||||
@@ -50,13 +50,18 @@ export default function PricingTableComponent({
|
||||
const upgradePlan = async (priceLookupKeys: StripePriceLookupKeys[]) => {
|
||||
try {
|
||||
setUpgradingPlan(true);
|
||||
const paymentUrl = await upgradePlanAction(team.id, environmentId, priceLookupKeys);
|
||||
const { status, newPlan, url } = await upgradePlanAction(team.id, environmentId, priceLookupKeys);
|
||||
setUpgradingPlan(false);
|
||||
if (!paymentUrl || paymentUrl === "") {
|
||||
if (status != 200) {
|
||||
throw new Error("Something went wrong");
|
||||
}
|
||||
if (!newPlan) {
|
||||
toast.success("Plan upgraded successfully");
|
||||
router.refresh();
|
||||
} else if (newPlan && url) {
|
||||
router.push(url);
|
||||
} else {
|
||||
router.push(paymentUrl);
|
||||
throw new Error("Something went wrong");
|
||||
}
|
||||
} catch (err) {
|
||||
toast.error("Unable to upgrade plan");
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
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";
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { StripePriceLookupKeys } from "@formbricks/ee/billing/lib/constants";
|
||||
|
||||
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.inAppSurveyUnlimited,
|
||||
StripePriceLookupKeys.linkSurveyUnlimited,
|
||||
StripePriceLookupKeys.userTargetingUnlimited,
|
||||
]);
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -69,15 +69,18 @@ export const handleCheckoutSessionCompleted = async (event: Stripe.Event) => {
|
||||
}
|
||||
}
|
||||
|
||||
await stripe.customers.update(stripeCustomer.id, {
|
||||
name: team.name,
|
||||
metadata: { team: team.id },
|
||||
});
|
||||
|
||||
await updateTeam(team.id, {
|
||||
billing: {
|
||||
stripeCustomerId: stripeCustomer.id,
|
||||
features: updatedFeatures,
|
||||
},
|
||||
});
|
||||
|
||||
await stripe.customers.update(stripeCustomer.id, {
|
||||
name: team.name,
|
||||
metadata: { team: team.id },
|
||||
invoice_settings: {
|
||||
default_payment_method: stripeSubscriptionObject.default_payment_method as string,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ export enum StripePriceLookupKeys {
|
||||
inAppSurvey = "inAppSurvey",
|
||||
linkSurvey = "linkSurvey",
|
||||
userTargeting = "userTargeting",
|
||||
inAppSurveyUnlimited = "survey-unlimited-30102023",
|
||||
linkSurveyUnlimited = "linkSurvey-unlimited-30102023",
|
||||
userTargetingUnlimited = "userTargeting-unlimited-30102023",
|
||||
inAppSurveyUnlimited = "survey-unlimited-03112023",
|
||||
linkSurveyUnlimited = "linkSurvey-unlimited-03112023",
|
||||
userTargetingUnlimited = "userTargeting-unlimited-03112023",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user