From 203da5008a0ea7e7b84e7a96818632c007856abe Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Mon, 8 Sep 2025 13:54:08 +0530 Subject: [PATCH] stripe: Fix licenses not updated to latest seat count after trial ends. Since we are forward dating the LicenseLedger entry user initially paid for, we need to create the new LicenseLedger entry with current license count so that user can be billed for the difference in licenses. --- corporate/lib/stripe.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index ab0945e924..5217eb188a 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -2319,6 +2319,16 @@ class BillingSession(ABC): microsecond=0 ) last_renewal_ledger_entry.save(update_fields=["event_time"]) + # Since we are skipping over processing license ledger + # entries / RealmAuditLogs that are after `last_renewal_ledger_entry`, + # we need to update `licenses_at_next_renewal` to reflect the current value. + # It is okay to skip over them here since they were in free trial. + licenses_at_next_renewal = max( + self.get_billable_licenses_for_customer( + plan.customer, plan.tier, licenses_at_next_renewal + ), + licenses_at_next_renewal, + ) else: # We end the free trial since customer hasn't paid. plan.status = CustomerPlan.DOWNGRADE_AT_END_OF_FREE_TRIAL