From 60cb882d6d9eebda1e9483da7071881da3c2b891 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 20 Sep 2024 14:23:21 +0300 Subject: [PATCH 01/32] [SL-234] fix not rendering --- views/templates/front/credit_cards.tpl | 2 +- views/templates/front/credit_cards_16.tpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/views/templates/front/credit_cards.tpl b/views/templates/front/credit_cards.tpl index d042b193..9c69534f 100755 --- a/views/templates/front/credit_cards.tpl +++ b/views/templates/front/credit_cards.tpl @@ -51,7 +51,7 @@ {foreach $rows as $row} - {$row nofilter|escape:'htmlall':'UTF-8'} + {$row|escape:'htmlall':'UTF-8' nofilter} {/foreach} diff --git a/views/templates/front/credit_cards_16.tpl b/views/templates/front/credit_cards_16.tpl index ee8f2a0a..292aa37e 100755 --- a/views/templates/front/credit_cards_16.tpl +++ b/views/templates/front/credit_cards_16.tpl @@ -53,7 +53,7 @@ {foreach $rows as $row} - {$row nofilter|escape:'htmlall':'UTF-8'} + {$row|escape:'htmlall':'UTF-8' nofilter} {/foreach} From b7f101dc428069907e6a62ae6df57d59022358a2 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 20 Sep 2024 14:28:06 +0300 Subject: [PATCH 02/32] [SL-234] fix --- saferpayofficial.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saferpayofficial.php b/saferpayofficial.php index a4a4e230..8512afaf 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -366,12 +366,12 @@ public function hookDisplayCustomerAccount() } if (\Invertus\SaferPay\Config\SaferPayConfig::isVersion17()) { return $this->context->smarty->fetch( - $this->getLocalPath() . 'views/templates/hook/front/MyAccount.tpl' + 'module:saferpayofficial/views/templates/hook/front/MyAccount.tpl' ); } return $this->context->smarty->fetch( - $this->getLocalPath() . 'views/templates/hook/front/MyAccount_16.tpl' + 'module:saferpayofficial/views/templates/hook/front/MyAccount_16.tpl' ); } From acd2f60f53f577e9704f3d5aae3d061d56dd6721 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 20 Sep 2024 15:26:25 +0300 Subject: [PATCH 03/32] [SL-234] fix --- src/Service/SaferPayOrderStatusService.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Service/SaferPayOrderStatusService.php b/src/Service/SaferPayOrderStatusService.php index 711b837c..390325c2 100755 --- a/src/Service/SaferPayOrderStatusService.php +++ b/src/Service/SaferPayOrderStatusService.php @@ -189,14 +189,21 @@ public function cancel(Order $order) $saferPayOrder = new SaferPayOrder($saferPayOrderId); $cancelRequest = $this->cancelRequestObjectCreator->create($saferPayOrder->transaction_id); try { - $this->cancelService->cancel($cancelRequest); + $cancelResponse = $this->cancelService->cancel($cancelRequest); } catch (Exception $e) { throw new SaferPayApiException('Cancel API failed', SaferPayApiException::CANCEL); } $order->setCurrentState(_SAFERPAY_PAYMENT_CANCELED_); $order->update(); $saferPayOrder->canceled = 1; + $saferPayOrder->update(); + + $assertId = $this->orderRepository->getAssertIdBySaferPayOrderId($saferPayOrder->id); + $saferPayAssert = new SaferPayAssert($assertId); + $saferPayAssert->status = 'CANCELED'; + + $saferPayAssert->update(); } public function refund(Order $order, $refundedAmount) From f3f85c2e1f4cbc67dbd4a6e68d9d7c6acf8f994e Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 20 Sep 2024 16:01:00 +0300 Subject: [PATCH 04/32] [SL-234] fix --- src/Service/SaferPayOrderStatusService.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Service/SaferPayOrderStatusService.php b/src/Service/SaferPayOrderStatusService.php index 390325c2..711b837c 100755 --- a/src/Service/SaferPayOrderStatusService.php +++ b/src/Service/SaferPayOrderStatusService.php @@ -189,21 +189,14 @@ public function cancel(Order $order) $saferPayOrder = new SaferPayOrder($saferPayOrderId); $cancelRequest = $this->cancelRequestObjectCreator->create($saferPayOrder->transaction_id); try { - $cancelResponse = $this->cancelService->cancel($cancelRequest); + $this->cancelService->cancel($cancelRequest); } catch (Exception $e) { throw new SaferPayApiException('Cancel API failed', SaferPayApiException::CANCEL); } $order->setCurrentState(_SAFERPAY_PAYMENT_CANCELED_); $order->update(); $saferPayOrder->canceled = 1; - $saferPayOrder->update(); - - $assertId = $this->orderRepository->getAssertIdBySaferPayOrderId($saferPayOrder->id); - $saferPayAssert = new SaferPayAssert($assertId); - $saferPayAssert->status = 'CANCELED'; - - $saferPayAssert->update(); } public function refund(Order $order, $refundedAmount) From ce82051725a9c6030aa3867d92d87a5532e0a656 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 20 Sep 2024 16:08:27 +0300 Subject: [PATCH 05/32] [SL-230] init --- src/Service/SaferPayOrderStatusService.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Service/SaferPayOrderStatusService.php b/src/Service/SaferPayOrderStatusService.php index 711b837c..d3c32483 100755 --- a/src/Service/SaferPayOrderStatusService.php +++ b/src/Service/SaferPayOrderStatusService.php @@ -197,6 +197,11 @@ public function cancel(Order $order) $order->update(); $saferPayOrder->canceled = 1; $saferPayOrder->update(); + + $assertId = $this->orderRepository->getAssertIdBySaferPayOrderId($saferPayOrder->id); + $saferPayAssert = new SaferPayAssert($assertId); + $saferPayAssert->status = TransactionStatus::CANCELED; + $saferPayAssert->update(); } public function refund(Order $order, $refundedAmount) From 908b462362352cf36ec67910d725b23ee2de67b9 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Sun, 22 Sep 2024 14:26:44 +0300 Subject: [PATCH 06/32] [SL-244] optimized images querys --- saferpayofficial.php | 5 ++++- src/Repository/SaferPayPaymentRepository.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/saferpayofficial.php b/saferpayofficial.php index a4a4e230..33313a38 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -206,6 +206,9 @@ public function hookPaymentOptions($params) \Invertus\SaferPay\Service\PaymentRestrictionValidation::class ); + $logosEnabled = $paymentRepository->getAllLogosEnabled(); + $logosEnabled = array_column($logosEnabled, 'name'); + foreach ($paymentMethods as $paymentMethod) { $paymentMethod['paymentMethod'] = str_replace(' ', '', $paymentMethod['paymentMethod']); @@ -214,7 +217,7 @@ public function hookPaymentOptions($params) continue; } - $imageUrl = ($paymentRepository->isLogoEnabledByName($paymentMethod['paymentMethod'])) + $imageUrl = (in_array($paymentMethod['paymentMethod'], $logosEnabled)) ? $paymentMethod['logoUrl'] : ''; $isCreditCard = in_array( diff --git a/src/Repository/SaferPayPaymentRepository.php b/src/Repository/SaferPayPaymentRepository.php index 90852ec0..490daef1 100755 --- a/src/Repository/SaferPayPaymentRepository.php +++ b/src/Repository/SaferPayPaymentRepository.php @@ -62,6 +62,16 @@ public function isLogoEnabledByName($paymentName) return Db::getInstance()->getValue($query); } + public function getAllLogosEnabled() + { + $query = new DbQuery(); + $query->select('name'); + $query->from('saferpay_logo'); + $query->where('active = "1"'); + + return Db::getInstance()->executeS($query); + } + public function getActivePaymentMethods() { $query = new DbQuery(); From 61cbcd1d7fd1f3b0764c2a966d0817a89e8ea8a9 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 23 Sep 2024 09:09:02 +0300 Subject: [PATCH 07/32] [SL-244] fix --- saferpayofficial.php | 9 ++++++++- src/Repository/SaferPayPaymentRepository.php | 10 ++++++++++ .../BasePaymentRestrictionValidation.php | 4 ---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/saferpayofficial.php b/saferpayofficial.php index 33313a38..1e482c00 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -182,7 +182,7 @@ public function hookPaymentOptions($params) /** @var Invertus\SaferPay\Service\SaferPayCartService $assertService */ $cartService = $this->getService(\Invertus\SaferPay\Service\SaferPayCartService::class); if (!$cartService->isCurrencyAvailable($params['cart'])) { - return; + return []; } /** @var \Invertus\SaferPay\Provider\PaymentTypeProvider $paymentTypeProvider */ @@ -209,10 +209,17 @@ public function hookPaymentOptions($params) $logosEnabled = $paymentRepository->getAllLogosEnabled(); $logosEnabled = array_column($logosEnabled, 'name'); + $activePaymentMethods = $paymentRepository->getActivePaymentMethodsNames(); + $activePaymentMethods = array_column($activePaymentMethods, 'name'); + foreach ($paymentMethods as $paymentMethod) { $paymentMethod['paymentMethod'] = str_replace(' ', '', $paymentMethod['paymentMethod']); + if(!in_array($paymentMethod['paymentMethod'], $activePaymentMethods)) { + continue; + } + if (!$paymentRestrictionValidation->isPaymentMethodValid($paymentMethod['paymentMethod'])) { continue; } diff --git a/src/Repository/SaferPayPaymentRepository.php b/src/Repository/SaferPayPaymentRepository.php index 490daef1..6d2bc87e 100755 --- a/src/Repository/SaferPayPaymentRepository.php +++ b/src/Repository/SaferPayPaymentRepository.php @@ -82,6 +82,16 @@ public function getActivePaymentMethods() return Db::getInstance()->executeS($query); } + public function getActivePaymentMethodsNames() + { + $query = new DbQuery(); + $query->select('name'); + $query->from('saferpay_payment'); + $query->where('active = "1"'); + + return Db::getInstance()->executeS($query); + } + public function truncateTable() { $query = 'TRUNCATE TABLE ' . _DB_PREFIX_ . 'saferpay_payment;'; diff --git a/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php b/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php index b98b49dc..2f573134 100755 --- a/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php +++ b/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php @@ -72,10 +72,6 @@ public function __construct( */ public function isValid($paymentName) { - if (!$this->paymentRepository->isActiveByName($paymentName)) { - return false; - } - if (!$this->isCountrySupportedByPaymentName($paymentName)) { return false; } From 3f5d3189b208f281f02063029171c392c6f186f5 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 23 Sep 2024 10:48:30 +0300 Subject: [PATCH 08/32] [SL-244] WIP --- saferpayofficial.php | 4 +++ .../BasePaymentRestrictionValidation.php | 28 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/saferpayofficial.php b/saferpayofficial.php index 1e482c00..0f21163f 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -220,6 +220,10 @@ public function hookPaymentOptions($params) continue; } + if (!in_array($this->context->currency->iso_code, $paymentMethods[$paymentMethod['paymentMethod']]['currencies'])) { + continue; + } + if (!$paymentRestrictionValidation->isPaymentMethodValid($paymentMethod['paymentMethod'])) { continue; } diff --git a/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php b/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php index 2f573134..98b90c98 100755 --- a/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php +++ b/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php @@ -76,9 +76,9 @@ public function isValid($paymentName) return false; } - if (!$this->isCurrencySupportedByPaymentName($paymentName)) { - return false; - } +// if (!$this->isCurrencySupportedByPaymentName($paymentName)) { +// return false; +// } return true; } @@ -137,6 +137,8 @@ private function isCountrySupportedByPaymentName($paymentName) * * @return bool */ + + // bottleneck private function isCurrencySupportedByPaymentName($paymentName) { $enabledCurrencies = $this->getEnabledCurrenciesByPaymentName($paymentName); @@ -144,13 +146,27 @@ private function isCurrencySupportedByPaymentName($paymentName) if (in_array('0', $enabledCurrencies)) { $enabledCurrencies = []; $currencyOptions = $this->obtainPaymentMethods->obtainPaymentMethods()[$paymentName]['currencies']; - foreach ($currencyOptions as $isoCode) { - $enabledCurrencies[$isoCode] = $isoCode; - } +// foreach ($currencyOptions as $isoCode) { +// $enabledCurrencies[$isoCode] = $isoCode; +// } + $enabledCurrencies = array_values($currencyOptions); return in_array($this->legacyContext->getCurrencyIsoCode(), $enabledCurrencies); } return in_array($this->legacyContext->getCurrencyId(), $enabledCurrencies); } + +// private function isCurrencySupportedByPaymentName($paymentName) +// { +// $enabledCurrencies = $this->getEnabledCurrenciesByPaymentName($paymentName); +// +// // If '0' is in the list, it means all currencies are supported +// if (in_array('0', $enabledCurrencies, false)) { +// return true; +// } +// +// // Check if the current currency is in the list of enabled currencies +// return in_array($this->legacyContext->getCurrencyId(), $enabledCurrencies, false); +// } } From d2d2aeabfb1e771d2b9597ace366b4815e96ab4f Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 23 Sep 2024 12:15:37 +0300 Subject: [PATCH 09/32] [SL-244] fix --- .../BasePaymentRestrictionValidation.php | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php b/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php index 98b90c98..4a56dfb8 100755 --- a/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php +++ b/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php @@ -76,10 +76,6 @@ public function isValid($paymentName) return false; } -// if (!$this->isCurrencySupportedByPaymentName($paymentName)) { -// return false; -// } - return true; } @@ -131,42 +127,4 @@ private function isCountrySupportedByPaymentName($paymentName) return $isCountryInList || $isAllCountries; } - - /** - * @param string $paymentName - * - * @return bool - */ - - // bottleneck - private function isCurrencySupportedByPaymentName($paymentName) - { - $enabledCurrencies = $this->getEnabledCurrenciesByPaymentName($paymentName); - - if (in_array('0', $enabledCurrencies)) { - $enabledCurrencies = []; - $currencyOptions = $this->obtainPaymentMethods->obtainPaymentMethods()[$paymentName]['currencies']; -// foreach ($currencyOptions as $isoCode) { -// $enabledCurrencies[$isoCode] = $isoCode; -// } - $enabledCurrencies = array_values($currencyOptions); - - return in_array($this->legacyContext->getCurrencyIsoCode(), $enabledCurrencies); - } - - return in_array($this->legacyContext->getCurrencyId(), $enabledCurrencies); - } - -// private function isCurrencySupportedByPaymentName($paymentName) -// { -// $enabledCurrencies = $this->getEnabledCurrenciesByPaymentName($paymentName); -// -// // If '0' is in the list, it means all currencies are supported -// if (in_array('0', $enabledCurrencies, false)) { -// return true; -// } -// -// // Check if the current currency is in the list of enabled currencies -// return in_array($this->legacyContext->getCurrencyId(), $enabledCurrencies, false); -// } } From ad707d6f77cef5ff8f02af7ecf4c2963e8db4c44 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 23 Sep 2024 12:58:19 +0300 Subject: [PATCH 10/32] [SL-234] fix --- saferpayofficial.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saferpayofficial.php b/saferpayofficial.php index 8512afaf..c7bc468b 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -371,7 +371,7 @@ public function hookDisplayCustomerAccount() } return $this->context->smarty->fetch( - 'module:saferpayofficial/views/templates/hook/front/MyAccount_16.tpl' + _PS_THEME_DIR_ . 'modules/saferpayofficial/views/templates/hook/front/MyAccount.tpl' ); } From e478360e75c2b81a81ba43accb762a3f8b8a72ab Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 23 Sep 2024 13:10:07 +0300 Subject: [PATCH 11/32] [SL-234] fix --- saferpayofficial.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/saferpayofficial.php b/saferpayofficial.php index c7bc468b..bd36b49e 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -370,9 +370,7 @@ public function hookDisplayCustomerAccount() ); } - return $this->context->smarty->fetch( - _PS_THEME_DIR_ . 'modules/saferpayofficial/views/templates/hook/front/MyAccount.tpl' - ); + return $this->display(__FILE__, 'front/MyAccount_16.tpl'); } public function displayNavigationTop() From aea64654217c748ef5a473c0e84749cf99296d51 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Sun, 29 Sep 2024 10:53:02 +0300 Subject: [PATCH 12/32] [SL-252] init --- controllers/front/ajax.php | 2 +- src/DTO/Request/Initialize/InitializeRequest.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index f221d68e..f96384bf 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -77,7 +77,7 @@ protected function processGetStatus() $this->ajaxDie(json_encode([ 'saferpayOrder' => json_encode($saferPayOrder), - 'isFinished' => $saferPayOrder->authorized || $saferPayOrder->captured || $saferPayOrder->pending, + 'isFinished' => true, 'href' => $this->context->link->getModuleLink( $this->module->name, $this->getSuccessControllerName($isBusinessLicence, $fieldToken), diff --git a/src/DTO/Request/Initialize/InitializeRequest.php b/src/DTO/Request/Initialize/InitializeRequest.php index 4bf07ddc..ec5ae506 100755 --- a/src/DTO/Request/Initialize/InitializeRequest.php +++ b/src/DTO/Request/Initialize/InitializeRequest.php @@ -222,11 +222,14 @@ public function getAsArray() 'AddressSource' => $this->deliveryAddressForm->getAddressSource(), 'MandatoryFields' => $this->deliveryAddressForm->getMandatoryFields(), ], - 'CardForm' => [ - 'HolderName' => SaferPayConfig::SAFERPAY_CARDFORM_HOLDERNAME_REQUIRENCE, - ], ]; + if ($this->getPaymentMeansField() === []) { + $return['CardForm'] = [ + 'HolderName' => SaferPayConfig::SAFERPAY_CARDFORM_HOLDERNAME_REQUIRENCE, + ]; + } + if ($this->notification !== null) { $return['Notification'] = [ 'MerchantEmails' => [$this->notification->getMerchantEmail()], From d0d0c4a8f6dc0d1e51cd199c0891561b29f52592 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 17:11:04 +0300 Subject: [PATCH 13/32] [SL-244] fix --- src/Repository/SaferPayPaymentRepository.php | 24 +++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Repository/SaferPayPaymentRepository.php b/src/Repository/SaferPayPaymentRepository.php index 6d2bc87e..825ef8fb 100755 --- a/src/Repository/SaferPayPaymentRepository.php +++ b/src/Repository/SaferPayPaymentRepository.php @@ -69,7 +69,13 @@ public function getAllLogosEnabled() $query->from('saferpay_logo'); $query->where('active = "1"'); - return Db::getInstance()->executeS($query); + $result = Db::getInstance()->executeS($query); + + if (!$result) { + return []; + } + + return $result; } public function getActivePaymentMethods() @@ -79,7 +85,13 @@ public function getActivePaymentMethods() $query->from('saferpay_payment'); $query->where('active = "1"'); - return Db::getInstance()->executeS($query); + $result = Db::getInstance()->executeS($query); + + if (!$result) { + return []; + } + + return $result; } public function getActivePaymentMethodsNames() @@ -89,7 +101,13 @@ public function getActivePaymentMethodsNames() $query->from('saferpay_payment'); $query->where('active = "1"'); - return Db::getInstance()->executeS($query); + $result = Db::getInstance()->executeS($query); + + if (!$result) { + return []; + } + + return $result; } public function truncateTable() From 08b2b1e63e33e24784fcfcaa1770f026491c180e Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 17:12:00 +0300 Subject: [PATCH 14/32] [SL-244] rename --- saferpayofficial.php | 2 +- src/Repository/SaferPayPaymentRepository.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/saferpayofficial.php b/saferpayofficial.php index 0f21163f..7d8fea7b 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -206,7 +206,7 @@ public function hookPaymentOptions($params) \Invertus\SaferPay\Service\PaymentRestrictionValidation::class ); - $logosEnabled = $paymentRepository->getAllLogosEnabled(); + $logosEnabled = $paymentRepository->getAllActiveLogosNames(); $logosEnabled = array_column($logosEnabled, 'name'); $activePaymentMethods = $paymentRepository->getActivePaymentMethodsNames(); diff --git a/src/Repository/SaferPayPaymentRepository.php b/src/Repository/SaferPayPaymentRepository.php index 825ef8fb..9b16e20c 100755 --- a/src/Repository/SaferPayPaymentRepository.php +++ b/src/Repository/SaferPayPaymentRepository.php @@ -62,7 +62,7 @@ public function isLogoEnabledByName($paymentName) return Db::getInstance()->getValue($query); } - public function getAllLogosEnabled() + public function getAllActiveLogosNames() { $query = new DbQuery(); $query->select('name'); From 3794fbe0ee24bc7e0af1257a9636a98df2c3b194 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 16:14:08 +0300 Subject: [PATCH 15/32] [SL-234] fix --- saferpayofficial.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/saferpayofficial.php b/saferpayofficial.php index bd36b49e..d3bb6a69 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -365,9 +365,7 @@ public function hookDisplayCustomerAccount() return; } if (\Invertus\SaferPay\Config\SaferPayConfig::isVersion17()) { - return $this->context->smarty->fetch( - 'module:saferpayofficial/views/templates/hook/front/MyAccount.tpl' - ); + return $this->display(__FILE__, 'front/MyAccount.tpl'); } return $this->display(__FILE__, 'front/MyAccount_16.tpl'); From c5bb91180494e3173cff2aa362e44b7b4649e482 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 12:29:44 +0300 Subject: [PATCH 16/32] fix --- views/templates/front/credit_cards.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/templates/front/credit_cards.tpl b/views/templates/front/credit_cards.tpl index d042b193..0e69ebf2 100755 --- a/views/templates/front/credit_cards.tpl +++ b/views/templates/front/credit_cards.tpl @@ -51,7 +51,7 @@ {foreach $rows as $row} - {$row nofilter|escape:'htmlall':'UTF-8'} + {$row escape:'htmlall':'UTF-8'|nofilter} {/foreach} From ad24887ece78f6bfa686c81f4f8c88ec668c2548 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 12:30:15 +0300 Subject: [PATCH 17/32] revert ajax --- controllers/front/ajax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index f96384bf..f221d68e 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -77,7 +77,7 @@ protected function processGetStatus() $this->ajaxDie(json_encode([ 'saferpayOrder' => json_encode($saferPayOrder), - 'isFinished' => true, + 'isFinished' => $saferPayOrder->authorized || $saferPayOrder->captured || $saferPayOrder->pending, 'href' => $this->context->link->getModuleLink( $this->module->name, $this->getSuccessControllerName($isBusinessLicence, $fieldToken), From 530f58f498d8a5d70e7d634873004817e34c5a04 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 12:53:03 +0300 Subject: [PATCH 18/32] [KS-252] logic --- controllers/front/return.php | 60 +++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index 1ce79fd0..ce7cc8b7 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -24,9 +24,11 @@ use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; +use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; use Invertus\SaferPay\DTO\Response\Assert\AssertBody; use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Exception\Api\SaferPayApiException; +use Invertus\SaferPay\Processor\CheckoutProcessor; use Invertus\SaferPay\Service\SaferPayOrderStatusService; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAssertion; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; @@ -44,7 +46,62 @@ public function postProcess() $cartId = (int) Tools::getValue('cartId'); $order = new Order($this->getOrderId($cartId)); - if (!$order->id) { + /** @var SaferPayTransactionAssertion $transactionAssert */ + $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); + + $assertResponseBody = $transactionAssert->assert($cartId); + $transactionStatus = $assertResponseBody->getTransaction()->getStatus(); + + if (Tools::getValue('isBusinessLicence')) { + /** @var CheckoutProcessor $checkoutProcessor **/ + $checkoutProcessor = $this->module->getService(CheckoutProcessor::class); + $checkoutData = CheckoutData::create( + (int) $cartId, + $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod(), + (int) Configuration::get(SaferPayConfig::IS_BUSINESS_LICENCE) + ); + + $checkoutData->setOrderStatus($transactionStatus); + $checkoutProcessor->run($checkoutData); + + $orderId = $this->getOrderId($cartId); + + $order = new Order($orderId); + + if (!$assertResponseBody->getLiability()->getLiabilityShift() && + in_array($order->payment, SaferPayConfig::SUPPORTED_3DS_PAYMENT_METHODS) && + (int) Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D) === SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D_CANCEL + ) { + /** @var SaferPayOrderStatusService $orderStatusService */ + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); + $orderStatusService->cancel($order); + } + + //NOTE to get latest information possible and not override new information. + $order = new Order($orderId); + $paymentMethod = $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod(); + + // if payment does not support order capture, it means it always auto-captures it (at least with accountToAccount payment), + // so in this case if status comes back "captured" we just update the order state accordingly + if (!SaferPayConfig::supportsOrderCapture($paymentMethod) && + $transactionStatus === TransactionStatus::CAPTURED + ) { + /** @var SaferPayOrderStatusService $orderStatusService */ + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); + $orderStatusService->setComplete($order); + + return; + } + + if (SaferPayConfig::supportsOrderCapture($paymentMethod) && + (int) Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR) === SaferPayConfig::DEFAULT_PAYMENT_BEHAVIOR_CAPTURE && + $transactionStatus !== TransactionStatus::CAPTURED + ) { + /** @var SaferPayOrderStatusService $orderStatusService */ + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); + $orderStatusService->capture($order); + } + return; } @@ -55,6 +112,7 @@ public function postProcess() /** @var SaferPayOrderStatusService $orderStatusService */ $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); + if ($transactionResponse->getTransaction()->getStatus() === TransactionStatus::PENDING) { $orderStatusService->setPending($order); } From 03252a165d66a30fb5b0d2c6df22522d898326ae Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 13:43:53 +0300 Subject: [PATCH 19/32] [SL-252] added try catch --- controllers/front/return.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index ce7cc8b7..5fde8b16 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -49,8 +49,12 @@ public function postProcess() /** @var SaferPayTransactionAssertion $transactionAssert */ $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); - $assertResponseBody = $transactionAssert->assert($cartId); - $transactionStatus = $assertResponseBody->getTransaction()->getStatus(); + try { + $assertResponseBody = $transactionAssert->assert($cartId); + $transactionStatus = $assertResponseBody->getTransaction()->getStatus(); + } catch (Exception $e) { + \PrestaShopLogger::addLog($e->getMessage()); + } if (Tools::getValue('isBusinessLicence')) { /** @var CheckoutProcessor $checkoutProcessor **/ From 42cffbec87c6c6d42c3a529d376d8df8c6741acb Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 13:45:39 +0300 Subject: [PATCH 20/32] [SL-252] note --- controllers/front/return.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/controllers/front/return.php b/controllers/front/return.php index 5fde8b16..02775635 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -56,6 +56,9 @@ public function postProcess() \PrestaShopLogger::addLog($e->getMessage()); } + /** + * NOTE: This flow is for hosted iframe payment method + */ if (Tools::getValue('isBusinessLicence')) { /** @var CheckoutProcessor $checkoutProcessor **/ $checkoutProcessor = $this->module->getService(CheckoutProcessor::class); From 6452898d33b729d8ce65cdef498e437564e7e178 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 14:06:07 +0300 Subject: [PATCH 21/32] [SL-252] fix --- controllers/front/return.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index 02775635..f6e212d7 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -108,24 +108,13 @@ public function postProcess() $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); $orderStatusService->capture($order); } - - return; } - try { - /** @var SaferPayTransactionAssertion $transactionAssert */ - $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); - $transactionResponse = $transactionAssert->assert($cartId, false); - - /** @var SaferPayOrderStatusService $orderStatusService */ - $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); + /** @var SaferPayOrderStatusService $orderStatusService */ + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); - if ($transactionResponse->getTransaction()->getStatus() === TransactionStatus::PENDING) { - $orderStatusService->setPending($order); - } - } catch (SaferPayApiException $e) { - \PrestaShopLogger::addLog($e->getMessage()); - // we only care if we have a response with pending status, else we skip further actions + if ($assertResponseBody->getTransaction()->getStatus() === TransactionStatus::PENDING) { + $orderStatusService->setPending($order); } } /** From 9234c25d595c17a668530b72dd191ccff4db117f Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 14:21:38 +0300 Subject: [PATCH 22/32] [SL-252] try catch --- controllers/front/return.php | 88 +++++++++++++++++------------------- 1 file changed, 42 insertions(+), 46 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index f6e212d7..c9ba7468 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -60,53 +60,49 @@ public function postProcess() * NOTE: This flow is for hosted iframe payment method */ if (Tools::getValue('isBusinessLicence')) { - /** @var CheckoutProcessor $checkoutProcessor **/ - $checkoutProcessor = $this->module->getService(CheckoutProcessor::class); - $checkoutData = CheckoutData::create( - (int) $cartId, - $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod(), - (int) Configuration::get(SaferPayConfig::IS_BUSINESS_LICENCE) - ); - $checkoutData->setOrderStatus($transactionStatus); - $checkoutProcessor->run($checkoutData); - - $orderId = $this->getOrderId($cartId); - - $order = new Order($orderId); - - if (!$assertResponseBody->getLiability()->getLiabilityShift() && - in_array($order->payment, SaferPayConfig::SUPPORTED_3DS_PAYMENT_METHODS) && - (int) Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D) === SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D_CANCEL - ) { - /** @var SaferPayOrderStatusService $orderStatusService */ - $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); - $orderStatusService->cancel($order); - } - - //NOTE to get latest information possible and not override new information. - $order = new Order($orderId); - $paymentMethod = $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod(); - - // if payment does not support order capture, it means it always auto-captures it (at least with accountToAccount payment), - // so in this case if status comes back "captured" we just update the order state accordingly - if (!SaferPayConfig::supportsOrderCapture($paymentMethod) && - $transactionStatus === TransactionStatus::CAPTURED - ) { - /** @var SaferPayOrderStatusService $orderStatusService */ - $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); - $orderStatusService->setComplete($order); - - return; - } - - if (SaferPayConfig::supportsOrderCapture($paymentMethod) && - (int) Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR) === SaferPayConfig::DEFAULT_PAYMENT_BEHAVIOR_CAPTURE && - $transactionStatus !== TransactionStatus::CAPTURED - ) { - /** @var SaferPayOrderStatusService $orderStatusService */ - $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); - $orderStatusService->capture($order); + try { + /** @var CheckoutProcessor $checkoutProcessor * */ + $checkoutProcessor = $this->module->getService(CheckoutProcessor::class); + $checkoutData = CheckoutData::create( + (int)$cartId, + $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod(), + (int)Configuration::get(SaferPayConfig::IS_BUSINESS_LICENCE) + ); + $checkoutData->setOrderStatus($transactionStatus); + $checkoutProcessor->run($checkoutData); + $orderId = $this->getOrderId($cartId); + $order = new Order($orderId); + if (!$assertResponseBody->getLiability()->getLiabilityShift() && + in_array($order->payment, SaferPayConfig::SUPPORTED_3DS_PAYMENT_METHODS) && + (int)Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D) === SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D_CANCEL + ) { + /** @var SaferPayOrderStatusService $orderStatusService */ + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); + $orderStatusService->cancel($order); + }//NOTE to get latest information possible and not override new information. + $order = new Order($orderId); + $paymentMethod = $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod();// if payment does not support order capture, it means it always auto-captures it (at least with accountToAccount payment), + // so in this case if status comes back "captured" we just update the order state accordingly + if (!SaferPayConfig::supportsOrderCapture($paymentMethod) && + $transactionStatus === TransactionStatus::CAPTURED + ) { + /** @var SaferPayOrderStatusService $orderStatusService */ + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); + $orderStatusService->setComplete($order); + + return; + } + if (SaferPayConfig::supportsOrderCapture($paymentMethod) && + (int)Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR) === SaferPayConfig::DEFAULT_PAYMENT_BEHAVIOR_CAPTURE && + $transactionStatus !== TransactionStatus::CAPTURED + ) { + /** @var SaferPayOrderStatusService $orderStatusService */ + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); + $orderStatusService->capture($order); + } + } catch (Exception $e) { + \PrestaShopLogger::addLog($e->getMessage()); } } From 64293712540e5ad7861208f6996ceb8b54a2afbd Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 14:46:28 +0300 Subject: [PATCH 23/32] [SL-252] fix --- controllers/front/return.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index c9ba7468..f393fa9f 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -54,6 +54,9 @@ public function postProcess() $transactionStatus = $assertResponseBody->getTransaction()->getStatus(); } catch (Exception $e) { \PrestaShopLogger::addLog($e->getMessage()); + // redirect with notifiation + $this->warning[] = $this->module->l('An error occurred. Please contact support', self::FILENAME); + $this->redirectWithNotifications($this->context->link->getPageLink('index', true, null)); } /** @@ -64,14 +67,18 @@ public function postProcess() try { /** @var CheckoutProcessor $checkoutProcessor * */ $checkoutProcessor = $this->module->getService(CheckoutProcessor::class); + $checkoutData = CheckoutData::create( (int)$cartId, $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod(), (int)Configuration::get(SaferPayConfig::IS_BUSINESS_LICENCE) ); $checkoutData->setOrderStatus($transactionStatus); + $checkoutProcessor->run($checkoutData); + $orderId = $this->getOrderId($cartId); + $order = new Order($orderId); if (!$assertResponseBody->getLiability()->getLiabilityShift() && in_array($order->payment, SaferPayConfig::SUPPORTED_3DS_PAYMENT_METHODS) && @@ -80,9 +87,13 @@ public function postProcess() /** @var SaferPayOrderStatusService $orderStatusService */ $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); $orderStatusService->cancel($order); - }//NOTE to get latest information possible and not override new information. + } + + //NOTE to get latest information possible and not override new information. $order = new Order($orderId); + $paymentMethod = $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod();// if payment does not support order capture, it means it always auto-captures it (at least with accountToAccount payment), + // so in this case if status comes back "captured" we just update the order state accordingly if (!SaferPayConfig::supportsOrderCapture($paymentMethod) && $transactionStatus === TransactionStatus::CAPTURED @@ -93,6 +104,7 @@ public function postProcess() return; } + if (SaferPayConfig::supportsOrderCapture($paymentMethod) && (int)Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR) === SaferPayConfig::DEFAULT_PAYMENT_BEHAVIOR_CAPTURE && $transactionStatus !== TransactionStatus::CAPTURED From 6311c4ffe626d42c9deaa39219da5e27e9943aae Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 14:47:14 +0300 Subject: [PATCH 24/32] [SL-252] fix --- controllers/front/return.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/controllers/front/return.php b/controllers/front/return.php index f393fa9f..2c70daa6 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -112,6 +112,8 @@ public function postProcess() /** @var SaferPayOrderStatusService $orderStatusService */ $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); $orderStatusService->capture($order); + + return; } } catch (Exception $e) { \PrestaShopLogger::addLog($e->getMessage()); From 78952dd7093c1235960e9a091a1405c1dfa6cb10 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 14:47:59 +0300 Subject: [PATCH 25/32] [SL-252] fix --- controllers/front/return.php | 1 - 1 file changed, 1 deletion(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index 2c70daa6..b61cb08f 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -63,7 +63,6 @@ public function postProcess() * NOTE: This flow is for hosted iframe payment method */ if (Tools::getValue('isBusinessLicence')) { - try { /** @var CheckoutProcessor $checkoutProcessor * */ $checkoutProcessor = $this->module->getService(CheckoutProcessor::class); From 77258ca935b5b25b74d4812c125e3f3f7e8e4789 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 15:24:55 +0300 Subject: [PATCH 26/32] fix --- controllers/front/return.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index b61cb08f..e4471e50 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -54,9 +54,8 @@ public function postProcess() $transactionStatus = $assertResponseBody->getTransaction()->getStatus(); } catch (Exception $e) { \PrestaShopLogger::addLog($e->getMessage()); - // redirect with notifiation $this->warning[] = $this->module->l('An error occurred. Please contact support', self::FILENAME); - $this->redirectWithNotifications($this->context->link->getPageLink('index', true, null)); + $this->redirectWithNotifications($this->getRedirectionToControllerUrl('fail')); } /** @@ -116,6 +115,8 @@ public function postProcess() } } catch (Exception $e) { \PrestaShopLogger::addLog($e->getMessage()); + $this->warning[] = $this->module->l('An error occurred. Please contact support', self::FILENAME); + $this->redirectWithNotifications($this->getRedirectionToControllerUrl('fail')); } } @@ -252,4 +253,24 @@ private function getOrderId($cartId) return Order::getOrderByCartId($cartId); } } + + /** + * @param string $controllerName + * + * @return string + */ + private function getRedirectionToControllerUrl($controllerName) + { + return $this->context->link->getModuleLink( + $this->module->name, + $controllerName, + [ + 'cartId' => $this->context->cart->id, + 'orderId' => Order::getOrderByCartId($this->context->cart->id), + 'secureKey' => $this->context->cart->secure_key, + 'moduleId' => $this->module->id, + ], + true + ); + } } From 1222fc9c35c9673439aecdaa3842e8eec207bb85 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 15:33:35 +0300 Subject: [PATCH 27/32] [SL-252] fix --- controllers/front/return.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index e4471e50..598d93e3 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -45,6 +45,18 @@ public function postProcess() { $cartId = (int) Tools::getValue('cartId'); $order = new Order($this->getOrderId($cartId)); + $secureKey = Tools::getValue('secureKey'); + $cart = new Cart($cartId); + + if (!Validate::isLoadedObject($cart)) { + $this->warning[] = $this->module->l('An unknown error error occurred. Please contact support', self::FILENAME); + $this->redirectWithNotifications($this->getRedirectionToControllerUrl('fail')); + } + + if ($cart->secure_key !== $secureKey) { + $this->warning[] = $this->module->l('Error. Insecure cart', self::FILENAME); + $this->redirectWithNotifications($this->getRedirectionToControllerUrl('fail')); + } /** @var SaferPayTransactionAssertion $transactionAssert */ $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); @@ -120,11 +132,15 @@ public function postProcess() } } - /** @var SaferPayOrderStatusService $orderStatusService */ - $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); - - if ($assertResponseBody->getTransaction()->getStatus() === TransactionStatus::PENDING) { - $orderStatusService->setPending($order); + try { + /** @var SaferPayOrderStatusService $orderStatusService */ + $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); + if ($assertResponseBody->getTransaction()->getStatus() === TransactionStatus::PENDING) { + $orderStatusService->setPending($order); + } + } catch (Exception $e) { + \PrestaShopLogger::addLog($e->getMessage()); + // if we can't set order status to pending, we don't want to stop the process } } /** From a685b4ead4beb46bc5c819834f4b0e3003da177a Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 09:57:14 +0300 Subject: [PATCH 28/32] [SL-252] fix --- controllers/front/return.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index 598d93e3..ce2096bf 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -138,9 +138,9 @@ public function postProcess() if ($assertResponseBody->getTransaction()->getStatus() === TransactionStatus::PENDING) { $orderStatusService->setPending($order); } - } catch (Exception $e) { + } catch (SaferPayApiException $e) { \PrestaShopLogger::addLog($e->getMessage()); - // if we can't set order status to pending, we don't want to stop the process + // we only care if we have a response with pending status, else we skip further actions } } /** From 3747819ea4b1d4e611b2cb8a58dd96daa6d82d04 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 12:58:41 +0300 Subject: [PATCH 29/32] typo --- views/templates/front/credit_cards.tpl | 2 +- views/templates/front/credit_cards_16.tpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/views/templates/front/credit_cards.tpl b/views/templates/front/credit_cards.tpl index 0e69ebf2..e2631bc9 100755 --- a/views/templates/front/credit_cards.tpl +++ b/views/templates/front/credit_cards.tpl @@ -51,7 +51,7 @@ {foreach $rows as $row} - {$row escape:'htmlall':'UTF-8'|nofilter} + {$row|escape:'htmlall':'UTF-8'|nofilter} {/foreach} diff --git a/views/templates/front/credit_cards_16.tpl b/views/templates/front/credit_cards_16.tpl index 292aa37e..8065bbfe 100755 --- a/views/templates/front/credit_cards_16.tpl +++ b/views/templates/front/credit_cards_16.tpl @@ -53,7 +53,7 @@ {foreach $rows as $row} - {$row|escape:'htmlall':'UTF-8' nofilter} + {$row|escape:'htmlall':'UTF-8'|nofilter} {/foreach} From 6f2a694f5f3e3e401061ce243d7e8d049f49ca69 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 13:00:44 +0300 Subject: [PATCH 30/32] removed order instance --- controllers/front/return.php | 1 - 1 file changed, 1 deletion(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index ce2096bf..baf637df 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -100,7 +100,6 @@ public function postProcess() } //NOTE to get latest information possible and not override new information. - $order = new Order($orderId); $paymentMethod = $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod();// if payment does not support order capture, it means it always auto-captures it (at least with accountToAccount payment), From beebabfab216c22778ba6705b8788e9de7146609 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 13:02:23 +0300 Subject: [PATCH 31/32] no ssl --- controllers/front/return.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index baf637df..c733dc95 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -284,8 +284,7 @@ private function getRedirectionToControllerUrl($controllerName) 'orderId' => Order::getOrderByCartId($this->context->cart->id), 'secureKey' => $this->context->cart->secure_key, 'moduleId' => $this->module->id, - ], - true + ] ); } } From 22854bf3052abd8c9bf510fe16099f9fc10131c8 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 13:47:10 +0300 Subject: [PATCH 32/32] csfixer --- ...dminSaferPayOfficialSettingsController.php | 2 +- controllers/front/ajax.php | 4 +-- controllers/front/iframe.php | 1 - controllers/front/notify.php | 8 ++--- controllers/front/return.php | 13 ++++--- controllers/front/successHosted.php | 3 -- controllers/front/successIFrame.php | 4 --- saferpayofficial.php | 6 ++-- src/Api/Request/AssertService.php | 3 +- src/Controller/AbstractSaferPayController.php | 1 - src/Controller/Front/index.php | 2 +- .../Order/Action/UpdateOrderStatusAction.php | 1 - src/Core/Payment/DTO/CheckoutData.php | 34 +++++++++---------- src/Exception/CouldNotProcessCheckout.php | 2 +- src/Exception/SaferPayException.php | 5 ++- src/Processor/CheckoutProcessor.php | 9 +++-- src/Processor/index.php | 2 +- .../InitializeRequestObjectCreator.php | 2 -- src/Service/SaferPayInitialize.php | 2 -- .../SaferPayTransactionAuthorization.php | 1 - upgrade/install-1.1.8.php | 2 +- upgrade/install-1.2.2.php | 1 - 22 files changed, 43 insertions(+), 65 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialSettingsController.php b/controllers/admin/AdminSaferPayOfficialSettingsController.php index fdd33062..3b310c5c 100755 --- a/controllers/admin/AdminSaferPayOfficialSettingsController.php +++ b/controllers/admin/AdminSaferPayOfficialSettingsController.php @@ -400,7 +400,7 @@ private function displayConfigurationSettings() 'title' => $this->module->l('Description', self::FILE_NAME), 'type' => 'text', 'desc' => 'This description is visible in payment page also in payment confirmation email', - 'class' => 'fixed-width-xxl' + 'class' => 'fixed-width-xxl', ], ], 'buttons' => [ diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index f221d68e..34a66a14 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -71,7 +71,7 @@ protected function processGetStatus() if (!$saferPayOrder->id || $saferPayOrder->canceled) { $this->ajaxDie(json_encode([ 'isFinished' => true, - 'href' => $this->getFailControllerLink($cartId, $secureKey, $moduleId) + 'href' => $this->getFailControllerLink($cartId, $secureKey, $moduleId), ])); } @@ -88,7 +88,7 @@ protected function processGetStatus() 'secureKey' => $secureKey, 'selectedCard' => $selectedCard, ] - ) + ), ])); } diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php index 7fb34709..262d30a3 100755 --- a/controllers/front/iframe.php +++ b/controllers/front/iframe.php @@ -98,7 +98,6 @@ public function initContent() ); $redirectUrl = $checkoutController->execute($checkoutData); - } catch (\Exception $exception) { $redirectUrl = $this->context->link->getModuleLink( $this->module->name, diff --git a/controllers/front/notify.php b/controllers/front/notify.php index d9fcaf5a..0155c521 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -201,7 +201,8 @@ public function postProcess() die($this->module->l('Success', self::FILENAME)); } - private function assertTransaction($cartId) { + private function assertTransaction($cartId) + { /** @var SaferPayTransactionAssertion $transactionAssert */ $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); @@ -217,10 +218,9 @@ private function getOrderId($cartId) { if (method_exists('Order', 'getIdByCartId')) { return Order::getIdByCartId($cartId); - } else { - // For PrestaShop 1.6 use the alternative method - return Order::getOrderByCartId($cartId); } + // For PrestaShop 1.6 use the alternative method + return Order::getOrderByCartId($cartId); } protected function displayMaintenancePage() diff --git a/controllers/front/return.php b/controllers/front/return.php index c733dc95..48cb8db7 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -79,9 +79,9 @@ public function postProcess() $checkoutProcessor = $this->module->getService(CheckoutProcessor::class); $checkoutData = CheckoutData::create( - (int)$cartId, + (int) $cartId, $assertResponseBody->getPaymentMeans()->getBrand()->getPaymentMethod(), - (int)Configuration::get(SaferPayConfig::IS_BUSINESS_LICENCE) + (int) Configuration::get(SaferPayConfig::IS_BUSINESS_LICENCE) ); $checkoutData->setOrderStatus($transactionStatus); @@ -92,7 +92,7 @@ public function postProcess() $order = new Order($orderId); if (!$assertResponseBody->getLiability()->getLiabilityShift() && in_array($order->payment, SaferPayConfig::SUPPORTED_3DS_PAYMENT_METHODS) && - (int)Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D) === SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D_CANCEL + (int) Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D) === SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D_CANCEL ) { /** @var SaferPayOrderStatusService $orderStatusService */ $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); @@ -115,7 +115,7 @@ public function postProcess() } if (SaferPayConfig::supportsOrderCapture($paymentMethod) && - (int)Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR) === SaferPayConfig::DEFAULT_PAYMENT_BEHAVIOR_CAPTURE && + (int) Configuration::get(SaferPayConfig::PAYMENT_BEHAVIOR) === SaferPayConfig::DEFAULT_PAYMENT_BEHAVIOR_CAPTURE && $transactionStatus !== TransactionStatus::CAPTURED ) { /** @var SaferPayOrderStatusService $orderStatusService */ @@ -263,10 +263,9 @@ private function getOrderId($cartId) { if (method_exists('Order', 'getIdByCartId')) { return Order::getIdByCartId($cartId); - } else { - // For PrestaShop 1.6 use the alternative method - return Order::getOrderByCartId($cartId); } + // For PrestaShop 1.6 use the alternative method + return Order::getOrderByCartId($cartId); } /** diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index 9998633d..63794782 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -21,12 +21,9 @@ *@license SIX Payment Services */ -use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; -use Invertus\SaferPay\Service\SaferPayOrderStatusService; -use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; if (!defined('_PS_VERSION_')) { exit; diff --git a/controllers/front/successIFrame.php b/controllers/front/successIFrame.php index a7ce3b5d..b7450363 100755 --- a/controllers/front/successIFrame.php +++ b/controllers/front/successIFrame.php @@ -21,13 +21,9 @@ *@license SIX Payment Services */ -use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; -use Invertus\SaferPay\Exception\Api\SaferPayApiException; -use Invertus\SaferPay\Service\SaferPayOrderStatusService; -use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; if (!defined('_PS_VERSION_')) { exit; diff --git a/saferpayofficial.php b/saferpayofficial.php index ef9266d1..9892ed2c 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -216,7 +216,7 @@ public function hookPaymentOptions($params) foreach ($paymentMethods as $paymentMethod) { $paymentMethod['paymentMethod'] = str_replace(' ', '', $paymentMethod['paymentMethod']); - if(!in_array($paymentMethod['paymentMethod'], $activePaymentMethods)) { + if (!in_array($paymentMethod['paymentMethod'], $activePaymentMethods)) { continue; } @@ -689,8 +689,8 @@ private function displayInAdminOrderPage(array $params) ); } else { $action = $this->context->link->getAdminLink( - self::ADMIN_ORDER_CONTROLLER - ) . '&id_order=' . (int) $orderId; + self::ADMIN_ORDER_CONTROLLER + ) . '&id_order=' . (int) $orderId; } $assertId = $orderRepo->getAssertIdBySaferPayOrderId($saferPayOrderId); diff --git a/src/Api/Request/AssertService.php b/src/Api/Request/AssertService.php index d1297a41..fc0d2871 100755 --- a/src/Api/Request/AssertService.php +++ b/src/Api/Request/AssertService.php @@ -29,7 +29,6 @@ use Invertus\SaferPay\DTO\Response\Assert\AssertBody; use Invertus\SaferPay\EntityBuilder\SaferPayAssertBuilder; use Invertus\SaferPay\Exception\Api\SaferPayApiException; -use Invertus\SaferPay\Exception\Api\TransactionDeclinedException; use Invertus\SaferPay\Service\Response\AssertResponseObjectCreator; use SaferPayOrder; @@ -84,7 +83,7 @@ public function assert(AssertRequest $assertRequest, $saferPayOrderId) // also we call authorize method in some of the success controllers, so if we leave the logic here, // we get an error with TRANSACTION_IN_WRONG_STATE if ($saferPayOrder->is_transaction) { - $assertApi = self::ASSERT_API_TRANSACTION; + $assertApi = self::ASSERT_API_TRANSACTION; } try { diff --git a/src/Controller/AbstractSaferPayController.php b/src/Controller/AbstractSaferPayController.php index cac8b4a2..f6bfc003 100755 --- a/src/Controller/AbstractSaferPayController.php +++ b/src/Controller/AbstractSaferPayController.php @@ -82,7 +82,6 @@ protected function applyLock($resource) $this->lock->create($resource); if (!$this->lock->acquire()) { - if (!SaferPayConfig::isVersion17()) { return http_response_code(409); } diff --git a/src/Controller/Front/index.php b/src/Controller/Front/index.php index 7487f261..6b778722 100644 --- a/src/Controller/Front/index.php +++ b/src/Controller/Front/index.php @@ -21,7 +21,7 @@ *@license SIX Payment Services */ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); +header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); diff --git a/src/Core/Order/Action/UpdateOrderStatusAction.php b/src/Core/Order/Action/UpdateOrderStatusAction.php index 000ce93b..983c5fcf 100644 --- a/src/Core/Order/Action/UpdateOrderStatusAction.php +++ b/src/Core/Order/Action/UpdateOrderStatusAction.php @@ -60,6 +60,5 @@ public function run($orderId, $orderStatusId) } catch (\Exception $exception) { throw CouldNotChangeOrderStatus::unknownError(); } - } } diff --git a/src/Core/Payment/DTO/CheckoutData.php b/src/Core/Payment/DTO/CheckoutData.php index 7a48165d..a5cf6336 100644 --- a/src/Core/Payment/DTO/CheckoutData.php +++ b/src/Core/Payment/DTO/CheckoutData.php @@ -44,15 +44,14 @@ class CheckoutData private $status; public function __construct( - $cartId, - $paymentMethod, - $isBusinessLicense, - $selectedCard = -1, - $fieldToken = null, - $successController = null, - $isTransaction = false - ) - { + $cartId, + $paymentMethod, + $isBusinessLicense, + $selectedCard = -1, + $fieldToken = null, + $successController = null, + $isTransaction = false + ) { $this->cartId = $cartId; $this->paymentMethod = $paymentMethod; $this->isBusinessLicense = $isBusinessLicense; @@ -65,15 +64,14 @@ public function __construct( } public static function create( - $cartId, - $paymentMethod, - $isBusinessLicense, - $selectedCard = -1, - $fieldToken = null, - $successController = null, - $isTransaction = false - ) - { + $cartId, + $paymentMethod, + $isBusinessLicense, + $selectedCard = -1, + $fieldToken = null, + $successController = null, + $isTransaction = false + ) { return new self( $cartId, $paymentMethod, diff --git a/src/Exception/CouldNotProcessCheckout.php b/src/Exception/CouldNotProcessCheckout.php index b8b19281..e495daa4 100644 --- a/src/Exception/CouldNotProcessCheckout.php +++ b/src/Exception/CouldNotProcessCheckout.php @@ -75,4 +75,4 @@ public static function failedToCreateSaferPayOrder($cartId) ] ); } -} \ No newline at end of file +} diff --git a/src/Exception/SaferPayException.php b/src/Exception/SaferPayException.php index 41906751..851bd257 100644 --- a/src/Exception/SaferPayException.php +++ b/src/Exception/SaferPayException.php @@ -35,8 +35,7 @@ final public function __construct( $internalMessage, $code, array $context = [] - ) - { + ) { parent::__construct($internalMessage, $code); $this->context = $context; } @@ -53,4 +52,4 @@ public static function unknownError() ExceptionCode::UNKNOWN_ERROR ); } -} \ No newline at end of file +} diff --git a/src/Processor/CheckoutProcessor.php b/src/Processor/CheckoutProcessor.php index 41826f57..62405046 100644 --- a/src/Processor/CheckoutProcessor.php +++ b/src/Processor/CheckoutProcessor.php @@ -40,7 +40,6 @@ use Order; use PrestaShopException; use SaferPayOrder; -use Validate; class CheckoutProcessor { @@ -68,7 +67,8 @@ public function __construct( $this->saferPayOrderRepository = $saferPayOrderRepository; } - public function run(CheckoutData $data) { + public function run(CheckoutData $data) + { $cart = new Cart($data->getCartId()); if (!$cart) { @@ -217,9 +217,8 @@ private function getOrder($cartId) { if (method_exists('Order', 'getIdByCartId')) { return new Order(Order::getIdByCartId($cartId)); - } else { - // For PrestaShop 1.6 use the alternative method - return new Order(Order::getOrderByCartId($cartId)); } + // For PrestaShop 1.6 use the alternative method + return new Order(Order::getOrderByCartId($cartId)); } } diff --git a/src/Processor/index.php b/src/Processor/index.php index 7487f261..6b778722 100644 --- a/src/Processor/index.php +++ b/src/Processor/index.php @@ -21,7 +21,7 @@ *@license SIX Payment Services */ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); +header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); diff --git a/src/Service/Request/InitializeRequestObjectCreator.php b/src/Service/Request/InitializeRequestObjectCreator.php index 0ca1e5e4..906cd5aa 100755 --- a/src/Service/Request/InitializeRequestObjectCreator.php +++ b/src/Service/Request/InitializeRequestObjectCreator.php @@ -27,10 +27,8 @@ use Configuration; use Customer; use Invertus\SaferPay\Config\SaferPayConfig; -use Invertus\SaferPay\DTO\Request\RequestHeader; use Invertus\SaferPay\DTO\Request\Initialize\InitializeRequest; use Invertus\SaferPay\DTO\Request\Payer; -use PrestaShop\PrestaShop\Adapter\Shop\Context; if (!defined('_PS_VERSION_')) { exit; diff --git a/src/Service/SaferPayInitialize.php b/src/Service/SaferPayInitialize.php index e1cb6300..e4822f7e 100755 --- a/src/Service/SaferPayInitialize.php +++ b/src/Service/SaferPayInitialize.php @@ -34,8 +34,6 @@ use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; use Invertus\SaferPay\Factory\ModuleFactory; use Invertus\SaferPay\Service\Request\InitializeRequestObjectCreator; -use Invertus\SaferPay\Config\SaferPayConfig; -use Order; use SaferPayOfficial; if (!defined('_PS_VERSION_')) { diff --git a/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php b/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php index 92c1b2fa..b79bc354 100755 --- a/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php +++ b/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php @@ -30,7 +30,6 @@ use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\Request\AuthorizationRequestObjectCreator; use Invertus\SaferPay\Service\SaferPayOrderStatusService; -use Order; use SaferPayOrder; if (!defined('_PS_VERSION_')) { diff --git a/upgrade/install-1.1.8.php b/upgrade/install-1.1.8.php index d52c8914..636a4cb3 100644 --- a/upgrade/install-1.1.8.php +++ b/upgrade/install-1.1.8.php @@ -41,4 +41,4 @@ function upgrade_module_1_1_8(SaferPayOfficial $module) $module->registerHook('actionObjectOrderPaymentAddAfter'); return true; -} \ No newline at end of file +} diff --git a/upgrade/install-1.2.2.php b/upgrade/install-1.2.2.php index b0b04cc5..5e3f08fc 100644 --- a/upgrade/install-1.2.2.php +++ b/upgrade/install-1.2.2.php @@ -35,4 +35,3 @@ function upgrade_module_1_2_2($module) && $module->unregisterHook('actionOrderStatusUpdate') && Configuration::deleteByName('SAFERPAY_SEND_ORDER_CONFIRMATION'); } -