Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PayPal popup infinite loading spinner if T&Cs are not checked #2659

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,41 @@ define(
let paypalConfiguration = Object.assign(baseComponentConfiguration, paymentMethodsExtraInfo[paymentMethod.type].configuration);
paypalConfiguration.showPayButton = true;

/*
* Add onInit and onClick functions to the configuration object in order to maange the PayPal Buttons
* state (enabled / disabled) depending on the checkout agreements checkbox state.
*
* Without these functions, if the form is not valid (checkbox unchecked) and the user clicks on the
* PayPal button, the popup will be opened with an infinite loading spinner, and even if the customer
* closes the popup, checks the checkbox and clicks again on the PayPal button, the popup will not work
* anymore, until the page is reloaded.
*/
let checkoutAgreementsInput = document.querySelector('.checkout-agreement input');

if (null !== checkoutAgreementsInput) {
let self = this;

paypalConfiguration.onInit = function (data, actions) {
actions.disable();

document.querySelector('.form-checkout-agreements input')
.addEventListener('change', function (event) {
// Enable or disable the button when it is checked or unchecked
if (event.target.checked) {
actions.enable();
} else {
actions.disable();
}
});
};

paypalConfiguration.onClick = function (data, actions) {
// Trigger the form validation in order to display potential error messages if the buttons
// have been disabled.
self.validate();
};
}

return paypalConfiguration
},
renderActionComponent: function(resultCode, action, component) {
Expand Down