mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
billing: Create is_realm_on_free_trial helper function.
This commit is contained in:
@@ -785,6 +785,11 @@ def invoice_plans_as_needed(event_time: datetime = timezone_now()) -> None:
|
|||||||
invoice_plan(plan, event_time)
|
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(
|
def attach_discount_to_realm(
|
||||||
realm: Realm, discount: Decimal, *, acting_user: Optional[UserProfile]
|
realm: Realm, discount: Decimal, *, acting_user: Optional[UserProfile]
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ from corporate.lib.stripe import (
|
|||||||
get_realms_to_default_discount_dict,
|
get_realms_to_default_discount_dict,
|
||||||
invoice_plan,
|
invoice_plan,
|
||||||
invoice_plans_as_needed,
|
invoice_plans_as_needed,
|
||||||
|
is_realm_on_free_trial,
|
||||||
make_end_of_cycle_updates_if_needed,
|
make_end_of_cycle_updates_if_needed,
|
||||||
next_month,
|
next_month,
|
||||||
process_initial_upgrade,
|
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):
|
class LicenseLedgerTest(StripeTestCase):
|
||||||
def test_add_plan_renewal_if_needed(self) -> None:
|
def test_add_plan_renewal_if_needed(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user