billing: Show appropriate message when not on a paid plan.

This commit is contained in:
Vishnu KS 2020-04-03 19:47:34 +05:30 committed by Tim Abbott
parent dc4d88f6c9
commit 3f94195d51
3 changed files with 46 additions and 24 deletions

View File

@ -21,7 +21,8 @@ from django.utils.timezone import now as timezone_now
import stripe import stripe
from zerver.lib.actions import do_deactivate_user, do_create_user, \ 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_classes import ZulipTestCase
from zerver.lib.test_helpers import reset_emails_in_zulip_realm from zerver.lib.test_helpers import reset_emails_in_zulip_realm
from zerver.lib.timestamp import timestamp_to_datetime, datetime_to_timestamp 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") @patch("corporate.lib.stripe.billing_logger.info")
def test_deactivate_realm(self, mock_: Mock) -> None: def test_deactivate_realm(self, mock_: Mock) -> None:
user = self.example_user("hamlet") user = self.example_user("hamlet")
self.login_user(user)
with patch("corporate.lib.stripe.timezone_now", return_value=self.now): with patch("corporate.lib.stripe.timezone_now", return_value=self.now):
self.local_upgrade(self.seat_count, True, CustomerPlan.ANNUAL, 'token') self.local_upgrade(self.seat_count, True, CustomerPlan.ANNUAL, 'token')
@ -1004,11 +1004,18 @@ class StripeTest(StripeTestCase):
do_deactivate_realm(get_realm("zulip")) do_deactivate_realm(get_realm("zulip"))
plan.refresh_from_db() plan.refresh_from_db()
self.assertTrue(get_realm('zulip').deactivated)
self.assertEqual(get_realm('zulip').plan_type, Realm.LIMITED) self.assertEqual(get_realm('zulip').plan_type, Realm.LIMITED)
self.assertEqual(plan.status, CustomerPlan.ENDED) self.assertEqual(plan.status, CustomerPlan.ENDED)
self.assertEqual(plan.invoiced_through, last_ledger_entry) self.assertEqual(plan.invoiced_through, last_ledger_entry)
self.assertIsNone(plan.next_invoice_date) 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 <b>Zulip Free</b>"], response)
# The extra users added in the final month are not charged # The extra users added in the final month are not charged
with patch("corporate.lib.stripe.invoice_plan") as mocked: with patch("corporate.lib.stripe.invoice_plan") as mocked:
invoice_plans_as_needed(self.next_month) invoice_plans_as_needed(self.next_month)

View File

@ -159,15 +159,11 @@ def billing_home(request: HttpRequest) -> HttpResponse:
if not user.is_realm_admin and not user.is_billing_admin: if not user.is_realm_admin and not user.is_billing_admin:
context = {'admin_access': False} # type: Dict[str, Any] context = {'admin_access': False} # type: Dict[str, Any]
return render(request, 'corporate/billing.html', context=context) return render(request, 'corporate/billing.html', context=context)
context = {'admin_access': True}
plan_name = "Zulip Free" context = {
licenses = 0 'admin_access': True,
licenses_used = 0 'has_active_plan': False,
renewal_date = '' }
renewal_cents = 0
payment_method = ''
charge_automatically = False
plan = get_current_plan_by_customer(customer) plan = get_current_plan_by_customer(customer)
if plan is not None: if plan is not None:
@ -190,17 +186,19 @@ def billing_home(request: HttpRequest) -> HttpResponse:
else: else:
payment_method = 'Billed by invoice' payment_method = 'Billed by invoice'
context.update({ context.update({
'plan_name': plan_name, 'plan_name': plan_name,
'licenses': licenses, 'has_active_plan': True,
'licenses_used': licenses_used, 'licenses': licenses,
'renewal_date': renewal_date, 'licenses_used': licenses_used,
'renewal_amount': '{:,.2f}'.format(renewal_cents / 100.), 'renewal_date': renewal_date,
'payment_method': payment_method, 'renewal_amount': '{:,.2f}'.format(renewal_cents / 100.),
'charge_automatically': charge_automatically, 'payment_method': payment_method,
'publishable_key': STRIPE_PUBLISHABLE_KEY, 'charge_automatically': charge_automatically,
'stripe_email': stripe_customer.email, 'publishable_key': STRIPE_PUBLISHABLE_KEY,
}) 'stripe_email': stripe_customer.email,
})
return render(request, 'corporate/billing.html', context=context) return render(request, 'corporate/billing.html', context=context)
@require_billing_access @require_billing_access

View File

@ -19,7 +19,7 @@
<div class="main"> <div class="main">
<div class="alert alert-danger" id="error-message-box"></div> <div class="alert alert-danger" id="error-message-box"></div>
<h1>{{ _("Billing") }}</h1> <h1>{{ _("Billing") }}</h1>
{% if admin_access %} {% if admin_access and has_active_plan %}
<ul class="nav nav-tabs" id="billing-tabs"> <ul class="nav nav-tabs" id="billing-tabs">
<li class="active"><a data-toggle="tab" href="#overview">Overview</a></li> <li class="active"><a data-toggle="tab" href="#overview">Overview</a></li>
<li><a data-toggle="tab" href="#payment-method">Payment Method</a></li> <li><a data-toggle="tab" href="#payment-method">Payment Method</a></li>
@ -69,14 +69,31 @@
<div class="tab-pane" id="loading"> <div class="tab-pane" id="loading">
</div> </div>
</div> </div>
<div class="support-link"> <div class="support-link">
<p> <p>
Contact <a href="mailto:support@zulipchat.com">support@zulipchat.com</a> Contact <a href="mailto:support@zulipchat.com">support@zulipchat.com</a>
for billing history or to make changes to your subscription. for billing history or to make changes to your subscription.
</p> </p>
</div> </div>
{% elif admin_access and not has_active_plan %}
<div class="tab-content">
<center>
<p>
<h2>Your organization is on the <b>Zulip Free</b> plan.</h2>
<a href="/upgrade">
<button type="submit" class="button green">Upgrade to Standard</button>
</a>
<a href="/plans">
<button type="submit">View all plans</button>
</a>
</p>
</center>
</div>
<div class="support-link">
<p>
Contact <a href="mailto:support@zulipchat.com">support@zulipchat.com</a> for billing history.
</p>
</div>
{% else %} {% else %}
<p> <p>
You must be an organization administrator or a billing administrator to view this page. You must be an organization administrator or a billing administrator to view this page.