diff --git a/Model/Ui/AdyenGenericConfigProvider.php b/Model/Ui/AdyenGenericConfigProvider.php index bc6690ff6..b87919adc 100644 --- a/Model/Ui/AdyenGenericConfigProvider.php +++ b/Model/Ui/AdyenGenericConfigProvider.php @@ -18,6 +18,7 @@ use Magento\Framework\App\RequestInterface; use Magento\Framework\UrlInterface; use Magento\Store\Model\StoreManagerInterface; +use Magento\CheckoutAgreements\Model\AgreementsConfigProvider; class AdyenGenericConfigProvider implements ConfigProviderInterface { @@ -28,6 +29,7 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface protected RequestInterface $request; protected UrlInterface $url; private Config $adyenConfigHelper; + private AgreementsConfigProvider $agreementsConfigProvider; /** * This data member will be passed to the js frontend. It will be used to map the method code (adyen_ideal) to the * corresponding txVariant (ideal). The txVariant will then be used to instantiate the component @@ -45,6 +47,7 @@ public function __construct( StoreManagerInterface $storeManager, RequestInterface $request, UrlInterface $url, + AgreementsConfigProvider $agreementsConfigProvider, array $txVariants = [], array $customMethodRenderers = [] ) { @@ -53,6 +56,7 @@ public function __construct( $this->storeManager = $storeManager; $this->request = $request; $this->url = $url; + $this->agreementsConfigProvider = $agreementsConfigProvider; $this->txVariants = $txVariants; $this->customMethodRenderers = $customMethodRenderers; } @@ -88,6 +92,7 @@ public function getConfig(): array 'checkout/onepage/success', ['_secure' => $this->request->isSecure()] ); + $config['payment']['adyen']['agreementsConfig'] = $this->agreementsConfigProvider->getConfig(); return $config; } @@ -100,4 +105,4 @@ protected function showLogos(): bool } return false; } -} +} \ No newline at end of file diff --git a/view/frontend/web/js/model/adyen-configuration.js b/view/frontend/web/js/model/adyen-configuration.js index 7cb6443d5..7b96a8f61 100644 --- a/view/frontend/web/js/model/adyen-configuration.js +++ b/view/frontend/web/js/model/adyen-configuration.js @@ -42,6 +42,9 @@ define( getCustomerStreetLinesEnabled: function () { return window.checkoutConfig.payment.customerStreetLinesEnabled; }, + getAgreementsConfig: function () { + return window.checkoutConfig.payment.adyen.agreementsConfig; + } }; }, ); diff --git a/view/frontend/web/js/view/payment/method-renderer/adyen-applepay-method.js b/view/frontend/web/js/view/payment/method-renderer/adyen-applepay-method.js index d6924aef2..4529ce864 100644 --- a/view/frontend/web/js/view/payment/method-renderer/adyen-applepay-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/adyen-applepay-method.js @@ -23,6 +23,7 @@ define( }, buildComponentConfiguration: function (paymentMethod, paymentMethodsExtraInfo) { let baseComponentConfiguration = this._super(); + let self = this; let applePayConfiguration = Object.assign(baseComponentConfiguration, { showPayButton: true, @@ -30,6 +31,13 @@ define( amount: paymentMethodsExtraInfo[paymentMethod.type].configuration.amount } ); + applePayConfiguration.onClick = function(resolve, reject) { + if (self.validate()) { + resolve(); + } else { + reject(); + } + } return applePayConfiguration; }, diff --git a/view/frontend/web/js/view/payment/method-renderer/adyen-googlepay-method.js b/view/frontend/web/js/view/payment/method-renderer/adyen-googlepay-method.js index 307220541..d42375148 100644 --- a/view/frontend/web/js/view/payment/method-renderer/adyen-googlepay-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/adyen-googlepay-method.js @@ -12,9 +12,9 @@ define( 'Magento_Checkout/js/model/quote', 'Adyen_Payment/js/view/payment/method-renderer/adyen-pm-method', ], - function( + function ( quote, - adyenPaymentMethod, + adyenPaymentMethod ) { return adyenPaymentMethod.extend({ placeOrderButtonVisible: false, @@ -23,12 +23,23 @@ define( }, buildComponentConfiguration: function (paymentMethod, paymentMethodsExtraInfo) { let baseComponentConfiguration = this._super(); + let self = this; + let googlePayConfiguration = Object.assign( + baseComponentConfiguration, + paymentMethodsExtraInfo[paymentMethod.type].configuration + ); - let googlePayConfiguration = Object.assign(baseComponentConfiguration, paymentMethodsExtraInfo[paymentMethod.type].configuration); googlePayConfiguration.showPayButton = true; - return googlePayConfiguration + googlePayConfiguration.onClick = function(resolve,reject) { + if (self.validate()) { + resolve(); + } else { + reject(); + } + } + return googlePayConfiguration; } - }) + }); } ); diff --git a/view/frontend/web/js/view/payment/method-renderer/adyen-paypal-method.js b/view/frontend/web/js/view/payment/method-renderer/adyen-paypal-method.js index bd7eb634b..52978f087 100644 --- a/view/frontend/web/js/view/payment/method-renderer/adyen-paypal-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/adyen-paypal-method.js @@ -9,20 +9,22 @@ */ define( [ - 'Magento_Checkout/js/model/quote', + 'jquery', 'Adyen_Payment/js/view/payment/method-renderer/adyen-pm-method', + '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', - 'Adyen_Payment/js/model/adyen-configuration' + 'Adyen_Payment/js/model/payment-component-states', ], function( - quote, + $, adyenPaymentMethod, + adyenConfiguration, fullScreenLoader, adyenPaymentService, errorProcessor, - adyenConfiguration + paymentComponentStates ) { return adyenPaymentMethod.extend({ placeOrderButtonVisible: false, @@ -31,10 +33,45 @@ define( this._super(); }, buildComponentConfiguration: function (paymentMethod, paymentMethodsExtraInfo) { + let self = this; + let baseComponentConfiguration = this._super(); let paypalConfiguration = Object.assign(baseComponentConfiguration, paymentMethodsExtraInfo[paymentMethod.type].configuration); paypalConfiguration.showPayButton = true; + let agreementsConfig = adyenConfiguration.getAgreementsConfig(); + + if (agreementsConfig && agreementsConfig.checkoutAgreements.isEnabled) { + let agreementsMode = null; + agreementsConfig.checkoutAgreements.agreements.forEach((item) => { + if (item.mode === '1') { + agreementsMode = 'manual'; + } + }); + + if (agreementsMode === 'manual') { + paypalConfiguration.onInit = function (data, actions) { + try { + actions.disable(); + + $("input.required-entry").on('change', function () { + self.validate() ? actions.enable() : actions.disable(); + }); + } catch (error) { + console.warn("PayPal component initialization failed!"); + } + }; + + paypalConfiguration.onClick = function (data, actions) { + if (self.validate()) { + return actions.resolve(); + } else { + return actions.reject(); + } + }; + } + } + return paypalConfiguration }, renderActionComponent: function(resultCode, action, component) { @@ -45,11 +82,15 @@ define( handleOnFailure: function(response, component) { this.isPlaceOrderAllowed(true); fullScreenLoader.stopLoader(); + if (response && response.error) { + console.error('Error details:', response.error); + } component.handleReject(response); }, handleOnError: function (error, component) { + let self = this; if ('test' === adyenConfiguration.getCheckoutEnvironment()) { - console.log("onError:",error); + console.log("An error occured on PayPal component!"); } // call endpoint with component.paymentData if available @@ -71,13 +112,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); }); } }) diff --git a/view/frontend/web/js/view/payment/method-renderer/adyen-pm-method.js b/view/frontend/web/js/view/payment/method-renderer/adyen-pm-method.js index f6f760d6e..f6bf2dffc 100755 --- a/view/frontend/web/js/view/payment/method-renderer/adyen-pm-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/adyen-pm-method.js @@ -149,7 +149,9 @@ define( }, handleOnFailure: function(error, component) { - this.isPlaceOrderAllowed(true); + + paymentComponentStates().setIsPlaceOrderAllowed(this.getMethodCode(), true); + fullScreenLoader.stopLoader(); errorProcessor.process(error, this.currentMessageContainer); },