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");
|
2019-01-02 09:12:19 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const add_card_handler = StripeCheckout.configure({
|
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",
|
2020-07-20 22:18:43 +02:00
|
|
|
token(stripe_token) {
|
2021-04-09 12:43:44 +02:00
|
|
|
helpers.create_ajax_request("/json/billing/upgrade", "autopay", stripe_token);
|
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();
|
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;
|
|
|
|
}
|
|
|
|
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();
|
2021-04-09 12:43:44 +02:00
|
|
|
helpers.create_ajax_request("/json/billing/upgrade", "invoice");
|
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-04-09 12:43:44 +02:00
|
|
|
helpers.create_ajax_request("/json/billing/sponsorship", "sponsorship", 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
|
|
|
};
|
|
|
|
|
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
|
|
|
});
|