|
|
|
/*
|
|
|
|
* 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_child_row").click(function () {
|
|
|
|
$.get("parts/template_child_entry.php", {}, function (resp) {
|
|
|
|
$("#child_list").append(resp);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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` <div>.
|
|
|
|
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 = $("#membershipform");
|
|
|
|
|
|
|
|
if (form[0].checkValidity() === false) {
|
|
|
|
event.preventDefault()
|
|
|
|
event.stopPropagation()
|
|
|
|
}
|
|
|
|
form.addClass('was-validated');
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#membershipform").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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|