From 78520f24a02113eb13a4eb160168c1d664007757 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Wed, 24 Jan 2024 20:39:49 +0100 Subject: [PATCH] Refactor Pre-Select --- src/Core/ViewConfig.php | 11 ------- views/frontend/tpl/payment/adyen_assets.tpl | 33 +++++++++++-------- .../payment/adyen_assets_configuration.tpl | 9 +++-- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/Core/ViewConfig.php b/src/Core/ViewConfig.php index 234d9ffc..79dca3ac 100644 --- a/src/Core/ViewConfig.php +++ b/src/Core/ViewConfig.php @@ -106,17 +106,6 @@ public function isAdyenLoggingActive(): bool return $this->getModuleSettingsSrvc()->isLoggingActive(); } - /** - * @return bool - */ - public function isAdyenPaymentOxChecked(): bool - { - /** @var Payment $oPayment */ - $oPayment = oxNew(Payment::class); - $oPayment->load('oscadyencreditcard'); - return (bool)$oPayment->oxpayments__oxchecked->value; - } - /** * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface diff --git a/views/frontend/tpl/payment/adyen_assets.tpl b/views/frontend/tpl/payment/adyen_assets.tpl index 6eb26f6d..48b0ebc6 100644 --- a/views/frontend/tpl/payment/adyen_assets.tpl +++ b/views/frontend/tpl/payment/adyen_assets.tpl @@ -23,6 +23,7 @@ let submitForm, submitLink; [{if $oViewConf->getTopActiveClassName() == 'payment'}] [{assign var="isPaymentPage" value=true}] + [{assign var="paymentID" value=$oView->getCheckedPaymentId()}] submitForm = document.getElementById('payment'); submitLink = document.getElementById('orderStep'); const nextStepEl = document.getElementById('paymentNextStepBottom'); @@ -59,22 +60,32 @@ console.log(checkout.paymentMethodsResponse); [{/if}] [{if $isPaymentPage && $oView->isAvailablePayment($adyenCreditCard)}] - const cardComponent = checkout.create('card').mount('#[{$adyenCreditCard}]-container'); - cardComponent.paymentIdViewEl = undefined; + const cardComponent = checkout.create( + 'card', + { + onFieldValid : function() { + const paymentIdEl = document.getElementById('payment_[{$adyenCreditCard}]'); + paymentIdEl.checked = true; + nextStepEl.disabled = true; + }, + + } + ).mount('#[{$adyenCreditCard}]-container'); + cardComponent.paymentIdViewEl = document.getElementById('payment_[{$adyenCreditCard}]').parentElement; [{elseif $isOrderPage}] [{if $orderPaymentApplePay}] const applePayComponent = checkout.create('[{$templateCheckoutCreateId}]', configuration); applePayComponent.isAvailable() .then(() => { [{if $isLog}] - console.log('mount checkout component') + console.log('mount checkout component'); [{/if}] applePayComponent.mount('#[{$templatePayButtonContainerId}]'); }) .catch(e => { [{if $isLog}] - console.error('Apple Pay not available') - console.error(e) + console.error('Apple Pay not available'); + console.error(e); [{/if}] }); [{else}] @@ -93,14 +104,6 @@ }); }; - const setPaymentIdEl = (component, nextStepElDisabled) => { - const paymentIdEl = document.getElementById(component._node.attributes.getNamedItem('data-paymentid').value); - paymentIdEl.checked = [{if $oViewConf->isAdyenPaymentOxChecked()}]true[{else}]false[{/if}]; - nextStepEl.disabled = nextStepElDisabled; - nextStepEl.dataset.adyensubmit = ''; - return paymentIdEl; - }; - const makeDetailsCall = data => httpPost('details', data) .then(response => { @@ -147,11 +150,13 @@ e.preventDefault(); this.disabled = true; if (this.dataset.adyensubmit === '[{$adyenCreditCard}]') { - cardComponent.paymentIdViewEl = document.getElementById('payment_[{$adyenCreditCard}]').parentElement; cardComponent.submit(); } } }, false); + [{if $paymentID === $adyenCreditCard}] + nextStepEl.disabled = true; + [{/if}] [{/if}] } // Call adyenAsync diff --git a/views/frontend/tpl/payment/adyen_assets_configuration.tpl b/views/frontend/tpl/payment/adyen_assets_configuration.tpl index 3a8f43d3..1e004637 100644 --- a/views/frontend/tpl/payment/adyen_assets_configuration.tpl +++ b/views/frontend/tpl/payment/adyen_assets_configuration.tpl @@ -11,9 +11,13 @@ const configuration = { }, onChange: (state, component) => { if (isPaymentPage) { - var paymentIdEl = setPaymentIdEl(component, !state.isValid); if (state.isValid) { + const paymentIdEl = document.getElementById(component._node.attributes.getNamedItem('data-paymentid').value); nextStepEl.dataset.adyensubmit = paymentIdEl.value; + nextStepEl.disabled = false; + } + else { + nextStepEl.dataset.adyensubmit = ''; } } if (isLog) { @@ -53,7 +57,8 @@ const configuration = { makeDetailsCall(state.data) .then(response => { if (isPaymentPage) { - setPaymentIdEl(component, true); + nextStepEl.dataset.adyensubmit = ''; + nextStepEl.disabled = true; } if (isLog) { console.log('makeDetailsCall:', response);