diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 6121936860..074906586f 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -785,6 +785,11 @@ def invoice_plans_as_needed(event_time: datetime = timezone_now()) -> None: invoice_plan(plan, event_time) +def is_realm_on_free_trial(realm: Realm) -> bool: + plan = get_current_plan_by_realm(realm) + return plan is not None and plan.is_free_trial() + + def attach_discount_to_realm( realm: Realm, discount: Decimal, *, acting_user: Optional[UserProfile] ) -> None: diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 18d31900ad..c6dccb95fb 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -35,6 +35,7 @@ from corporate.lib.stripe import ( get_realms_to_default_discount_dict, invoice_plan, invoice_plans_as_needed, + is_realm_on_free_trial, make_end_of_cycle_updates_if_needed, next_month, process_initial_upgrade, @@ -2969,6 +2970,24 @@ class BillingHelpersTest(ZulipTestCase): }, ) + def test_is_realm_on_free_trial(self) -> None: + realm = get_realm("zulip") + self.assertFalse(is_realm_on_free_trial(realm)) + + customer = Customer.objects.create(realm=realm, stripe_customer_id="cus_12345") + plan = CustomerPlan.objects.create( + customer=customer, + status=CustomerPlan.ACTIVE, + billing_cycle_anchor=timezone_now(), + billing_schedule=CustomerPlan.ANNUAL, + tier=CustomerPlan.STANDARD, + ) + self.assertFalse(is_realm_on_free_trial(realm)) + + plan.status = CustomerPlan.FREE_TRIAL + plan.save(update_fields=["status"]) + self.assertTrue(is_realm_on_free_trial(realm)) + class LicenseLedgerTest(StripeTestCase): def test_add_plan_renewal_if_needed(self) -> None: