/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ $("#add_camper").click(function () { var copyfrom = $("#camper_list .person-list-item").first(); $.get("parts/template_person.php", { type: "camper", lastname: $("input[name=lastname]", copyfrom).val(), parentname: $("input[name=parentname]", copyfrom).val(), address: $("input[name=address]", copyfrom).val(), zip: $("input[name=zip]", copyfrom).val(), phone1: $("input[name=phone1]", copyfrom).val(), phone2: $("input[name=phone2]", copyfrom).val(), email: $("input[name=email]", copyfrom).val(), unit: $("input[name=unit]", copyfrom).val() }, function (resp) { $("#camper_list").append(resp); updateTotal(); }); }); $("#add_adult").click(function () { var copyfrom = $("#adult_list .person-list-item").first(); $.get("parts/template_person.php", { type: "adult", lastname: $("input[name=lastname]", copyfrom).val(), address: $("input[name=address]", copyfrom).val(), zip: $("input[name=zip]", copyfrom).val(), phone1: $("input[name=phone1]", copyfrom).val(), phone2: $("input[name=phone2]", copyfrom).val(), email: $("input[name=email]", copyfrom).val() }, function (resp) { $("#adult_list").append(resp); updateTotal(); }); }); $("#add_youth").click(function () { var copyfrom = $("#youth_list .person-list-item").first(); $.get("parts/template_person.php", { type: "youth", lastname: $("input[name=lastname]", copyfrom).val(), address: $("input[name=address]", copyfrom).val(), zip: $("input[name=zip]", copyfrom).val(), parentname: $("input[name=parentname]", copyfrom).val(), phone2: $("input[name=phone2]", copyfrom).val(), email: $("input[name=email]", copyfrom).val() }, function (resp) { $("#youth_list").append(resp); updateTotal(); }); }); $("#camper_list").on("change", "input[name=firstname]", function () { updateTotal(); }); $("#adult_list").on("change", "input[name=days]", function () { updateTotal(); }); function updateTotal() { totalcharge = $(".person-list-item[data-persontype=camper] input[name=firstname]").filter(function () { return $(this).val() != ''; }).length * 50.0; totalcharge = totalcharge - $(".person-list-item[data-persontype=adult] input[name=days]:checked").filter(function () { return $(this).val() != ''; }).length * 10.0; totalcharge = Math.max(totalcharge, 0); // The server will refuse to finish the registration if this doesn't match // the backend-calculated amount, don't bother being a haxxor $("#total").text(totalcharge); $("input[name=totalcharge]").val(totalcharge); } // Create a Stripe client. var stripe = Stripe(stripe_pubkey); // Create an instance of Elements. var elements = stripe.elements(); // Create an instance of the card Element. var card = elements.create('card'); // Add an instance of the card Element into the `card-element`
. card.mount('#card-element'); card.addEventListener('change', function (event) { if (event.error) { $("#card-errors").removeClass("d-none"); $("#card-errors").text(event.error.message); } else { $("#card-errors").addClass("d-none"); $("#card-errors").text(""); } }); $("#savebutton").click(function (event) { var form = $("#registrationform"); console.log("Validating..."); if (form[0].checkValidity() === false) { console.log("Invalid!"); event.preventDefault(); event.stopPropagation(); } form.addClass('was-validated'); }); $("#registrationform").on("submit", function (event) { event.preventDefault(); // prevent multiple clicks since Stripe can take a few seconds $("#savebutton").prop("disabled", true); $("#savebutton-text").addClass("d-none"); $("#savebutton-wait").removeClass("d-none"); stripe.createToken(card).then(function (result) { if (result.error) { // Inform the customer that there was an error. $("#card-errors").removeClass("d-none"); $("#card-errors").text(event.error.message); $("#savebutton").prop("disabled", false); $("#savebutton-text").removeClass("d-none"); $("#savebutton-wait").addClass("d-none"); } else { $("#stripe-token").val(result.token.id); console.log(result.token); document.getElementById('membershipform').submit(); } }); });