Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: update quantity if updated
Marc Seitz4a92b6a7d5ec
diff --git a/lib/stripe/webhooks/customer-subscription-updated.ts b/lib/stripe/webhooks/customer-subscription-updated.tsindex 4c23e8c4..85d3e448 100644--- a/lib/stripe/webhooks/customer-subscription-updated.ts+++ b/lib/stripe/webhooks/customer-subscription-updated.ts@@ -53,8 +53,13 @@ export async function customerSubsciptionUpdated(const endsAt = new Date(subscriptionUpdated.current_period_end * 1000);const quantity = subscriptionUpdated.items.data[0].quantity;+ let teamPlan = team.plan;+ if (isOldAccount) {+ // remove +old from plan+ teamPlan = teamPlan.replace("+old", "");+ }// If a team upgrades/downgrades their subscription, update their plan- if (team.plan !== newPlan) {+ if (teamPlan !== newPlan) {// Choose the correct plan limitslet planLimits:| typeof PRO_PLAN_LIMITS@@ -86,4 +91,25 @@ export async function customerSubsciptionUpdated(},});}++ // If new account, and the plan is the same, but the quantity is different, update the quantity+ if (+ !isOldAccount &&+ teamPlan === newPlan &&+ (team.limits as any)?.users !== quantity+ ) {+ // Update the user limit in planLimits based on the subscription quantity+ const newLimits = team.limits as any;+ newLimits.users = quantity;+ await prisma.team.update({+ where: { stripeId },+ data: {+ plan: plan.slug,+ subscriptionId,+ startsAt,+ endsAt,+ limits: newLimits,+ },+ });+ }}