mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-06 16:24:08 -06:00
feat: downgrade team functionality when payment subscription has expired (#2092)
This commit is contained in:
committed by
GitHub
parent
eadf63b47e
commit
6ae782b984
@@ -3,6 +3,7 @@ import Stripe from "stripe";
|
||||
import { getTeam, updateTeam } from "@formbricks/lib/team/service";
|
||||
|
||||
import { ProductFeatureKeys, StripeProductNames } from "../lib/constants";
|
||||
import { unsubscribeCoreAndAppSurveyFeatures, unsubscribeLinkSurveyProFeatures } from "../lib/downgradePlan";
|
||||
|
||||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
|
||||
// https://github.com/stripe/stripe-node#configuration
|
||||
@@ -31,12 +32,14 @@ export const handleSubscriptionDeleted = async (event: Stripe.Event) => {
|
||||
"inactive";
|
||||
updatedFeatures[ProductFeatureKeys.inAppSurvey as keyof typeof team.billing.features].unlimited =
|
||||
false;
|
||||
await unsubscribeCoreAndAppSurveyFeatures(teamId);
|
||||
break;
|
||||
case StripeProductNames.linkSurvey:
|
||||
updatedFeatures[ProductFeatureKeys.linkSurvey as keyof typeof team.billing.features].status =
|
||||
"inactive";
|
||||
updatedFeatures[ProductFeatureKeys.linkSurvey as keyof typeof team.billing.features].unlimited =
|
||||
false;
|
||||
await unsubscribeLinkSurveyProFeatures(teamId);
|
||||
break;
|
||||
case StripeProductNames.userTargeting:
|
||||
updatedFeatures[ProductFeatureKeys.userTargeting as keyof typeof team.billing.features].status =
|
||||
|
||||
23
packages/ee/billing/lib/downgradePlan.ts
Normal file
23
packages/ee/billing/lib/downgradePlan.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { getProducts, updateProduct } from "@formbricks/lib/product/service";
|
||||
|
||||
export const unsubscribeLinkSurveyProFeatures = async (teamId: string) => {
|
||||
const productsOfTeam = await getProducts(teamId);
|
||||
for (const product of productsOfTeam) {
|
||||
if (!product.linkSurveyBranding) {
|
||||
await updateProduct(product.id, {
|
||||
linkSurveyBranding: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const unsubscribeCoreAndAppSurveyFeatures = async (teamId: string) => {
|
||||
const productsOfTeam = await getProducts(teamId);
|
||||
for (const product of productsOfTeam) {
|
||||
if (!product.inAppSurveyBranding) {
|
||||
await updateProduct(product.id, {
|
||||
inAppSurveyBranding: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user