diff --git a/src/Core/ViewConfig.php b/src/Core/ViewConfig.php index eac1a3e..5c7ddae 100644 --- a/src/Core/ViewConfig.php +++ b/src/Core/ViewConfig.php @@ -308,6 +308,14 @@ public function isApplePay( ->isApplePay($payment); } + public function isOrderPaymentCreditCard( + FrontendController $oView, + ?Payment $payment + ): string { + return $this->getServiceFromContainer(JSAPITemplateConfiguration::class) + ->isOrderPaymentCreditCard($oView, $payment); + } + /** * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface diff --git a/src/Service/JSAPITemplateConfiguration.php b/src/Service/JSAPITemplateConfiguration.php index bda221d..3d0f2ae 100644 --- a/src/Service/JSAPITemplateConfiguration.php +++ b/src/Service/JSAPITemplateConfiguration.php @@ -54,6 +54,16 @@ public function isApplePay( return $paymentId === Module::PAYMENT_APPLE_PAY_ID; } + public function isOrderPaymentCreditCard( + FrontendController $controller, + ?Payment $payment + ): bool { + $paymentId = $payment instanceof Payment ? $payment->getId() : ''; + + return $controller instanceof Ordercontroller + && $paymentId === Module::PAYMENT_CREDITCARD_ID; + } + private function getViewData( ViewConfig $viewConfig, FrontendController $controller, diff --git a/views/twig/extensions/themes/apex/page/checkout/order.html.twig b/views/twig/extensions/themes/apex/page/checkout/order.html.twig index 36f8df4..cb8bf5d 100644 --- a/views/twig/extensions/themes/apex/page/checkout/order.html.twig +++ b/views/twig/extensions/themes/apex/page/checkout/order.html.twig @@ -41,7 +41,31 @@ {% include sModuleId ~ "/payment/adyen_payment_psp.html.twig" %} + {% if payment.isAdyenCreditCardPayment() %} + {% set payment=oView.getPayment()%} +

+ {{ payment.oxpayments__oxdesc.value|raw }} +

+
+
+ +
+ +
+ {% endif %} + {% endif %} diff --git a/views/twig/payment/adyen_assets.html.twig b/views/twig/payment/adyen_assets.html.twig index f2b68ad..52a159c 100644 --- a/views/twig/payment/adyen_assets.html.twig +++ b/views/twig/payment/adyen_assets.html.twig @@ -49,9 +49,13 @@ const adyenResultCodeEl = document.getElementById('{{ oViewConf.getAdyenHtmlParamResultCodeName() }}'); const adyenAmountCurrencyEl = document.getElementById('{{ oViewConf.getAdyenHtmlParamAmountCurrencyName() }}'); const adyenAmountValueEl = document.getElementById('{{ oViewConf.getAdyenHtmlParamAmountValueName() }}'); + {% if isOrderPage %} + const orderSubmitButton = document.getElementById("orderConfirmAgbBottom"); + {% endif %} const adyenAsync = async function () { {{ oViewConf.getTemplateConfiguration(oView, payment)|raw }} + {% set orderPaymentCreditCard = oViewConf.isOrderPaymentCreditCard(oView, payment) %} const checkout = await AdyenCheckout(configuration); // Access the available payment methods for the session. @@ -85,22 +89,31 @@ } }); {% endif %} - {% if oView.handleAdyenAssets(adyenCreditCard) %} + {% elseif isOrderPage %} + {% if orderPaymentCreditCard %} + orderSubmitButton.disabled = true; + orderSubmitButton.title = '{{ oViewConf.getAdyenCreditCardTooltipText()|raw }}'; const cardComponent = checkout.create( 'card', { onFieldValid : function() { - const paymentIdEl = document.getElementById('payment_{{adyenCreditCard}}'); - paymentIdEl.checked = true; - nextStepEl.disabled = true; + orderSubmitButton.disabled = false; }, - + onLoad: function () { + document.querySelector("#oscadyencreditcard-container button").style.display = 'none'; + } } ).mount('#{{adyenCreditCard}}-container'); - cardComponent.paymentIdViewEl = document.getElementById('payment_{{adyenCreditCard}}').parentElement; - {% endif %} - {% elseif isOrderPage %} - {% if oViewConf.isApplePay(payment) %} + + submitForm.addEventListener('submit', function(event) { + event.preventDefault(); + this.disabled = true; + {% if isLog %} + console.log("cardComp:", cardComponent) + {% endif %} + cardComponent.submit(); + }); + {% elseif oViewConf.isApplePay(payment) %} const applePayComponent = checkout.create('{{ templateCheckoutCreateId }}', configuration); applePayComponent.isAvailable() .then(() => { @@ -171,21 +184,6 @@ } return result; } - - {% if isPaymentPage %} - nextStepEl.addEventListener("click", function(e) { - if (this.dataset.adyensubmit !== '') { - e.preventDefault(); - this.disabled = true; - if (this.dataset.adyensubmit === '{{ adyenCreditCard }}') { - cardComponent.submit(); - } - } - }, false); - {% if paymentID is same as(adyenCreditCard) %} - nextStepEl.disabled = true; - {% endif %} - {% endif %} } // Call adyenAsync adyenAsync(); diff --git a/views/twig/payment/adyen_assets_configuration.html.twig b/views/twig/payment/adyen_assets_configuration.html.twig index 447fb11..8f981dc 100644 --- a/views/twig/payment/adyen_assets_configuration.html.twig +++ b/views/twig/payment/adyen_assets_configuration.html.twig @@ -2,6 +2,7 @@ const isLog = {% if isLog %}true{% else %}false{% endif %}; const isPaymentPage = {% if isPaymentPage %}true{% else %}false{% endif %}; const isOrderPage = {% if isOrderPage %}true{% else %}false{% endif %}; +const isCreditCard = {% if orderPaymentCreditCard %}true{% else %}false{% endif %}; const configuration = { {{ configFields|raw }}, onError: (error, component) => { @@ -29,21 +30,17 @@ const configuration = { console.log('onSubmit:', state.data); } component.setStatus('loading'); - if (isPaymentPage) { + if (isPaymentPage || isCreditCard) { state.data.deliveryAddress = configuration.deliveryAddress; state.data.shopperEmail = configuration.shopperEmail; state.data.shopperIP = configuration.shopperIP; } - makePayment(state.data) + makePayment(state.data) //this function is declared in adyen_assets.html.twig .then(response => { if (isLog) { console.log('onSubmit-response:', response); } if (response.action) { - // Drop-in handles the action object from the /payments response - if ('paymentIdViewEl' in component) { - component.paymentIdViewEl.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"}); - } component.handleAction(response.action); } else { setPspReference(response); diff --git a/views/twig/payment/adyen_order_submit.html.twig b/views/twig/payment/adyen_order_submit.html.twig index 0ffed73..5b40aeb 100644 --- a/views/twig/payment/adyen_order_submit.html.twig +++ b/views/twig/payment/adyen_order_submit.html.twig @@ -2,8 +2,10 @@ {% set containerId = oViewConf.getTemplatePayButtonContainerId(payment) %} {% set sModuleId = '@' ~ constant('\\OxidSolutionCatalysts\\Adyen\\Core\\Module::MODULE_ID') %}
- {{ translate({ ident: "OSC_ADYEN_BUY_NOW_PAY_WITH" }) }} -
+ {% if not payment.isAdyenCreditCardPayment() %} + {{ translate({ ident: "OSC_ADYEN_BUY_NOW_PAY_WITH" }) }} +
+ {% endif %}
\ No newline at end of file