Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
billing: Show sponsorship message for organization on STANDARD_FREE.
Vishnu KSd3c7277f7765
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.pyindex 752fc098637..32abc25aa8f 100644--- a/corporate/tests/test_stripe.py+++ b/corporate/tests/test_stripe.py@@ -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 /upgraderesponse = 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)diff --git a/corporate/views.py b/corporate/views.pyindex affa89333b1..6b1751cf3a0 100644--- a/corporate/views.py+++ b/corporate/views.py@@ -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.usercustomer = 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"] = Truereturn 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()diff --git a/templates/corporate/billing.html b/templates/corporate/billing.htmlindex b2796bbfb14..efb6116c9a9 100644--- a/templates/corporate/billing.html+++ b/templates/corporate/billing.html@@ -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>