diff --git a/Model/ApiFacade/CardTransaction/CardApiFacade.php b/Model/ApiFacade/CardTransaction/CardApiFacade.php index 867894b..4124d5f 100755 --- a/Model/ApiFacade/CardTransaction/CardApiFacade.php +++ b/Model/ApiFacade/CardTransaction/CardApiFacade.php @@ -25,7 +25,7 @@ class CardApiFacade public function __construct(TpayInterface $tpay, TpayTokensService $tokensService, TpayService $tpayService, StoreManagerInterface $storeManager) { $this->storeManager = $storeManager; - $this->cardOrigin = new CardOrigin($tpay, $tokensService, $tpayService); + $this->createCardOriginApiInstance($tpay, $tokensService, $tpayService); $this->createOpenApiInstance($tpay, $tokensService, $tpayService); } @@ -39,6 +39,15 @@ private function getCurrent() return $this->useOpenCard ? $this->cardOpen : $this->cardOrigin; } + private function createCardOriginApiInstance(TpayInterface $tpay, TpayTokensService $tokensService, TpayService $tpayService) + { + try { + $this->cardOrigin = new CardOrigin($tpay, $tokensService, $tpayService); + } catch (Exception $exception) { + $this->cardOrigin = null; + } + } + private function createOpenApiInstance(TpayInterface $tpay, TpayTokensService $tokensService, TpayService $tpayService) { if ('PLN' !== $this->storeManager->getStore()->getCurrentCurrencyCode()) { diff --git a/Model/ApiFacade/Refund/RefundApiFacade.php b/Model/ApiFacade/Refund/RefundApiFacade.php index 7263575..713de5a 100755 --- a/Model/ApiFacade/Refund/RefundApiFacade.php +++ b/Model/ApiFacade/Refund/RefundApiFacade.php @@ -24,7 +24,7 @@ class RefundApiFacade public function __construct(TpayInterface $tpay) { $this->tpay = $tpay; - $this->originApi = new RefundOriginApi($tpay); + $this->createRefundOriginApiInstance($tpay); $this->createOpenApiInstance($tpay->getOpenApiClientId(), $tpay->getOpenApiPassword(), !$tpay->useSandboxMode()); } @@ -45,6 +45,15 @@ private function getCurrentApi() return $this->useOpenApi ? $this->openApi : $this->originApi; } + private function createRefundOriginApiInstance(TpayInterface $tpay) + { + try { + $this->originApi = new RefundOriginApi($tpay); + } catch (Exception $exception) { + $this->originApi = null; + } + } + private function createOpenApiInstance(string $clientId, string $apiPassword, bool $isProd) { try { diff --git a/Model/ApiFacade/TpayConfig/ConfigFacade.php b/Model/ApiFacade/TpayConfig/ConfigFacade.php index 55c29f6..06d1d6c 100755 --- a/Model/ApiFacade/TpayConfig/ConfigFacade.php +++ b/Model/ApiFacade/TpayConfig/ConfigFacade.php @@ -21,7 +21,7 @@ class ConfigFacade public function __construct(TpayInterface $tpay, Repository $assetRepository, TpayTokensService $tokensService, StoreManagerInterface $storeManager) { - $this->originApi = new ConfigOrigin($tpay, $assetRepository, $tokensService); + $this->createOriginApiInstance($tpay, $assetRepository, $tokensService); $this->createOpenApiInstance($tpay, $assetRepository, $tokensService, $storeManager); } @@ -35,6 +35,15 @@ private function getCurrentApi() return $this->useOpenApi ? $this->openApi : $this->originApi; } + private function createOriginApiInstance(TpayInterface $tpay, Repository $assetRepository, TpayTokensService $tokensService) + { + try { + $this->originApi = new ConfigOrigin($tpay, $assetRepository, $tokensService); + } catch (Exception $exception) { + $this->originApi = null; + } + } + private function createOpenApiInstance(TpayInterface $tpay, Repository $assetRepository, TpayTokensService $tokensService, StoreManagerInterface $storeManager) { if ('PLN' !== $storeManager->getStore()->getCurrentCurrencyCode()) { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index f8bfec1..a03ea36 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -23,35 +23,33 @@ - validate-no-empty validate-number validate-length maximum-length-10 + validate-number validate-length maximum-length-10 - validate-no-empty validate-length maximum-length-32 + validate-length maximum-length-32 - validate-no-empty no-whitespace validate-length maximum-length-126 + no-whitespace validate-length maximum-length-126 - validate-no-empty no-whitespace validate-length maximum-length-40 + no-whitespace validate-length maximum-length-40 - validate-no-empty no-whitespace validate-length maximum-length-126 + no-whitespace validate-length maximum-length-126 - validate-no-empty no-whitespace validate-length maximum-length-40 + no-whitespace validate-length maximum-length-40 - validate-no-empty - validate-no-empty @@ -115,13 +113,6 @@ validate-length maximum-length-64 - - - validate-no-empty validate-length maximum-length-32 - - - - diff --git a/view/base/web/js/renderSavedCards.js b/view/base/web/js/renderSavedCards.js index 36a04dd..e5e2088 100644 --- a/view/base/web/js/renderSavedCards.js +++ b/view/base/web/js/renderSavedCards.js @@ -14,11 +14,11 @@ require(['jquery', 'mage/translate'], function ($, $t) { $('#saved_card_payment').css('display', 'none'); return; } - $("#tpaycom_magento2cards_submit").removeClass('disabled'); + $('input[name=savedId]').each(function () { if ($(this).val() !== 'new') { $(this).click(function () { - if ($(this).is(":checked")) { + if ($(this).is(":checked") && $('#card_accept_tos').is(':checked')) { $('#card_form').css({opacity: 1.0}).animate({opacity: 0.0}, 500); setTimeout( function () { @@ -48,7 +48,6 @@ require(['jquery', 'mage/translate'], function ($, $t) { } } }); - } function generateHtml() { @@ -75,7 +74,14 @@ require(['jquery', 'mage/translate'], function ($, $t) { } $('document').ready(function () { + var tos = $('#card_accept_tos'); + renderForm(); + tos.on('change', function () { + if (tos.is(':checked')) { + $("#tpaycom_magento2cards_submit").removeClass('disabled'); + } + }); }); }); diff --git a/view/base/web/js/render_channels.js b/view/base/web/js/render_channels.js index 7f299c7..ac33b65 100644 --- a/view/base/web/js/render_channels.js +++ b/view/base/web/js/render_channels.js @@ -156,5 +156,26 @@ require(['jquery', 'mage/translate'], function ($, $t) { payButton.addClass('disabled'); }); }); + + $("#tpaycom_magento2generic_submit", '.payment-method').addClass('disabled'); + + $('input[name="payment[method]"]').on('click', function () { + var parent = $(this).closest('.payment-method'); + $('input[name="accept_tos"]', parent).prop('checked', false); + + var submitBtn = $("#tpaycom_magento2generic_submit", parent); + submitBtn.addClass('disabled'); + }); + + $("input[name='accept_tos']").on("click", function () { + var parent = $(this).closest('.payment-method-content'); + var submitBtn = $("#tpaycom_magento2generic_submit", parent); + + if ($('#generic_accept_tos', parent).is(':checked')) { + submitBtn.removeClass('disabled'); + } else { + submitBtn.addClass('disabled'); + } + }); } ); diff --git a/view/base/web/js/tpayCards.js b/view/base/web/js/tpayCards.js index 2fd9e1d..f7adf0f 100644 --- a/view/base/web/js/tpayCards.js +++ b/view/base/web/js/tpayCards.js @@ -1,15 +1,17 @@ require(['jquery', 'mage/translate'], function ($, $t) { function CardPayment() { - var numberInput = $('#card_number'), + var payButton = $('#tpaycom_magento2cards_submit'), + numberInput = $('#card_number'), expiryInput = $('#expiry_date'), cvcInput = $('#cvc'), - RSA = $('#tpayRSA').text(); + RSA = $('#tpayRSA').text(), + tos = $('#card_accept_tos'); const TRIGGER_EVENTS = 'input change blur'; function setWrong($elem) { $elem.addClass('wrong').removeClass('valid'); - $("#tpaycom_magento2cards_submit").addClass('disabled'); + payButton.addClass('disabled'); } function setValid($elem) { @@ -90,12 +92,14 @@ require(['jquery', 'mage/translate'], function ($, $t) { if (cn.length === 0 || ed.length === 0 || cvc.length === 0) { isValid = false; } - if (isValid) { + if (isValid && tos.is(':checked')) { encrypt.setPublicKey(decoded); encrypted = encrypt.encrypt(cd); $("#card_data").val(encrypted); $("#card_short_code").val(cn.substr(-4)); - $("#tpaycom_magento2cards_submit").removeClass('disabled'); + payButton.removeClass('disabled'); + } else { + payButton.addClass('disabled'); } } @@ -109,6 +113,9 @@ require(['jquery', 'mage/translate'], function ($, $t) { validateCvc($(this)); }); + tos.on('change', function () { + enablePayment(); + }); } $(document).ready(function () { diff --git a/view/frontend/web/js/view/payment/method-renderer/tpay-generic-onsite.js b/view/frontend/web/js/view/payment/method-renderer/tpay-generic-onsite.js index d5b4a9c..a1c4811 100644 --- a/view/frontend/web/js/view/payment/method-renderer/tpay-generic-onsite.js +++ b/view/frontend/web/js/view/payment/method-renderer/tpay-generic-onsite.js @@ -22,6 +22,10 @@ define( window.location.replace(window.checkoutConfig.tpay.payment.redirectUrl); }, + getTerms: function () { + return window.checkoutConfig.tpay.payment.getTerms; + }, + getLogoUrl: function (code) { const id = code.slice(code.indexOf('-') + 1); diff --git a/view/frontend/web/template/payment/card-tpay-form.html b/view/frontend/web/template/payment/card-tpay-form.html index 3ea10ca..46f78a7 100644 --- a/view/frontend/web/template/payment/card-tpay-form.html +++ b/view/frontend/web/template/payment/card-tpay-form.html @@ -1,4 +1,3 @@ -
+
+ + +
diff --git a/view/frontend/web/template/payment/tpay-generic-onsite.html b/view/frontend/web/template/payment/tpay-generic-onsite.html index 4253f95..95aa7b1 100644 --- a/view/frontend/web/template/payment/tpay-generic-onsite.html +++ b/view/frontend/web/template/payment/tpay-generic-onsite.html @@ -11,10 +11,22 @@
+
+ + + +
+ + +
+