billing: Create is_sponsored_realm function.

This commit is contained in:
Vishnu KS 2020-10-14 22:15:57 +05:30 committed by Tim Abbott
parent cdf683e36f
commit 1eb83cbadc
3 changed files with 15 additions and 1 deletions

View File

@ -876,6 +876,10 @@ def approve_sponsorship(realm: Realm, *, acting_user: Optional[UserProfile]) ->
internal_send_private_message(notification_bot, billing_admin, message)
def is_sponsored_realm(realm: Realm) -> bool:
return realm.plan_type == Realm.STANDARD_FREE
def get_discount_for_realm(realm: Realm) -> Optional[Decimal]:
customer = get_customer_by_realm(realm)
if customer is not None:

View File

@ -38,6 +38,7 @@ from corporate.lib.stripe import (
invoice_plan,
invoice_plans_as_needed,
is_realm_on_free_trial,
is_sponsored_realm,
make_end_of_cycle_updates_if_needed,
next_month,
process_initial_upgrade,
@ -3005,6 +3006,14 @@ class BillingHelpersTest(ZulipTestCase):
plan.save(update_fields=["status"])
self.assertTrue(is_realm_on_free_trial(realm))
def test_is_sponsored_realm(self) -> None:
realm = get_realm("zulip")
self.assertFalse(is_sponsored_realm(realm))
realm.plan_type = Realm.STANDARD_FREE
realm.save()
self.assertTrue(is_sponsored_realm(realm))
class LicenseLedgerTest(StripeTestCase):
def test_add_plan_renewal_if_needed(self) -> None:

View File

@ -22,6 +22,7 @@ from corporate.lib.stripe import (
downgrade_at_the_end_of_billing_cycle,
downgrade_now_without_creating_additional_invoices,
get_latest_seat_count,
is_sponsored_realm,
make_end_of_cycle_updates_if_needed,
process_initial_upgrade,
renewal_amount,
@ -190,7 +191,7 @@ def initial_upgrade(request: HttpRequest) -> HttpResponse:
billing_page_url = f"{billing_page_url}?onboarding=true"
return HttpResponseRedirect(billing_page_url)
if user.realm.plan_type == user.realm.STANDARD_FREE:
if is_sponsored_realm(user.realm):
return HttpResponseRedirect(billing_page_url)
percent_off = Decimal(0)