Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
billing: Inline is_realm_on_paid_plan.
Tim Abbott7de061cf10bc
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex 87f6cff19fd..ad81fac01d2 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -79,11 +79,6 @@ CARD_CAPITALIZATION = {"visa": "Visa",}-PAID_PLANS = [- Realm.PLAN_TYPE_STANDARD,- Realm.PLAN_TYPE_PLUS,-]-# The version of Stripe API the billing system supports.STRIPE_API_VERSION = "2020-08-27"@@ -212,10 +207,6 @@ def check_upgrade_parameters()-def is_realm_on_paid_plan(realm: Realm) -> bool:- return realm.plan_type in PAID_PLANS--# Be extremely careful changing this function. Historical billing periods# are not stored anywhere, and are just computed on the fly using this# function. Any change you make here should return the same value (or be@@ -1636,6 +1627,11 @@ class RealmBillingSession(BillingSession):assert realm is not None # for mypyself.realm = realm+ PAID_PLANS = [+ Realm.PLAN_TYPE_STANDARD,+ Realm.PLAN_TYPE_PLUS,+ ]+@override@propertydef billing_session_url(self) -> str:@@ -1861,7 +1857,7 @@ class RealmBillingSession(BillingSession):@overridedef on_paid_plan(self) -> bool:- return is_realm_on_paid_plan(self.realm)+ return self.realm.plan_type in self.PAID_PLANS@overridedef add_sponsorship_info_to_context(self, context: Dict[str, Any]) -> None:diff --git a/corporate/views/billing_page.py b/corporate/views/billing_page.pyindex 6cf35a7e835..d0aee6691ff 100644--- a/corporate/views/billing_page.py+++ b/corporate/views/billing_page.py@@ -5,7 +5,7 @@ from django.http import HttpRequest, HttpResponse, HttpResponseRedirectfrom django.shortcuts import renderfrom django.urls import reverse-from corporate.lib.stripe import RealmBillingSession, UpdatePlanRequest, is_realm_on_paid_plan+from corporate.lib.stripe import RealmBillingSession, UpdatePlanRequestfrom corporate.models import CustomerPlan, get_customer_by_realmfrom zerver.decorator import require_billing_access, zulip_login_requiredfrom zerver.lib.request import REQ, has_request_variables@@ -39,6 +39,11 @@ def billing_home(user = request.userassert user.is_authenticated+ # BUG: This should pass the acting_user; this is just working+ # around that make_end_of_cycle_updates_if_needed doesn't do audit+ # logging not using the session user properly.+ billing_session = RealmBillingSession(user=None, realm=user.realm)+context: Dict[str, Any] = {"admin_access": user.has_billing_access,"has_active_plan": False,@@ -54,7 +59,7 @@ def billing_home(customer = get_customer_by_realm(user.realm)if customer is not None and customer.sponsorship_pending:# Don't redirect to sponsorship page if the realm is on a paid plan- if not is_realm_on_paid_plan(user.realm):+ if not billing_session.on_paid_plan():return HttpResponseRedirect(reverse("sponsorship_request"))# If the realm is on a paid plan, show the sponsorship pending message# TODO: Add a sponsorship pending message to the billing page@@ -73,7 +78,6 @@ def billing_home(return HttpResponseRedirect(reverse(upgrade_page))- billing_session = RealmBillingSession(user=None, realm=user.realm)main_context = billing_session.get_billing_page_context()if main_context:context.update(main_context)