2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "../page_params";
|
|
|
|
|
2021-02-28 01:28:31 +01:00
|
|
|
import * as helpers from "./helpers";
|
|
|
|
|
2021-02-10 17:12:09 +01:00
|
|
|
export const initialize = () => {
|
2019-01-02 09:44:45 +01:00
|
|
|
helpers.set_tab("upgrade");
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#add-card-button").on("click", (e) => {
|
|
|
|
const license_management = $("input[type=radio][name=license_management]:checked").val();
|
2021-02-03 23:23:32 +01:00
|
|
|
if (
|
|
|
|
helpers.is_valid_input($(`#${CSS.escape(license_management)}_license_count`)) === false
|
|
|
|
) {
|
2019-01-02 09:12:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
2021-08-29 15:33:29 +02:00
|
|
|
const success_callback = (response) => {
|
|
|
|
window.location.replace(response.stripe_session_url);
|
|
|
|
};
|
|
|
|
helpers.create_ajax_request(
|
|
|
|
"/json/billing/upgrade",
|
|
|
|
"autopay",
|
|
|
|
[],
|
|
|
|
"POST",
|
|
|
|
success_callback,
|
|
|
|
);
|
2019-01-02 09:12:19 +01:00
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#invoice-button").on("click", (e) => {
|
2019-01-29 18:28:50 +01:00
|
|
|
if (helpers.is_valid_input($("#invoiced_licenses")) === false) {
|
2019-01-02 09:12:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
2021-08-29 15:33:29 +02:00
|
|
|
helpers.create_ajax_request("/json/billing/upgrade", "invoice", [], "POST", () =>
|
2020-09-03 15:34:20 +02:00
|
|
|
window.location.replace("/billing"),
|
|
|
|
);
|
2019-01-02 09:12:19 +01:00
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#sponsorship-button").on("click", (e) => {
|
2020-07-31 16:55:55 +02:00
|
|
|
if (!helpers.is_valid_input($("#sponsorship-form"))) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-09 12:24:32 +02:00
|
|
|
e.preventDefault();
|
2021-08-29 15:33:29 +02:00
|
|
|
helpers.create_ajax_request("/json/billing/sponsorship", "sponsorship", [], "POST", () =>
|
|
|
|
window.location.replace("/"),
|
2020-12-30 19:00:49 +01:00
|
|
|
);
|
2020-06-09 12:24:32 +02:00
|
|
|
});
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const prices = {};
|
2019-01-02 09:12:19 +01:00
|
|
|
prices.annual = page_params.annual_price * (1 - page_params.percent_off / 100);
|
|
|
|
prices.monthly = page_params.monthly_price * (1 - page_params.percent_off / 100);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("input[type=radio][name=license_management]").on("change", function () {
|
2019-01-30 13:59:19 +01:00
|
|
|
helpers.show_license_section(this.value);
|
2019-01-02 09:12:19 +01:00
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("input[type=radio][name=schedule]").on("change", function () {
|
2019-01-30 13:59:19 +01:00
|
|
|
helpers.update_charged_amount(prices, this.value);
|
2019-01-02 09:12:19 +01:00
|
|
|
});
|
|
|
|
|
2021-07-19 03:36:52 +02:00
|
|
|
$("select[name=organization-type]").on("change", (e) => {
|
|
|
|
const string_value = $(e.currentTarget).find(":selected").attr("data-string-value");
|
|
|
|
helpers.update_discount_details(string_value);
|
2020-06-09 12:24:32 +02:00
|
|
|
});
|
|
|
|
|
2019-01-02 09:12:19 +01:00
|
|
|
$("#autopay_annual_price").text(helpers.format_money(prices.annual));
|
|
|
|
$("#autopay_annual_price_per_month").text(helpers.format_money(prices.annual / 12));
|
|
|
|
$("#autopay_monthly_price").text(helpers.format_money(prices.monthly));
|
|
|
|
$("#invoice_annual_price").text(helpers.format_money(prices.annual));
|
|
|
|
$("#invoice_annual_price_per_month").text(helpers.format_money(prices.annual / 12));
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
helpers.show_license_section($("input[type=radio][name=license_management]:checked").val());
|
|
|
|
helpers.update_charged_amount(prices, $("input[type=radio][name=schedule]:checked").val());
|
2019-01-02 09:12:19 +01:00
|
|
|
};
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$(() => {
|
2021-02-10 17:12:09 +01:00
|
|
|
initialize();
|
2019-01-02 09:12:19 +01:00
|
|
|
});
|