mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	billing: Deduplicate get_form_input in billing.js.
This commit is contained in:
		@@ -77,20 +77,26 @@ $(function () {
 | 
				
			|||||||
        return (cents / 100).toFixed(precision);
 | 
					        return (cents / 100).toFixed(precision);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    function get_form_input(form_name, input_name, stringify = true) {
 | 
				
			||||||
 | 
					        var input = $("#" + form_name + "-form input[name='" + input_name + "']");
 | 
				
			||||||
 | 
					        var val;
 | 
				
			||||||
 | 
					        if (input.attr('type') === "radio") {
 | 
				
			||||||
 | 
					            val =  $("#" + form_name + "-form input[name='" + input_name + "']:checked").val();
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            val = input.val();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (stringify) {
 | 
				
			||||||
 | 
					            return JSON.stringify(val);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return val;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (window.location.pathname === '/upgrade/') {
 | 
					    if (window.location.pathname === '/upgrade/') {
 | 
				
			||||||
        var add_card_handler = StripeCheckout.configure({ // eslint-disable-line no-undef
 | 
					        var add_card_handler = StripeCheckout.configure({ // eslint-disable-line no-undef
 | 
				
			||||||
            key: $("#autopay-form").data("key"),
 | 
					            key: $("#autopay-form").data("key"),
 | 
				
			||||||
            image: '/static/images/logo/zulip-icon-128x128.png',
 | 
					            image: '/static/images/logo/zulip-icon-128x128.png',
 | 
				
			||||||
            locale: 'auto',
 | 
					            locale: 'auto',
 | 
				
			||||||
            token: function (stripe_token) {
 | 
					            token: function (stripe_token) {
 | 
				
			||||||
                function get_form_input(name) {
 | 
					 | 
				
			||||||
                    var input = $("#autopay-form input[name='" + name + "']");
 | 
					 | 
				
			||||||
                    if (input.attr('type') === "radio") {
 | 
					 | 
				
			||||||
                        return JSON.stringify($("#autopay-form input[name='" + name + "']:checked").val());
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    return JSON.stringify(input.val());
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                loading.make_indicator($('#autopay_loading_indicator'),
 | 
					                loading.make_indicator($('#autopay_loading_indicator'),
 | 
				
			||||||
                                       {text: 'Processing ...', abs_positioned: true});
 | 
					                                       {text: 'Processing ...', abs_positioned: true});
 | 
				
			||||||
                $("#autopay-input-section").hide();
 | 
					                $("#autopay-input-section").hide();
 | 
				
			||||||
@@ -101,10 +107,10 @@ $(function () {
 | 
				
			|||||||
                    data: {
 | 
					                    data: {
 | 
				
			||||||
                        stripe_token: JSON.stringify(stripe_token.id),
 | 
					                        stripe_token: JSON.stringify(stripe_token.id),
 | 
				
			||||||
                        csrfmiddlewaretoken: $("#autopay-form input[name='csrf']").val(),
 | 
					                        csrfmiddlewaretoken: $("#autopay-form input[name='csrf']").val(),
 | 
				
			||||||
                        signed_seat_count: get_form_input("signed_seat_count"),
 | 
					                        signed_seat_count: get_form_input("autopay", "signed_seat_count"),
 | 
				
			||||||
                        salt: get_form_input("salt"),
 | 
					                        salt: get_form_input("autopay", "salt"),
 | 
				
			||||||
                        plan: get_form_input("plan"),
 | 
					                        plan: get_form_input("autopay", "plan"),
 | 
				
			||||||
                        billing_modality: get_form_input("billing_modality"),
 | 
					                        billing_modality: get_form_input("autopay", "billing_modality"),
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                    success: function () {
 | 
					                    success: function () {
 | 
				
			||||||
                        $("#autopay-loading").hide();
 | 
					                        $("#autopay-loading").hide();
 | 
				
			||||||
@@ -140,14 +146,6 @@ $(function () {
 | 
				
			|||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            e.preventDefault();
 | 
					            e.preventDefault();
 | 
				
			||||||
 | 
					 | 
				
			||||||
            function get_form_input(name, stringify = true) {
 | 
					 | 
				
			||||||
                var value = $("#invoice-form input[name='" + name + "']").val();
 | 
					 | 
				
			||||||
                if (stringify) {
 | 
					 | 
				
			||||||
                    value = JSON.stringify(value);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                return value;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            loading.make_indicator($('#invoice_loading_indicator'),
 | 
					            loading.make_indicator($('#invoice_loading_indicator'),
 | 
				
			||||||
                                   {text: 'Processing ...', abs_positioned: true});
 | 
					                                   {text: 'Processing ...', abs_positioned: true});
 | 
				
			||||||
            $("#invoice-input-section").hide();
 | 
					            $("#invoice-input-section").hide();
 | 
				
			||||||
@@ -156,12 +154,12 @@ $(function () {
 | 
				
			|||||||
            $.post({
 | 
					            $.post({
 | 
				
			||||||
                url: "/json/billing/upgrade",
 | 
					                url: "/json/billing/upgrade",
 | 
				
			||||||
                data: {
 | 
					                data: {
 | 
				
			||||||
                    csrfmiddlewaretoken: get_form_input("csrfmiddlewaretoken", false),
 | 
					                    csrfmiddlewaretoken: get_form_input("invoice", "csrfmiddlewaretoken", false),
 | 
				
			||||||
                    signed_seat_count: get_form_input("signed_seat_count"),
 | 
					                    signed_seat_count: get_form_input("invoice", "signed_seat_count"),
 | 
				
			||||||
                    salt: get_form_input("salt"),
 | 
					                    salt: get_form_input("invoice", "salt"),
 | 
				
			||||||
                    plan: get_form_input("plan"),
 | 
					                    plan: get_form_input("invoice", "plan"),
 | 
				
			||||||
                    billing_modality: get_form_input("billing_modality"),
 | 
					                    billing_modality: get_form_input("invoice", "billing_modality"),
 | 
				
			||||||
                    invoiced_seat_count: get_form_input("invoiced_seat_count", false),
 | 
					                    invoiced_seat_count: get_form_input("invoice", "invoiced_seat_count", false),
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                success: function () {
 | 
					                success: function () {
 | 
				
			||||||
                    $("#invoice-loading").hide();
 | 
					                    $("#invoice-loading").hide();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user