Skip to content

Commit

Permalink
Improving code which was failing when T&C was disabled, Paypal orders…
Browse files Browse the repository at this point in the history
… cannot be made
  • Loading branch information
khushboo-singhvi authored Nov 21, 2024
1 parent fadf5fc commit 34200e8
Showing 1 changed file with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ define(
'Adyen_Payment/js/model/adyen-configuration',
'Magento_Checkout/js/model/full-screen-loader',
'Adyen_Payment/js/model/adyen-payment-service',
'Magento_Checkout/js/model/error-processor'
'Magento_Checkout/js/model/error-processor',
'Adyen_Payment/js/model/payment-component-states',
],
function(
$,
Expand All @@ -24,7 +25,8 @@ define(
adyenConfiguration,
fullScreenLoader,
adyenPaymentService,
errorProcessor
errorProcessor,
paymentComponentStates
) {
return adyenPaymentMethod.extend({
placeOrderButtonVisible: false,
Expand All @@ -38,22 +40,28 @@ define(
paypalConfiguration.showPayButton = true;
let agreementsConfig = adyenConfiguration.getAgreementsConfig();

if (null !== agreementsConfig) {
if (agreementsConfig && agreementsConfig.checkoutAgreements.isEnabled) {
let self = this;

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

$(document).off('change', '.checkout-agreements input').on('change', '.checkout-agreements input', function () {
self.updatePayPalButton(actions);
});
}
$(document).off('change', '.checkout-agreements input')
.on('change', '.checkout-agreements input', function () {
self.updatePayPalButton(actions);
});

} catch (error) {
console.warn("Error in onInit:", error.message);
}
};

paypalConfiguration.onClick = function (data, actions) {
if(!self.validate()) {
console.error('Agreements configuration failed');
}
}
};
}

return paypalConfiguration
Expand All @@ -79,6 +87,7 @@ define(
}
},
handleOnError: function (error, component) {
let self = this;
if ('test' === adyenConfiguration.getCheckoutEnvironment()) {
console.log("onError:",error);
}
Expand All @@ -102,13 +111,13 @@ define(
);
}).fail(function(response) {
fullScreenLoader.stopLoader();

if (this.popupModal) {
this.closeModal(this.popupModal);
}
errorProcessor.process(response,
this.currentMessageContainer);
this.isPlaceOrderAllowed(true);
this.showErrorMessage(response);
self.currentMessageContainer);
paymentComponentStates().setIsPlaceOrderAllowed(self.getMethodCode(), true);
});
}
})
Expand Down

0 comments on commit 34200e8

Please sign in to comment.