Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
billing: Make plan cancel/renew work.
Aman Agrawal3d45e7ca6447
diff --git a/templates/corporate/billing.html b/templates/corporate/billing.htmlindex 8ca84f77f4b..eefad746a52 100644--- a/templates/corporate/billing.html+++ b/templates/corporate/billing.html@@ -118,8 +118,6 @@Your plan will be upgraded to <strong>{{ plan_name }}</strong> on <strong>{{ renewal_date }}</strong> for<strong>${{ renewal_amount }}</strong>.{% elif downgrade_at_end_of_cycle %}- Your plan will be downgraded to <strong>Zulip Free</strong> on <strong>{{ renewal_date }}</strong>.- {% elif switch_to_annual_at_end_of_cycle %}Your organization will be downgraded to <strong>Zulip Cloud Free</strong> at the end of the current billingperiod (<strong>{{ renewal_date }}</strong>). You will lose access to unlimited search history and<a href="/plans/">other features</a> of your current plan.@@ -146,7 +144,6 @@<div id="planchange-error" class="alert alert-danger"></div><div id="planchange-input-section">{% if free_trial %}- <input name="status" type="hidden" value="{{ CustomerPlan.ENDED }}" /><div class="end-free-trail"><p>End Free Trial and downgrade plan to <strong>Zulip Free</strong>.@@ -156,26 +153,32 @@<object class="loader billing-button-loader" type="image/svg+xml" data="{{ static('images/loading/loader-white.svg') }}"></object></button></div>- {% else %}- {% if downgrade_at_end_of_cycle %}- <input name="status" type="hidden" value="{{ CustomerPlan.ACTIVE }}" />- <div class="reactivate-current-plan plan-toggle-action input-box billing-page-field no-validation">+ {% elif downgrade_at_end_of_cycle %}+ <div class="reactivate-current-plan plan-toggle-action input-box billing-page-field no-validation" id="reactivate-subscription"><button class="reactivate-current-plan-button plan-toggle-action-button"><span class="billing-button-text">Reactivate subscription</span><object class="loader billing-button-loader" type="image/svg+xml" data="{{ static('images/loading/loader-white.svg') }}"></object></button></div>- {% else %}- <input name="status" type="hidden" value="{{ CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE }}" />- <div class="cancel-current-plan plan-toggle-action input-box billing-page-field no-validation">+ {% else %}+ <div class="cancel-current-plan plan-toggle-action input-box billing-page-field no-validation" id="cancel-subscription"><button class="cancel-current-plan-button plan-toggle-action-button"><span class="billing-button-text">Cancel plan</span><object class="loader billing-button-loader" type="image/svg+xml" data="{{ static('images/loading/loader-white.svg') }}"></object></button></div>- {% endif %}{% endif %}</div>+ <form id="planchange-form">+ {% if free_trial %}+ <input name="status" type="hidden" value="{{ CustomerPlan.ENDED }}" />+ {% elif downgrade_at_end_of_cycle %}+ <input name="status" type="hidden" value="{{ CustomerPlan.ACTIVE }}" />+ {% else %}+ <input name="status" type="hidden" value="{{ CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE }}" />+ {% endif %}+ </form>+ <input name="status" type="hidden" value="{{ CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE }}" /><div id="planchange-success" class="alert alert-success billing-page-success">Plan updated. The page will now reload.</div>diff --git a/web/src/billing/billing.ts b/web/src/billing/billing.tsindex a36a5761d2c..d03f974b714 100644--- a/web/src/billing/billing.ts+++ b/web/src/billing/billing.ts@@ -7,29 +7,43 @@ import * as helpers from "./helpers";export function create_update_current_cycle_license_request(): void {$("#current-manual-license-count-update-button .billing-button-text").text("");$("#current-manual-license-count-update-button .loader").show();- helpers.create_ajax_request("/json/billing/plan", "current-license-change", [], "PATCH", () => {- window.location.replace("/billing/");- $("#licensechange-success").show();- $("#current-manual-license-count-update-button .loader").hide();- $("#current-manual-license-count-update-button .billing-button-text").text("Update");- }, () => {- $("#current-manual-license-count-update-button .loader").hide();- $("#current-manual-license-count-update-button .billing-button-text").text("Update");- });+ helpers.create_ajax_request(+ "/json/billing/plan",+ "current-license-change",+ [],+ "PATCH",+ () => {+ window.location.replace("/billing/");+ $("#licensechange-success").show();+ $("#current-manual-license-count-update-button .loader").hide();+ $("#current-manual-license-count-update-button .billing-button-text").text("Update");+ },+ () => {+ $("#current-manual-license-count-update-button .loader").hide();+ $("#current-manual-license-count-update-button .billing-button-text").text("Update");+ },+ );}export function create_update_next_cycle_license_request(): void {$("#next-manual-license-count-update-button .loader").show();$("#next-manual-license-count-update-button .billing-button-text").text("");- helpers.create_ajax_request("/json/billing/plan", "next-license-change", [], "PATCH", () => {- window.location.replace("/billing/");- $("#licensechange-success").show();- $("#next-manual-license-count-update-button .loader").hide();- $("#next-manual-license-count-update-button .billing-button-text").text("");- }, () => {- $("#next-manual-license-count-update-button .loader").hide();- $("#next-manual-license-count-update-button .billing-button-text").text("");- });+ helpers.create_ajax_request(+ "/json/billing/plan",+ "next-license-change",+ [],+ "PATCH",+ () => {+ window.location.replace("/billing/");+ $("#licensechange-success").show();+ $("#next-manual-license-count-update-button .loader").hide();+ $("#next-manual-license-count-update-button .billing-button-text").text("Update");+ },+ () => {+ $("#next-manual-license-count-update-button .loader").hide();+ $("#next-manual-license-count-update-button .billing-button-text").text("Update");+ },+ );}export function initialize(): void {@@ -46,10 +60,11 @@ export function initialize(): void {(response) => {const response_data = helpers.stripe_session_url_schema.parse(response);window.location.replace(response_data.stripe_session_url);- }, () => {+ },+ () => {$("#update-card-button .loader").hide();$("#update-card-button .billing-button-text").text("Update card");- }+ },);e.preventDefault();});@@ -125,7 +140,6 @@ export function initialize(): void {$("#confirm-licenses-modal .dialog_submit_button").on("click", () => {portico_modals.close("confirm-licenses-modal");if ($("#confirm-licenses-modal .dialog_submit_button").attr("data-cycle") === "current") {-create_update_current_cycle_license_request();} else if ($("#confirm-licenses-modal .dialog_submit_button").attr("data-cycle") === "next"@@ -134,12 +148,15 @@ export function initialize(): void {}});- $("#change-plan-status").on("click", (e) => {- helpers.create_ajax_request("/json/billing/plan", "planchange", [], "PATCH", () =>- window.location.replace("/billing/"),- );- e.preventDefault();- });+ $("#confirm-cancel-subscription-modal .dialog_submit_button, #reactivate-subscription").on(+ "click",+ (e) => {+ helpers.create_ajax_request("/json/billing/plan", "planchange", [], "PATCH", () =>+ window.location.replace("/billing/"),+ );+ e.preventDefault();+ },+ );$("#cancel-subscription").on("click", (e) => {e.preventDefault();