From 134a05ff5e43fe4e3c778cb4f32fbce3f0c49fc4 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 8 Dec 2023 01:45:11 +0000 Subject: [PATCH] billing: Hide license management fields for free trial states. * For free trial, don't show number of licenses for current billing period. * For free trial scheduled to downgrade, don't show number of licenses for next billing period. --- corporate/lib/stripe.py | 13 +++++++++++++ corporate/tests/test_stripe.py | 2 +- templates/corporate/billing.html | 4 +++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 6f3fa93183..2e69523ea8 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -1919,6 +1919,10 @@ class BillingSession(ABC): licenses = update_plan_request.licenses if licenses is not None: + if plan.is_free_trial(): # nocoverage + raise JsonableError( + _("Cannot update licenses in the current billing period for free trial plan.") + ) if plan.automanage_licenses: raise JsonableError( _( @@ -1952,6 +1956,15 @@ class BillingSession(ABC): "Unable to update licenses manually. Your plan is on automatic license management." ) ) + if plan.status in ( + CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE, + CustomerPlan.DOWNGRADE_AT_END_OF_FREE_TRIAL, + ): # nocoverage + raise JsonableError( + _( + "Cannot change the licenses for next billing cycle for a plan that is being downgraded." + ) + ) if last_ledger_entry.licenses_at_next_renewal == licenses_at_next_renewal: raise JsonableError( _( diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 01e8a57631..9935410cfb 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -1331,7 +1331,7 @@ class StripeTest(StripeTestCase): for substring in [ "Zulip Cloud Standard (free trial)", str(self.seat_count), - "Number of licenses for current billing period", + "Number of licenses for next billing period", f"{self.seat_count} in use", "Your next invoice is due on", "March 2, 2012", diff --git a/templates/corporate/billing.html b/templates/corporate/billing.html index 8fa89b3641..ea2447f6e6 100644 --- a/templates/corporate/billing.html +++ b/templates/corporate/billing.html @@ -104,6 +104,7 @@ {% else %} + {% if not (free_trial or downgrade_at_end_of_free_trial) %}
- {% if not downgrade_at_end_of_cycle %} + {% endif %} + {% if not (downgrade_at_end_of_cycle or downgrade_at_end_of_free_trial) %}