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.
This commit is contained in:
Aman Agrawal
2025-09-08 13:54:08 +05:30
committed by Tim Abbott
parent 28a7507b8e
commit 203da5008a

View File

@@ -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