From 3f94195d515e5d009222a41d0acbe03eaaf9abae Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Fri, 3 Apr 2020 19:47:34 +0530 Subject: [PATCH] billing: Show appropriate message when not on a paid plan. --- corporate/tests/test_stripe.py | 11 ++++++++-- corporate/views.py | 36 +++++++++++++++----------------- templates/corporate/billing.html | 23 +++++++++++++++++--- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 7719306dfd..de897c4621 100644 --- a/corporate/tests/test_stripe.py +++ b/corporate/tests/test_stripe.py @@ -21,7 +21,8 @@ from django.utils.timezone import now as timezone_now import stripe from zerver.lib.actions import do_deactivate_user, do_create_user, \ - do_activate_user, do_reactivate_user, do_deactivate_realm + do_activate_user, do_reactivate_user, do_deactivate_realm, \ + do_reactivate_realm from zerver.lib.test_classes import ZulipTestCase from zerver.lib.test_helpers import reset_emails_in_zulip_realm from zerver.lib.timestamp import timestamp_to_datetime, datetime_to_timestamp @@ -984,7 +985,6 @@ class StripeTest(StripeTestCase): @patch("corporate.lib.stripe.billing_logger.info") def test_deactivate_realm(self, mock_: Mock) -> None: user = self.example_user("hamlet") - self.login_user(user) with patch("corporate.lib.stripe.timezone_now", return_value=self.now): self.local_upgrade(self.seat_count, True, CustomerPlan.ANNUAL, 'token') @@ -1004,11 +1004,18 @@ class StripeTest(StripeTestCase): do_deactivate_realm(get_realm("zulip")) plan.refresh_from_db() + self.assertTrue(get_realm('zulip').deactivated) self.assertEqual(get_realm('zulip').plan_type, Realm.LIMITED) self.assertEqual(plan.status, CustomerPlan.ENDED) self.assertEqual(plan.invoiced_through, last_ledger_entry) self.assertIsNone(plan.next_invoice_date) + do_reactivate_realm(get_realm('zulip')) + + self.login_user(user) + response = self.client_get("/billing/") + self.assert_in_success_response(["Your organization is on the Zulip Free"], response) + # The extra users added in the final month are not charged with patch("corporate.lib.stripe.invoice_plan") as mocked: invoice_plans_as_needed(self.next_month) diff --git a/corporate/views.py b/corporate/views.py index 345f4bc1e3..7890011f27 100644 --- a/corporate/views.py +++ b/corporate/views.py @@ -159,15 +159,11 @@ def billing_home(request: HttpRequest) -> HttpResponse: if not user.is_realm_admin and not user.is_billing_admin: context = {'admin_access': False} # type: Dict[str, Any] return render(request, 'corporate/billing.html', context=context) - context = {'admin_access': True} - plan_name = "Zulip Free" - licenses = 0 - licenses_used = 0 - renewal_date = '' - renewal_cents = 0 - payment_method = '' - charge_automatically = False + context = { + 'admin_access': True, + 'has_active_plan': False, + } plan = get_current_plan_by_customer(customer) if plan is not None: @@ -190,17 +186,19 @@ def billing_home(request: HttpRequest) -> HttpResponse: else: payment_method = 'Billed by invoice' - context.update({ - 'plan_name': plan_name, - 'licenses': licenses, - 'licenses_used': licenses_used, - 'renewal_date': renewal_date, - 'renewal_amount': '{:,.2f}'.format(renewal_cents / 100.), - 'payment_method': payment_method, - 'charge_automatically': charge_automatically, - 'publishable_key': STRIPE_PUBLISHABLE_KEY, - 'stripe_email': stripe_customer.email, - }) + context.update({ + 'plan_name': plan_name, + 'has_active_plan': True, + 'licenses': licenses, + 'licenses_used': licenses_used, + 'renewal_date': renewal_date, + 'renewal_amount': '{:,.2f}'.format(renewal_cents / 100.), + 'payment_method': payment_method, + 'charge_automatically': charge_automatically, + 'publishable_key': STRIPE_PUBLISHABLE_KEY, + 'stripe_email': stripe_customer.email, + }) + return render(request, 'corporate/billing.html', context=context) @require_billing_access diff --git a/templates/corporate/billing.html b/templates/corporate/billing.html index fedb2954a5..d57e63edab 100644 --- a/templates/corporate/billing.html +++ b/templates/corporate/billing.html @@ -19,7 +19,7 @@

{{ _("Billing") }}

- {% if admin_access %} + {% if admin_access and has_active_plan %}
- - + {% elif admin_access and not has_active_plan %} +
+
+

+

Your organization is on the Zulip Free plan.

+ + + + + + +

+
+
+ {% else %}

You must be an organization administrator or a billing administrator to view this page.