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

[ECP-9098] Validate terms and agreements checkboxes for PayPal #2759

Merged
merged 6 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions Model/Ui/AdyenGenericConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand All @@ -45,6 +47,7 @@ public function __construct(
StoreManagerInterface $storeManager,
RequestInterface $request,
UrlInterface $url,
AgreementsConfigProvider $agreementsConfigProvider,
array $txVariants = [],
array $customMethodRenderers = []
) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -88,6 +92,7 @@ public function getConfig(): array
'checkout/onepage/success',
['_secure' => $this->request->isSecure()]
);
$config['payment']['adyen']['agreementsConfig'] = $this->agreementsConfigProvider->getConfig();

return $config;
}
Expand Down
3 changes: 3 additions & 0 deletions view/frontend/web/js/model/adyen-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ define(
getCustomerStreetLinesEnabled: function () {
return window.checkoutConfig.payment.customerStreetLinesEnabled;
},
getAgreementsConfig: function () {
return window.checkoutConfig.payment.adyen.agreementsConfig;
}
};
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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);
});
}
})
Expand Down
Loading