PPv2: Fix continue button behaviour (#2821)

Co-authored-by: Richard Schreiber <wiffbi@gmail.com>
This commit is contained in:
Julian Rother
2022-12-20 16:09:42 +01:00
committed by GitHub
parent eeb6e11934
commit f0c5e54e34

View File

@@ -73,12 +73,21 @@ var pretixpaypal = {
pretixpaypal.locale = this.guessLocale();
}
// If no payment option is selected, and we're not on the paypage (which doesn't have a continue button),
// disable the continue button
if (!pretixpaypal.paypage) {
if (!pretixpaypal.continue_button[0].form.elements['payment'].value) {
$("input[name=payment][value^='paypal']").change(function () {
if (pretixpaypal.paypal !== null) {
pretixpaypal.renderButton($(this).val());
} else {
pretixpaypal.continue_button.prop("disabled", true);
}
});
$("input[name=payment]").not("[value^='paypal']").change(function () {
pretixpaypal.restore();
});
// If paypal is pre-selected, we must disable the continue button and handle it after SDK is loaded
if ($("input[name=payment][value^='paypal']").is(':checked')) {
pretixpaypal.continue_button.prop("disabled", true);
}
// We are setting the cogwheel already here, as the renderAPM() method might take some time to get loaded.
@@ -139,14 +148,6 @@ var pretixpaypal = {
pretixpaypal.renderAPMs();
}
$("input[name=payment][value^='paypal']").change(function () {
pretixpaypal.renderButton($(this).val());
});
$("input[name=payment]").not("[value^='paypal']").change(function () {
pretixpaypal.restore();
});
if ($("input[name=payment][value^='paypal']").is(':checked')) {
pretixpaypal.renderButton($("input[name=payment][value^='paypal']:checked").val());
} else if ($(".payment-redo-form").length) {
@@ -162,8 +163,8 @@ var pretixpaypal = {
$('#paypal-button-container').empty()
pretixpaypal.continue_button.text(gettext('Continue'));
pretixpaypal.continue_button.show();
pretixpaypal.continue_button.prop("disabled", false);
}
pretixpaypal.continue_button.prop("disabled", false);
},
renderButton: function (method) {
@@ -321,6 +322,15 @@ var pretixpaypal = {
};
$(function () {
// This script is always loaded if paypal is enabled as a payment method, regardless of
// whether it is available (it could e.g. be hidden or limited to certain countries).
// We do not want to unnecessarily load the sdk.
// If no paypal/paypal_apm payment option is present and we are not on
// the (APM) PayView, then we do not need the SDK.
if (!$("input[name=payment][value^='paypal']").length && !$('#paypal-button-container').data('paypage')) {
return
}
pretixpaypal.load();
(async() => {