2019-01-02 09:12:19 +01:00
|
|
|
exports.initialize = () => {
|
2019-01-02 09:44:45 +01:00
|
|
|
helpers.set_tab("upgrade");
|
2019-01-02 09:12:19 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const add_card_handler = StripeCheckout.configure({
|
|
|
|
// eslint-disable-line no-undef
|
2019-01-02 09:12:19 +01:00
|
|
|
key: $("#autopay-form").data("key"),
|
2020-07-15 01:29:15 +02:00
|
|
|
image: "/static/images/logo/zulip-icon-128x128.png",
|
|
|
|
locale: "auto",
|
2019-01-02 09:12:19 +01:00
|
|
|
token: function (stripe_token) {
|
2020-07-15 00:34:28 +02:00
|
|
|
helpers.create_ajax_request("/json/billing/upgrade", "autopay", stripe_token, [
|
|
|
|
"licenses",
|
|
|
|
]);
|
2019-01-02 09:12:19 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
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();
|
2019-01-29 18:28:50 +01:00
|
|
|
if (helpers.is_valid_input($("#" + license_management + "_license_count")) === false) {
|
2019-01-02 09:12:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
add_card_handler.open({
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "Zulip",
|
2019-01-02 09:12:19 +01:00
|
|
|
zipCode: true,
|
|
|
|
billingAddress: true,
|
|
|
|
panelLabel: "Make payment",
|
|
|
|
email: $("#autopay-form").data("email"),
|
|
|
|
label: "Add card",
|
|
|
|
allowRememberMe: false,
|
|
|
|
description: "Zulip Cloud Standard",
|
|
|
|
});
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
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();
|
2020-04-24 17:36:20 +02:00
|
|
|
helpers.create_ajax_request("/json/billing/upgrade", "invoice", undefined, ["licenses"]);
|
2019-01-02 09:12:19 +01:00
|
|
|
});
|
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$("#sponsorship-button").on("click", (e) => {
|
2020-06-09 12:24:32 +02:00
|
|
|
e.preventDefault();
|
2020-07-15 00:34:28 +02:00
|
|
|
helpers.create_ajax_request(
|
|
|
|
"/json/billing/sponsorship",
|
|
|
|
"sponsorship",
|
|
|
|
undefined,
|
|
|
|
undefined,
|
|
|
|
"/",
|
|
|
|
);
|
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
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("select[name=organization-type]").on("change", function () {
|
2020-06-09 12:24:32 +02:00
|
|
|
helpers.update_discount_details(this.value);
|
|
|
|
});
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.upgrade = exports;
|
2019-01-02 09:12:19 +01:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$(() => {
|
2019-10-25 09:45:13 +02:00
|
|
|
exports.initialize();
|
2019-01-02 09:12:19 +01:00
|
|
|
});
|