diff --git a/Controller/tpay/CardPayment.php b/Controller/tpay/CardPayment.php index e614cce..db7d38b 100644 --- a/Controller/tpay/CardPayment.php +++ b/Controller/tpay/CardPayment.php @@ -12,6 +12,7 @@ use Tpay\OriginApi\Utilities\Util; use tpaycom\magento2basic\Api\TpayInterface; use tpaycom\magento2basic\Model\ApiFacade\CardTransaction\CardApiFacade; +use tpaycom\magento2basic\Model\Tpay; use tpaycom\magento2basic\Service\TpayService; use tpaycom\magento2basic\Service\TpayTokensService; @@ -49,6 +50,13 @@ public function execute() $orderId = $this->checkoutSession->getLastRealOrderId(); if ($orderId) { + $payment = $this->tpayService->getPayment($orderId); + $additionalPaymentInformation = $payment->getData()['additional_information']; + + if (!$additionalPaymentInformation[Tpay::TERMS_ACCEPT]) { + return $this->_redirect('magento2basic/tpay/error'); + } + $cardTransaction = new CardApiFacade($this->tpay, $this->tokensService, $this->tpayService, $this->storeManager); $redirectUrl = $cardTransaction->makeCardTransaction($orderId); diff --git a/Controller/tpay/Create.php b/Controller/tpay/Create.php index 265c84e..d006e28 100644 --- a/Controller/tpay/Create.php +++ b/Controller/tpay/Create.php @@ -11,6 +11,7 @@ use tpaycom\magento2basic\Api\TpayInterface; use tpaycom\magento2basic\Model\ApiFacade\Transaction\TransactionApiFacade; use tpaycom\magento2basic\Model\ApiFacade\Transaction\TransactionOriginApi; +use tpaycom\magento2basic\Model\Tpay; use tpaycom\magento2basic\Service\TpayService; class Create extends Action @@ -56,6 +57,10 @@ public function execute(): ResponseInterface $this->transaction = new TransactionApiFacade($this->tpay, $this->cache); $additionalPaymentInformation = $paymentData['additional_information']; + if (!$additionalPaymentInformation[Tpay::TERMS_ACCEPT]) { + return $this->_redirect('magento2basic/tpay/error'); + } + $transaction = $this->prepareTransaction($orderId, $additionalPaymentInformation); if (!isset($transaction['title'], $transaction['url'])) { diff --git a/Model/Tpay.php b/Model/Tpay.php index 79e8938..1e235a4 100755 --- a/Model/Tpay.php +++ b/Model/Tpay.php @@ -315,9 +315,7 @@ public function assignData(DataObject $data) $info->setAdditionalInformation('channel', $additionalData['channel'] ?? null); - if (array_key_exists(static::TERMS_ACCEPT, $additionalData) && 1 === $additionalData[static::TERMS_ACCEPT]) { - $info->setAdditionalInformation(static::TERMS_ACCEPT, 1); - } + $info->setAdditionalInformation(static::TERMS_ACCEPT, isset($additionalData[static::TERMS_ACCEPT]) ? '1' === $additionalData[static::TERMS_ACCEPT] : false); // KARTY $info->setAdditionalInformation(static::CARDDATA, $additionalData[static::CARDDATA] ?? ''); diff --git a/view/frontend/web/js/view/payment/method-renderer/tpay-card-method.js b/view/frontend/web/js/view/payment/method-renderer/tpay-card-method.js index c0dfd73..3524051 100644 --- a/view/frontend/web/js/view/payment/method-renderer/tpay-card-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/tpay-card-method.js @@ -87,7 +87,7 @@ define( paymentData = {}; paymentData['group'] = $('#tpay-channel-input').val(); paymentData['blik_code'] = $('#blik_code').val(); - paymentData['accept_tos'] = $('#accept_tos').is(':checked'); + paymentData['accept_tos'] = $('input[name="accept_tos"]').is(':checked'); paymentData['card_data'] = $('input[name="card_data"]').val(); paymentData['card_save'] = $('input[name="card_save"]').is(":checked"); 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 a1c4811..4a06d56 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 @@ -33,6 +33,15 @@ define( redirectAfterPlaceOrder: false, + getData: function () { + var parent = this._super(), + paymentData = {}; + + paymentData['accept_tos'] = $('input[name="accept_tos"]').is(':checked'); + + return $.extend(true, parent, {'additional_data': paymentData}); + }, + isActive: function () { return true; } diff --git a/view/frontend/web/js/view/payment/method-renderer/tpay-method.js b/view/frontend/web/js/view/payment/method-renderer/tpay-method.js index c75256d..5aefaa8 100644 --- a/view/frontend/web/js/view/payment/method-renderer/tpay-method.js +++ b/view/frontend/web/js/view/payment/method-renderer/tpay-method.js @@ -87,7 +87,7 @@ define( paymentData = {}; paymentData['group'] = $('#tpay-channel-input').val(); paymentData['blik_code'] = $('#blik_code').val(); - paymentData['accept_tos'] = $('#accept_tos').is(':checked'); + paymentData['accept_tos'] = $('input[name="accept_tos"]').is(':checked'); paymentData['card_data'] = $('input[name="card_data"]').val(); paymentData['card_save'] = $('input[name="card_save"]').is(":checked");