-
Notifications
You must be signed in to change notification settings - Fork 903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: downgrade team functionality when payment subscription has expired #2092
feat: downgrade team functionality when payment subscription has expired #2092
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ |
Thank you for following the naming conventions for pull request titles! 🙏 |
packages/ee/billing/lib/downgradePlan.tsInstead of calling the export const unsubscribeLinkSurveyProFeatures = async (teamId: string) => {
const productsOfTeam = await getProducts(teamId);
const productsToUpdate = productsOfTeam.filter(product => !product.linkSurveyBranding);
await Promise.all(productsToUpdate.map(product => updateProduct(product.id, { linkSurveyBranding: true })));
};
export const unsubscribeCoreAndAppSurveyFeatures = async (teamId: string) => {
const productsOfTeam = await getProducts(teamId);
const productsToUpdate = productsOfTeam.filter(product => !product.inAppSurveyBranding);
await Promise.all(productsToUpdate.map(product => updateProduct(product.id, { inAppSurveyBranding: true })));
};
packages/ee/billing/handlers/subscriptionDeleted.tsThere is a lot of repeated code in the const updateFeaturesAndUnsubscribe = async (teamId: string, featureKey: keyof typeof team.billing.features, unsubscribeFunction: Function) => {
updatedFeatures[featureKey].status = "inactive";
updatedFeatures[featureKey].unlimited = false;
await unsubscribeFunction(teamId);
}
// Then in your switch statement
switch (product.name) {
case StripeProductNames.inAppSurvey:
await updateFeaturesAndUnsubscribe(teamId, ProductFeatureKeys.inAppSurvey, unsubscribeCoreAndAppSurveyFeatures);
break;
case StripeProductNames.linkSurvey:
await updateFeaturesAndUnsubscribe(teamId, ProductFeatureKeys.linkSurvey, unsubscribeLinkSurveyProFeatures);
break;
case StripeProductNames.userTargeting:
await updateFeaturesAndUnsubscribe(teamId, ProductFeatureKeys.userTargeting);
break;
}
|
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, | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code has been modified to collect all the products that need to be updated and then perform a batch update. This reduces the number of database calls and improves the performance of the code.
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, | |
}); | |
} | |
} | |
export const unsubscribeLinkSurveyProFeatures = async (teamId: string) => { | |
const productsOfTeam = await getProducts(teamId); | |
const productsToUpdate = productsOfTeam.filter(product => !product.linkSurveyBranding); | |
await Promise.all(productsToUpdate.map(product => updateProduct(product.id, { linkSurveyBranding: true }))); | |
}; | |
export const unsubscribeCoreAndAppSurveyFeatures = async (teamId: string) => { | |
const productsOfTeam = await getProducts(teamId); | |
const productsToUpdate = productsOfTeam.filter(product => !product.inAppSurveyBranding); | |
await Promise.all(productsToUpdate.map(product => updateProduct(product.id, { inAppSurveyBranding: true }))); | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ShubhamPalriwala thanks for adding the unsubscribe functionality 😊
What does this PR do?
Downgrades the team's ability to change Link Survey Branding & In App Branding when respective paid plans are downgraded in stripe ie end of month!
How should this be tested?
Checklist
Required
pnpm build
console.logs
git pull origin main
Appreciated