Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
billing: Allow legacy servers to cancel upgrade.
Aman Agrawal825986ac3adf
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex 37271e073ad..b96b93ab8ea 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -1869,7 +1869,14 @@ class BillingSession(ABC):if status is not None:if status == CustomerPlan.ACTIVE:assert plan.status < CustomerPlan.LIVE_STATUS_THRESHOLD- do_change_plan_status(plan, status)+ with transaction.atomic(): # nocoverage+ # Switch to a different plan was cancelled. We end the next plan+ # and set the current one as active.+ if plan.status == CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END:+ next_plan = self.get_next_plan(plan)+ assert next_plan is not None+ do_change_plan_status(next_plan, CustomerPlan.ENDED)+ do_change_plan_status(plan, status)elif status == CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE:assert not plan.is_free_trial()assert plan.status < CustomerPlan.LIVE_STATUS_THRESHOLDdiff --git a/corporate/views/billing_page.py b/corporate/views/billing_page.pyindex ab271f3031f..37b80ef662f 100644--- a/corporate/views/billing_page.py+++ b/corporate/views/billing_page.py@@ -169,9 +169,12 @@ def remote_server_billing_page(context["sponsorship_pending"] = Trueif (- billing_session.remote_server.plan_type == RemoteZulipServer.PLAN_TYPE_SELF_HOSTED- or customer is None+ customer is Noneor get_current_plan_by_customer(customer) is None+ or (+ billing_session.get_legacy_remote_server_new_plan_name(customer) is None+ and billing_session.remote_server.plan_type == RemoteZulipServer.PLAN_TYPE_SELF_HOSTED+ )):return HttpResponseRedirect(reverse(diff --git a/templates/corporate/billing.html b/templates/corporate/billing.htmlindex 08d568e25e7..8fa89b36410 100644--- a/templates/corporate/billing.html+++ b/templates/corporate/billing.html@@ -252,7 +252,7 @@<input name="status" type="hidden" value="{{ CustomerPlan.DOWNGRADE_AT_END_OF_FREE_TRIAL }}" />{% elif downgrade_at_end_of_free_trial %}<input name="status" type="hidden" value="{{ CustomerPlan.FREE_TRIAL }}" />- {% elif downgrade_at_end_of_cycle %}+ {% elif downgrade_at_end_of_cycle or is_server_on_legacy_plan %}<input name="status" type="hidden" value="{{ CustomerPlan.ACTIVE }}" />{% else %}<input name="status" type="hidden" value="{{ CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE }}" />@@ -392,4 +392,27 @@</div></div></div>+<div id="confirm-cancel-legacy-server-upgrade-modal" class="micromodal" aria-hidden="true">+ <div class="modal__overlay" tabindex="-1">+ <div class="modal__container" role="dialog" aria-modal="true" aria-labelledby="dialog_title">+ <header class="modal__header">+ <h1 class="modal__title dialog_heading">+ Downgrade?+ </h1>+ <button class="modal__close" aria-label="{{ _('Close modal') }}" data-micromodal-close></button>+ </header>+ <main class="modal__content">+ <p>+ Lose benefits?+ </p>+ </main>+ <footer class="modal__footer">+ <button class="modal__btn dialog_exit_button" aria-label="{{ '(Close this dialog window)' }}" data-micromodal-close>{{ _('Never mind') }}</button>+ <button class="modal__btn dialog_submit_button">+ <span>{{ _('Downgrade') }}</span>+ </button>+ </footer>+ </div>+ </div>+</div>{% endblock %}diff --git a/web/src/billing/billing.ts b/web/src/billing/billing.tsindex 0242cc59852..50aad680d10 100644--- a/web/src/billing/billing.ts+++ b/web/src/billing/billing.ts@@ -173,6 +173,26 @@ export function initialize(): void {portico_modals.open($modal.attr("id")!);});+ $("#cancel-legacy-server-upgrade").on("click", (e) => {+ e.preventDefault();+ portico_modals.open("confirm-cancel-legacy-server-upgrade-modal");+ });++ $("#confirm-cancel-legacy-server-upgrade-modal .dialog_submit_button").on("click", (e) => {+ helpers.create_ajax_request(+ `/json${billing_base_url}/billing/plan`,+ "planchange",+ [],+ "PATCH",+ () =>+ window.location.replace(+ `${billing_base_url}/upgrade/?success_message=` ++ encodeURIComponent("Your plan is no longer scheduled for an upgrade."),+ ),+ );+ e.preventDefault();+ });+$("#confirm-licenses-modal-increase, #confirm-licenses-modal-decrease").on("click",".dialog_submit_button",