billing: Show sponsorship message for organization on STANDARD_FREE.

Fixes #16180
This commit is contained in:
Vishnu KS 2020-08-21 12:45:43 +00:00 committed by Tim Abbott
parent 31a5e0b441
commit d3c7277f77
3 changed files with 42 additions and 16 deletions

View File

@ -1118,15 +1118,26 @@ class StripeTest(StripeTestCase):
response = self.client_get("/billing/")
self.assert_in_success_response(["You must be an organization owner or a billing administrator to view this page."], response)
user.realm.plan_type = Realm.STANDARD_FREE
user.realm.save()
self.login_user(self.example_user("hamlet"))
response = self.client_get("/billing/")
self.assert_in_success_response(["Your organization is fully sponsored and is on the <b>Zulip Standard</b>"], response)
def test_redirect_for_billing_home(self) -> None:
user = self.example_user("iago")
self.login_user(user)
# No Customer yet; check that we are redirected to /upgrade
response = self.client_get("/billing/")
self.assertEqual(response.status_code, 302)
self.assertEqual('/upgrade/', response.url)
# Customer, but no CustomerPlan; check that we are still redirected to /upgrade
user.realm.plan_type = Realm.STANDARD_FREE
user.realm.save()
response = self.client_get("/billing/")
self.assertEqual(response.status_code, 200)
user.realm.plan_type = Realm.LIMITED
user.realm.save()
Customer.objects.create(realm=user.realm, stripe_customer_id='cus_123')
response = self.client_get("/billing/")
self.assertEqual(response.status_code, 302)
@ -1135,11 +1146,18 @@ class StripeTest(StripeTestCase):
def test_redirect_for_upgrade_page(self) -> None:
user = self.example_user("iago")
self.login_user(user)
# No Customer yet;
response = self.client_get("/upgrade/")
self.assertEqual(response.status_code, 200)
# Customer, but no CustomerPlan;
user.realm.plan_type = Realm.STANDARD_FREE
user.realm.save()
response = self.client_get("/upgrade/")
self.assertEqual(response.status_code, 302)
self.assertEqual(response.url, "/billing/")
user.realm.plan_type = Realm.LIMITED
user.realm.save()
customer = Customer.objects.create(realm=user.realm, stripe_customer_id='cus_123')
response = self.client_get("/upgrade/")
self.assertEqual(response.status_code, 200)

View File

@ -154,13 +154,17 @@ def initial_upgrade(request: HttpRequest) -> HttpResponse:
if not settings.BILLING_ENABLED or user.is_guest:
return render(request, "404.html", status=404)
billing_page_url = reverse('corporate.views.billing_home')
customer = get_customer_by_realm(user.realm)
if customer is not None and (get_current_plan_by_customer(customer) is not None or customer.sponsorship_pending):
billing_page_url = reverse('corporate.views.billing_home')
if request.GET.get("onboarding") is not None:
billing_page_url = f"{billing_page_url}?onboarding=true"
return HttpResponseRedirect(billing_page_url)
if user.realm.plan_type == user.realm.STANDARD_FREE:
return HttpResponseRedirect(billing_page_url)
percent_off = Decimal(0)
if customer is not None and customer.default_discount is not None:
percent_off = customer.default_discount
@ -232,30 +236,28 @@ def sponsorship(request: HttpRequest, user: UserProfile,
def billing_home(request: HttpRequest) -> HttpResponse:
user = request.user
customer = get_customer_by_realm(user.realm)
context: Dict[str, Any] = {}
context: Dict[str, Any] = {
"admin_access": user.has_billing_access,
'has_active_plan': False,
}
if user.realm.plan_type == user.realm.STANDARD_FREE:
context["is_sponsored"] = True
return render(request, 'corporate/billing.html', context=context)
if customer is None:
return HttpResponseRedirect(reverse('corporate.views.initial_upgrade'))
if customer.sponsorship_pending:
if user.has_billing_access:
context = {"admin_access": True, "sponsorship_pending": True}
else:
context = {"admin_access": False}
context["sponsorship_pending"] = True
return render(request, 'corporate/billing.html', context=context)
if not CustomerPlan.objects.filter(customer=customer).exists():
return HttpResponseRedirect(reverse('corporate.views.initial_upgrade'))
if not user.has_billing_access:
context = {'admin_access': False}
return render(request, 'corporate/billing.html', context=context)
context = {
'admin_access': True,
'has_active_plan': False,
}
plan = get_current_plan_by_customer(customer)
if plan is not None:
now = timezone_now()

View File

@ -150,6 +150,12 @@
<div class="tab-content">
{% if sponsorship_pending %}
<h3>Your organization has requested sponsored or discounted hosting.</h3>
{% elif is_sponsored %}
<center>
<p>
<h3>💚 Your organization is fully sponsored and is on the <b>Zulip Standard</b> plan.</h3>
</p>
</center>
{% else %}
<center>
<p>