diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 37271e073a..b96b93ab8e 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_THRESHOLD diff --git a/corporate/views/billing_page.py b/corporate/views/billing_page.py index ab271f3031..37b80ef662 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"] = True if ( - billing_session.remote_server.plan_type == RemoteZulipServer.PLAN_TYPE_SELF_HOSTED - or customer is None + customer is None or 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.html index 08d568e25e..8fa89b3641 100644 --- a/templates/corporate/billing.html +++ b/templates/corporate/billing.html @@ -252,7 +252,7 @@ {% elif downgrade_at_end_of_free_trial %} - {% elif downgrade_at_end_of_cycle %} + {% elif downgrade_at_end_of_cycle or is_server_on_legacy_plan %} {% else %} @@ -392,4 +392,27 @@ + {% endblock %} diff --git a/web/src/billing/billing.ts b/web/src/billing/billing.ts index 0242cc5985..50aad680d1 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",