Improve Stripe.js loading

This commit is contained in:
Raphael Michel
2017-08-09 13:56:30 +02:00
parent b8704f980f
commit f02ec8b24b

View File

@@ -28,6 +28,7 @@ var pretixstripe = {
}); });
}, },
'load': function () { 'load': function () {
$('.stripe-container').closest("form").find(".btn-primary").prop("disabled", true);
$.ajax( $.ajax(
{ {
url: 'https://js.stripe.com/v3/', url: 'https://js.stripe.com/v3/',
@@ -59,11 +60,13 @@ var pretixstripe = {
}); });
pretixstripe.card.mount("#stripe-card"); pretixstripe.card.mount("#stripe-card");
} }
$('.stripe-container').closest("form").find(".btn-primary").prop("disabled", false);
} }
} }
); );
}, },
'load_checkout': function () { 'load_checkout': function () {
$('.stripe-container').closest("form").find(".btn-primary").prop("disabled", true);
$.ajax( $.ajax(
{ {
url: 'https://checkout.stripe.com/checkout.js', url: 'https://checkout.stripe.com/checkout.js',
@@ -85,6 +88,7 @@ var pretixstripe = {
allowRememberMe: false, allowRememberMe: false,
billingAddress: false billingAddress: false
}); });
$('.stripe-container').closest("form").find(".btn-primary").prop("disabled", false);
} }
} }
); );
@@ -106,21 +110,23 @@ var pretixstripe = {
'checkout_handler': null 'checkout_handler': null
}; };
$(function () { $(function () {
if (!$(".stripe-container").length) // Not on the checkout page if (!$(".stripe-container, #stripe-checkout").length) // Not on the checkout page
return; return;
if ($("input[name=payment][value=stripe]").is(':checked') || $(".payment-redo-form").length) { if ($("input[name=payment][value=stripe]").is(':checked') || $(".payment-redo-form").length) {
if ($("#stripe-checkout").length) { if ($("#stripe-checkout").length) {
pretixstripe.load_checkout(); pretixstripe.load_checkout();
} else {
pretixstripe.load();
} }
pretixstripe.load();
} else { } else {
$("input[name=payment]").change(function () { $("input[name=payment]").change(function () {
if ($(this).val() === 'stripe') { if ($(this).val() === 'stripe') {
if ($("#stripe-checkout").length) { if ($("#stripe-checkout").length) {
pretixstripe.load_checkout(); pretixstripe.load_checkout();
} else {
pretixstripe.load();
} }
pretixstripe.load();
} }
}) })
} }