2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-02-28 01:28:31 +01:00
|
|
|
import * as helpers from "./helpers";
|
|
|
|
|
2020-12-23 17:08:27 +01:00
|
|
|
export function create_update_license_request() {
|
|
|
|
helpers.create_ajax_request(
|
|
|
|
"/json/billing/plan",
|
|
|
|
"licensechange",
|
|
|
|
["licenses_at_next_renewal"],
|
|
|
|
"PATCH",
|
2020-09-03 15:34:20 +02:00
|
|
|
() => window.location.replace("/billing"),
|
2020-12-23 17:08:27 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-10 17:11:54 +01:00
|
|
|
export function initialize() {
|
2019-01-02 09:44:45 +01:00
|
|
|
helpers.set_tab("billing");
|
2018-11-25 08:02:51 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#update-card-button").on("click", (e) => {
|
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/session/start_card_update_session",
|
|
|
|
"cardchange",
|
|
|
|
[],
|
|
|
|
"POST",
|
|
|
|
success_callback,
|
|
|
|
);
|
2019-01-02 09:12:19 +01:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
2020-04-24 17:38:13 +02:00
|
|
|
|
2020-12-23 17:08:27 +01:00
|
|
|
$("#update-licenses-button").on("click", (e) => {
|
|
|
|
if (helpers.is_valid_input($("#new_licenses_input")) === false) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
const current_licenses = $("#licensechange-input-section").data("licenses");
|
|
|
|
const new_licenses = $("#new_licenses_input").val();
|
|
|
|
if (new_licenses > current_licenses) {
|
|
|
|
$("#new_license_count_holder").text(new_licenses);
|
|
|
|
$("#current_license_count_holder").text(current_licenses);
|
|
|
|
$("#confirm-licenses-modal").modal("show");
|
|
|
|
} else {
|
|
|
|
create_update_license_request();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#confirm-license-update-button").on("click", () => {
|
|
|
|
create_update_license_request();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#update-licenses-at-next-renewal-button").on("click", (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
helpers.create_ajax_request(
|
|
|
|
"/json/billing/plan",
|
|
|
|
"licensechange",
|
|
|
|
["licenses"],
|
|
|
|
"PATCH",
|
2020-09-03 15:34:20 +02:00
|
|
|
() => window.location.replace("/billing"),
|
2020-12-23 17:08:27 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#change-plan-status").on("click", (e) => {
|
2021-08-29 15:33:29 +02:00
|
|
|
helpers.create_ajax_request("/json/billing/plan", "planchange", [], "PATCH", () =>
|
|
|
|
window.location.replace("/billing"),
|
2020-12-10 18:15:09 +01:00
|
|
|
);
|
2020-04-24 17:38:13 +02:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
2021-02-10 17:11:54 +01:00
|
|
|
}
|
2018-12-21 18:44:24 +01:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$(() => {
|
2021-02-10 17:11:54 +01:00
|
|
|
initialize();
|
2018-09-06 15:14:54 +02:00
|
|
|
});
|