Files
zulip/static/js/billing/upgrade.js
Anders Kaseorg 28f3dfa284 js: Automatically convert var to let and const in most files.
This commit was originally automatically generated using `tools/lint
--only=eslint --fix`.  It was then modified by tabbott to contain only
changes to a set of files that are unlikely to result in significant
merge conflicts with any open pull request, excluding about 20 files.
His plan is to merge the remaining changes with more precise care,
potentially involving merging parts of conflicting pull requests
before running the `eslint --fix` operation.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-11-03 12:42:39 -08:00

66 lines
2.5 KiB
JavaScript

exports.initialize = () => {
helpers.set_tab("upgrade");
const add_card_handler = StripeCheckout.configure({ // eslint-disable-line no-undef
key: $("#autopay-form").data("key"),
image: '/static/images/logo/zulip-icon-128x128.png',
locale: 'auto',
token: function (stripe_token) {
helpers.create_ajax_request("/json/billing/upgrade", "autopay", stripe_token = stripe_token);
},
});
$('#add-card-button').on('click', function (e) {
const license_management = $('input[type=radio][name=license_management]:checked').val();
if (helpers.is_valid_input($("#" + license_management + "_license_count")) === false) {
return;
}
add_card_handler.open({
name: 'Zulip',
zipCode: true,
billingAddress: true,
panelLabel: "Make payment",
email: $("#autopay-form").data("email"),
label: "Add card",
allowRememberMe: false,
description: "Zulip Cloud Standard",
});
e.preventDefault();
});
$("#invoice-button").on("click", function (e) {
if (helpers.is_valid_input($("#invoiced_licenses")) === false) {
return;
}
e.preventDefault();
helpers.create_ajax_request("/json/billing/upgrade", "invoice");
});
const prices = {};
prices.annual = page_params.annual_price * (1 - page_params.percent_off / 100);
prices.monthly = page_params.monthly_price * (1 - page_params.percent_off / 100);
$('input[type=radio][name=license_management]').on("change", function () {
helpers.show_license_section(this.value);
});
$('input[type=radio][name=schedule]').on("change", function () {
helpers.update_charged_amount(prices, this.value);
});
$("#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));
helpers.show_license_section($('input[type=radio][name=license_management]:checked').val());
helpers.update_charged_amount(prices, $('input[type=radio][name=schedule]:checked').val());
};
window.upgrade = exports;
$(function () {
exports.initialize();
});