From 7678e2c00396da0baa4dc74644bf0a880ff9581b Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 15:49:28 +0300 Subject: [PATCH 01/40] [SV-34] added Logger --- src/Config/SaferPayConfig.php | 5 + src/EntityManager/EntityManagerInterface.php | 51 ++++++ src/EntityManager/ObjectModelUnitOfWork.php | 64 +++++++ src/Logger/Logger.php | 165 +++++++++++++++++++ 4 files changed, 285 insertions(+) create mode 100644 src/EntityManager/EntityManagerInterface.php create mode 100644 src/EntityManager/ObjectModelUnitOfWork.php diff --git a/src/Config/SaferPayConfig.php b/src/Config/SaferPayConfig.php index cb8997a6..51641801 100755 --- a/src/Config/SaferPayConfig.php +++ b/src/Config/SaferPayConfig.php @@ -425,6 +425,11 @@ public static function isTestMode() return (bool) Configuration::get(self::TEST_MODE); } + public static function isDebugMode() + { + return (bool) Configuration::get(self::SAFERPAY_DEBUG_MODE); + } + public static function isVersion17() { return (bool) version_compare(_PS_VERSION_, '1.7', '>='); diff --git a/src/EntityManager/EntityManagerInterface.php b/src/EntityManager/EntityManagerInterface.php new file mode 100644 index 00000000..ed7bbd7c --- /dev/null +++ b/src/EntityManager/EntityManagerInterface.php @@ -0,0 +1,51 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +namespace Invertus\SaferPay\EntityManager; + +if (!defined('_PS_VERSION_')) { + exit; +} + +interface EntityManagerInterface +{ + /** + * @param \ObjectModel $model + * @param string $unitOfWorkType - @see ObjectModelUnitOfWork + * @param string|null $specificKey + * + * @return EntityManagerInterface + */ + public function persist( + \ObjectModel $model, + $unitOfWorkType, + $specificKey = null + ); + + /** + * @return array<\ObjectModel> + * + * @throws \PrestaShopException + */ + public function flush(); +} diff --git a/src/EntityManager/ObjectModelUnitOfWork.php b/src/EntityManager/ObjectModelUnitOfWork.php new file mode 100644 index 00000000..7a969693 --- /dev/null +++ b/src/EntityManager/ObjectModelUnitOfWork.php @@ -0,0 +1,64 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +namespace Invertus\SaferPay\EntityManager; + +if (!defined('_PS_VERSION_')) { + exit; +} + +/** In memory entity manager object model unit of work */ +class ObjectModelUnitOfWork +{ + const UNIT_OF_WORK_SAVE = 'UNIT_OF_WORK_SAVE'; + const UNIT_OF_WORK_DELETE = 'UNIT_OF_WORK_DELETE'; + + private $work = []; + + public function setWork(\ObjectModel $objectModel, $unitOfWorkType, $specificKey) + { + $work = [ + 'unit_of_work_type' => $unitOfWorkType, + 'object' => $objectModel, + ]; + + if (!is_null($specificKey)) { + $this->work[$specificKey] = $work; + } else { + $this->work[] = $work; + } + } + + /** + * @return array + */ + public function getWork() + { + return $this->work; + } + + public function clearWork() + { + $this->work = []; + } +} diff --git a/src/Logger/Logger.php b/src/Logger/Logger.php index ab849a15..cdf60eca 100644 --- a/src/Logger/Logger.php +++ b/src/Logger/Logger.php @@ -23,7 +23,172 @@ namespace Invertus\SaferPay\Logger; +use Invertus\SaferPay\Adapter\Configuration; +use Invertus\SaferPay\Adapter\LegacyContext; +use Invertus\SaferPay\Config\SaferPayConfig; +use Invertus\Saferpay\Context\GlobalShopContext; +use Invertus\SaferPay\EntityManager\EntityManagerInterface; +use Invertus\SaferPay\EntityManager\ObjectModelUnitOfWork; +use Invertus\SaferPay\Logger\Formatter\LogFormatterInterface; +use Invertus\SaferPay\Provider\BasicIdempotencyProvider; +use KlarnaPayment\Module\Infrastructure\Logger\Repository\PrestashopLoggerRepositoryInterface; + class Logger { + const FILE_NAME = 'Logger'; + const LOG_OBJECT_TYPE = 'saferpayLog'; + + const SEVERITY_INFO = 1; + const SEVERITY_WARNING = 2; + const SEVERITY_ERROR = 3; + + private $logFormatter; + private $globalShopContext; + private $configuration; + private $context; + private $entityManager; + private $idempotencyProvider; + private $prestashopLoggerRepository; + + public function __construct( + LogFormatterInterface $logFormatter, + GlobalShopContext $globalShopContext, + Configuration $configuration, + LegacyContext $context, + EntityManagerInterface $entityManager, + BasicIdempotencyProvider $idempotencyProvider, + PrestashopLoggerRepositoryInterface $prestashopLoggerRepository + ) { + $this->logFormatter = $logFormatter; + $this->globalShopContext = $globalShopContext; + $this->configuration = $configuration; + $this->context = $context; + $this->entityManager = $entityManager; + $this->idempotencyProvider = $idempotencyProvider; + $this->prestashopLoggerRepository = $prestashopLoggerRepository; + } + + public function emergency($message, array $context = []) + { + $this->log( + $this->configuration->getAsInteger( + 'PS_LOGS_BY_EMAIL', + $this->globalShopContext->getShopId() + ), + $message, + $context + ); + } + + public function alert($message, array $context = []) + { + $this->log(self::SEVERITY_WARNING, $message, $context); + } + + public function critical($message, array $context = []) + { + $this->log( + $this->configuration->getAsInteger( + 'PS_LOGS_BY_EMAIL', + $this->globalShopContext->getShopId() + ), + $message, + $context + ); + } + + public function error($message, array $context = []) + { + $this->log(self::SEVERITY_ERROR, $message, $context); + } + + public function warning($message, array $context = []) + { + $this->log(self::SEVERITY_WARNING, $message, $context); + } + + public function notice($message, array $context = []) + { + $this->log(self::SEVERITY_INFO, $message, $context); + } + + public function info($message, array $context = []) + { + $this->log(self::SEVERITY_INFO, $message, $context); + } + + public function debug($message, array $context = []) + { + if (!SaferPayConfig::isDebugMode()) { + return; + } + + $this->log(self::SEVERITY_INFO, $message, $context); + } + + public function log($level, $message, array $context = []) + { + $idempotencyKey = $this->idempotencyProvider->getIdempotencyKey(); + + \PrestaShopLogger::addLog( + $this->logFormatter->getMessage($message), + $level, + null, + self::LOG_OBJECT_TYPE, + $idempotencyKey + ); + + $logId = $this->prestashopLoggerRepository->getLogIdByObjectId( + $idempotencyKey, + $this->globalShopContext->getShopId() + ); + + if (!$logId) { + return; + } + + $this->logContext($logId, $context); + } + + private function logContext($logId, array $context) + { + $request = ''; + $response = ''; + + if (isset($context['request'])) { + $request = $context['request']; + unset($context['request']); + } + + if (isset($context['response'])) { + $response = $context['response']; + unset($context['response']); + } + + if (isset($context['correlation-id'])) { + $correlationId = $context['correlation-id']; + unset($context['correlation-id']); + } + + $log = new \SaferPayLog(); + $log->id_log = $logId; + $log->id_shop = $this->globalShopContext->getShopId(); + $log->context = json_encode($this->getFilledContextWithShopData($context)); + $log->request = json_encode($request); + $log->response = json_encode($response); + + $this->entityManager->persist($log, ObjectModelUnitOfWork::UNIT_OF_WORK_SAVE); + $this->entityManager->flush(); + } + + private function getFilledContextWithShopData(array $context = []) + { + $context['context_id_customer'] = $this->context->getCustomerId(); + $context['id_shop'] = $this->globalShopContext->getShopId(); + $context['currency'] = $this->globalShopContext->getCurrencyIso(); + $context['id_language'] = $this->globalShopContext->getLanguageId(); + + return $context; + } } From 03bdc2bbbc06db4b62f63811ac0fb46608aaf99e Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 15:51:01 +0300 Subject: [PATCH 02/40] [SV-34] added LoggerInterface --- src/Logger/LoggerInterface.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Logger/LoggerInterface.php diff --git a/src/Logger/LoggerInterface.php b/src/Logger/LoggerInterface.php new file mode 100644 index 00000000..0b0a588c --- /dev/null +++ b/src/Logger/LoggerInterface.php @@ -0,0 +1,32 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +namespace Invertus\Saferpay\Logger; + +if (!defined('_PS_VERSION_')) { + exit; +} + +interface LoggerInterface extends \Psr\Log\LoggerInterface +{ +} \ No newline at end of file From f906c955319934ef77863b0ecdfa5d760d2e1f37 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 15:53:54 +0300 Subject: [PATCH 03/40] [SV-34] added LoggerInterface into BaseServiceProvider --- src/ServiceProvider/BaseServiceProvider.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index 5b600aa3..3d830cc4 100755 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -23,6 +23,8 @@ namespace Invertus\SaferPay\ServiceProvider; +use Invertus\SaferPay\Logger\Logger; +use Invertus\Saferpay\Logger\LoggerInterface; use Invertus\SaferPay\Provider\BasicIdempotencyProvider; use Invertus\SaferPay\Provider\IdempotencyProviderInterface; use Invertus\SaferPay\Repository\OrderRepository; @@ -52,6 +54,7 @@ public function register(Container $container) $this->addService($container, IdempotencyProviderInterface::class, $container->get(BasicIdempotencyProvider::class)); $this->addService($container, OrderRepositoryInterface::class, $container->get(OrderRepository::class)); $this->addService($container, SaferPayLogRepositoryInterface::class, $container->get(SaferPayLogRepository::class)); + $this->addService($container, LoggerInterface::class, $container->get(Logger::class)); } private function addService(Container $container, $className, $service) From 437b79a7cb45f25e991453d227683f608aec1cc8 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 16:56:55 +0300 Subject: [PATCH 04/40] [SV-34] added LOGGER --- composer.json | 3 +- .../AdminSaferPayOfficialLogsController.php | 18 ++++- ...AdminSaferPayOfficialPaymentController.php | 1 + src/Context/GlobalShopContext.php | 5 +- src/Context/GlobalShopContextInterface.php | 50 ++++++++++++++ .../ObjectModelEntityManager.php | 65 +++++++++++++++++++ src/Logger/Logger.php | 7 +- src/Repository/PrestashopLoggerRepository.php | 53 +++++++++++++++ .../PrestashopLoggerRepositoryInterface.php | 24 +++++-- src/ServiceProvider/BaseServiceProvider.php | 12 ++++ 10 files changed, 222 insertions(+), 16 deletions(-) create mode 100644 src/Context/GlobalShopContextInterface.php create mode 100644 src/EntityManager/ObjectModelEntityManager.php create mode 100644 src/Repository/PrestashopLoggerRepository.php rename var/cache/index.php => src/Repository/PrestashopLoggerRepositoryInterface.php (68%) mode change 100755 => 100644 diff --git a/composer.json b/composer.json index 7f887c40..d6b9c7ca 100755 --- a/composer.json +++ b/composer.json @@ -42,7 +42,8 @@ "symfony/yaml": "^3.4", "league/container": "2.5.0", "invertus/lock": "^1.0.0", - "invertus/knapsack": "^10.0" + "invertus/knapsack": "^10.0", + "psr/log": "^1.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "*", diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 228a50ab..583c6486 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -21,10 +21,13 @@ *@license SIX Payment Services */ +use Invertus\SaferPay\Adapter\LegacyContext; use Invertus\SaferPay\Config\SaferPayConfig; +use Invertus\Saferpay\Context\GlobalShopContext; use Invertus\SaferPay\Controller\AbstractAdminSaferPayController; use Invertus\SaferPay\Enum\PermissionType; use Invertus\SaferPay\Logger\Formatter\LogFormatter; +use Invertus\Saferpay\Logger\LoggerInterface; use Invertus\SaferPay\Utility\VersionUtility; use Invertus\SaferPay\Logger\Logger; @@ -150,7 +153,16 @@ public function setMedia($isNewTheme = false) { parent::setMedia($isNewTheme); - $context = $this->module->getService(\Invertus\SaferPay\Adapter\LegacyContext::class); + /** @var LegacyContext $context */ + $context = $this->module->getService(LegacyContext::class); + + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + $logger->info('AdminSaferPayOfficialLogsController setMedia', [ + 'context' => [ + 'admin_link' => $context->getAdminLink(SaferPayOfficial::ADMIN_LOGS_CONTROLLER), + ], + ]); Media::addJsDef([ 'saferpayofficial' => [ @@ -245,8 +257,8 @@ public function displayAjaxGetLog() /** @var \Invertus\SaferPay\Repository\SaferPayLogRepository $logRepository */ $logRepository = $this->module->getService(\Invertus\SaferPay\Repository\SaferPayLogRepository::class); - /** @var \Invertus\SaferPay\Context\GlobalShopContext $shopContext */ - $globalShopContext = $this->module->getService(\Invertus\SaferPay\Context\GlobalShopContext::class); + /** @var Invertus\Saferpay\Context\GlobalShopContext $shopContext */ + $globalShopContext = $this->module->getService(GlobalShopContext::class); $logId = $tools->getValueAsInt('log_id'); diff --git a/controllers/admin/AdminSaferPayOfficialPaymentController.php b/controllers/admin/AdminSaferPayOfficialPaymentController.php index 5a85cc65..5a89702d 100755 --- a/controllers/admin/AdminSaferPayOfficialPaymentController.php +++ b/controllers/admin/AdminSaferPayOfficialPaymentController.php @@ -51,6 +51,7 @@ public function __construct() public function setMedia($isNewTheme = false) { parent::setMedia($isNewTheme); + $this->addCSS("{$this->module->getPathUri()}views/css/admin/payment_method.css"); $this->addJS("{$this->module->getPathUri()}views/js/admin/chosen_countries.js"); $this->addJS("{$this->module->getPathUri()}views/js/admin/payment_method_all.js"); diff --git a/src/Context/GlobalShopContext.php b/src/Context/GlobalShopContext.php index 8372078f..7bbb54d2 100644 --- a/src/Context/GlobalShopContext.php +++ b/src/Context/GlobalShopContext.php @@ -21,9 +21,10 @@ *@license SIX Payment Services */ -namespace Invertus\Saferpay\Context; +namespace Invertus\SaferPay\Context; use Invertus\SaferPay\Adapter\LegacyContext; +use Invertus\SaferPay\Context\GlobalShopContextInterface; if (!defined('_PS_VERSION_')) { exit; @@ -32,7 +33,7 @@ * Gets shop context data * NOTE: Done without interface because throwing error in the module */ -class GlobalShopContext +class GlobalShopContext implements GlobalShopContextInterface { private $context; diff --git a/src/Context/GlobalShopContextInterface.php b/src/Context/GlobalShopContextInterface.php new file mode 100644 index 00000000..773a8462 --- /dev/null +++ b/src/Context/GlobalShopContextInterface.php @@ -0,0 +1,50 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +namespace Invertus\SaferPay\Context; + +if (!defined('_PS_VERSION_')) { + exit; +} + +/** + * Gets shop context data + */ +interface GlobalShopContextInterface +{ + public function getShopId(); + + public function getLanguageId(); + + public function getLanguageIso(); + + public function getCurrencyIso(); + + public function getCurrency(); + + public function getShopDomain(); + + public function getShopName(); + + public function isShopSingleShopContext(); +} \ No newline at end of file diff --git a/src/EntityManager/ObjectModelEntityManager.php b/src/EntityManager/ObjectModelEntityManager.php new file mode 100644 index 00000000..8b45f16c --- /dev/null +++ b/src/EntityManager/ObjectModelEntityManager.php @@ -0,0 +1,65 @@ +unitOfWork = $unitOfWork; + } + + /** + * @param \ObjectModel $model + * @param string $unitOfWorkType + * @param string|null $specificKey + * for example external_id key to make it easier to keep + * track of which object model is related to which external_id + */ + public function persist( + \ObjectModel $model, + $unitOfWorkType, + $specificKey = null + ) { + $this->unitOfWork->setWork($model, $unitOfWorkType, $specificKey); + + return $this; + } + + /** + * @return array<\ObjectModel> + * + * @throws \PrestaShopDatabaseException + * @throws \PrestaShopException + */ + public function flush() + { + $persistenceModels = $this->unitOfWork->getWork(); + $persistedModels = []; + + foreach ($persistenceModels as $externalId => $persistenceModel) { + if ($persistenceModel['unit_of_work_type'] === ObjectModelUnitOfWork::UNIT_OF_WORK_SAVE) { + $persistenceModel['object']->save(); + } + + if ($persistenceModel['unit_of_work_type'] === ObjectModelUnitOfWork::UNIT_OF_WORK_DELETE) { + $persistenceModel['object']->delete(); + } + + if (!empty($externalId)) { + $persistedModels[$externalId] = $persistenceModel['object']; + } else { + $persistedModels[] = $persistenceModel['object']; + } + } + $this->unitOfWork->clearWork(); + + return $persistedModels; + } +} \ No newline at end of file diff --git a/src/Logger/Logger.php b/src/Logger/Logger.php index cdf60eca..60339fa6 100644 --- a/src/Logger/Logger.php +++ b/src/Logger/Logger.php @@ -28,12 +28,13 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\Saferpay\Context\GlobalShopContext; use Invertus\SaferPay\EntityManager\EntityManagerInterface; +use Invertus\SaferPay\EntityManager\ObjectModelEntityManager; use Invertus\SaferPay\EntityManager\ObjectModelUnitOfWork; use Invertus\SaferPay\Logger\Formatter\LogFormatterInterface; use Invertus\SaferPay\Provider\BasicIdempotencyProvider; -use KlarnaPayment\Module\Infrastructure\Logger\Repository\PrestashopLoggerRepositoryInterface; +use Invertus\SaferPay\Repository\PrestashopLoggerRepositoryInterface; -class Logger +class Logger implements LoggerInterface { const FILE_NAME = 'Logger'; @@ -56,7 +57,7 @@ public function __construct( GlobalShopContext $globalShopContext, Configuration $configuration, LegacyContext $context, - EntityManagerInterface $entityManager, + ObjectModelEntityManager $entityManager, BasicIdempotencyProvider $idempotencyProvider, PrestashopLoggerRepositoryInterface $prestashopLoggerRepository ) { diff --git a/src/Repository/PrestashopLoggerRepository.php b/src/Repository/PrestashopLoggerRepository.php new file mode 100644 index 00000000..30de4a91 --- /dev/null +++ b/src/Repository/PrestashopLoggerRepository.php @@ -0,0 +1,53 @@ +select('l.id_log') + ->from('log', 'l') + ->where('l.object_id = "' . pSQL($objectId) . '"') + ->orderBy('l.id_log DESC'); + + if (VersionUtility::isPsVersionGreaterOrEqualTo('1.7.8.0')) { + $query->where('l.id_shop = ' . (int) $shopId); + } + + $logId = \Db::getInstance()->getValue($query); + + return (int) $logId ?: null; + } + + public function prune($daysToKeep) + { + Collection::from( + $this->findAllInCollection() + ->sqlWhere('DATEDIFF(NOW(),date_add) >= ' . $daysToKeep) + ->where('object_type', '=', Logger::LOG_OBJECT_TYPE) + ) + ->each(function (\PrestaShopLogger $log) { + $log->delete(); + }) + ->realize(); + } +} \ No newline at end of file diff --git a/var/cache/index.php b/src/Repository/PrestashopLoggerRepositoryInterface.php old mode 100755 new mode 100644 similarity index 68% rename from var/cache/index.php rename to src/Repository/PrestashopLoggerRepositoryInterface.php index ee622726..3acfd3af --- a/var/cache/index.php +++ b/src/Repository/PrestashopLoggerRepositoryInterface.php @@ -20,12 +20,22 @@ *@copyright SIX Payment Services *@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('Cache-Control: no-store, no-cache, must-revalidate'); -header('Cache-Control: post-check=0, pre-check=0', false); -header('Pragma: no-cache'); +namespace Invertus\SaferPay\Repository; -header('Location: ../'); -exit; +if (!defined('_PS_VERSION_')) { + exit; +} + +interface PrestashopLoggerRepositoryInterface extends ReadOnlyCollectionRepositoryInterface +{ + /** + * @param string $objectId + * @param int $shopId + * + * @return int|null + */ + public function getLogIdByObjectId($objectId, $shopId); + + public function prune($daysToKeep); +} \ No newline at end of file diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index 3d830cc4..92a707d3 100755 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -23,14 +23,22 @@ namespace Invertus\SaferPay\ServiceProvider; +use Invertus\SaferPay\Context\GlobalShopContext; +use Invertus\SaferPay\EntityManager\EntityManagerInterface; +use Invertus\SaferPay\EntityManager\ObjectModelEntityManager; +use Invertus\SaferPay\Logger\Formatter\LogFormatter; +use Invertus\SaferPay\Logger\Formatter\LogFormatterInterface; use Invertus\SaferPay\Logger\Logger; use Invertus\Saferpay\Logger\LoggerInterface; use Invertus\SaferPay\Provider\BasicIdempotencyProvider; use Invertus\SaferPay\Provider\IdempotencyProviderInterface; use Invertus\SaferPay\Repository\OrderRepository; use Invertus\SaferPay\Repository\OrderRepositoryInterface; +use Invertus\SaferPay\Repository\PrestashopLoggerRepository; +use Invertus\SaferPay\Repository\PrestashopLoggerRepositoryInterface; use Invertus\SaferPay\Repository\SaferPayLogRepository; use Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface; +use Invertus\SaferPay\Context\GlobalShopContextInterface; use League\Container\Container; if (!defined('_PS_VERSION_')) { @@ -52,9 +60,13 @@ public function __construct($extendedServices) public function register(Container $container) { $this->addService($container, IdempotencyProviderInterface::class, $container->get(BasicIdempotencyProvider::class)); + $this->addService($container, LogFormatterInterface::class, $container->get(LogFormatter::class)); + $this->addService($container, GlobalShopContextInterface::class, $container->get(GlobalShopContext::class)); $this->addService($container, OrderRepositoryInterface::class, $container->get(OrderRepository::class)); $this->addService($container, SaferPayLogRepositoryInterface::class, $container->get(SaferPayLogRepository::class)); + $this->addService($container, PrestashopLoggerRepositoryInterface::class, $container->get(PrestashopLoggerRepository::class)); $this->addService($container, LoggerInterface::class, $container->get(Logger::class)); + $this->addService($container, EntityManagerInterface::class, $container->get(ObjectModelEntityManager::class)); } private function addService(Container $container, $className, $service) From 53da130252a4af8dfcec1230caa908e674e7684a Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 16:59:06 +0300 Subject: [PATCH 05/40] revert cache --- var/cache/index.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 var/cache/index.php diff --git a/var/cache/index.php b/var/cache/index.php new file mode 100644 index 00000000..9d92aad2 --- /dev/null +++ b/var/cache/index.php @@ -0,0 +1,31 @@ + + *@copyright SIX Payment Services + *@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('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../'); +exit; \ No newline at end of file From 83016ac315a4765d20c765556e99ffa6381403d1 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 17:12:48 +0300 Subject: [PATCH 06/40] [SV-34] fix composer --- composer.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index d6b9c7ca..27aa2a13 100755 --- a/composer.json +++ b/composer.json @@ -42,16 +42,14 @@ "symfony/yaml": "^3.4", "league/container": "2.5.0", "invertus/lock": "^1.0.0", - "invertus/knapsack": "^10.0", - "psr/log": "^1.1" + "invertus/knapsack": "^10.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "*", "phpunit/phpunit": "*", "behat/behat": "*", "symfony/translation": "*", - "prestashop/php-dev-tools": "^3.16", - "invertus/knapsack": "^10.0" + "prestashop/php-dev-tools": "^3.16" }, "scripts": { "test-integration": "./vendor/bin/phpunit --configuration ./tests/Integration/phpunit.xml", From cfca8e1c672bf0b422750c55e04a0ed068e666ce Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 17:15:33 +0300 Subject: [PATCH 07/40] [SV-34] REMOVED LOG --- controllers/admin/AdminSaferPayOfficialLogsController.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 583c6486..12cb70f7 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -156,14 +156,6 @@ public function setMedia($isNewTheme = false) /** @var LegacyContext $context */ $context = $this->module->getService(LegacyContext::class); - /** @var LoggerInterface $logger */ - $logger = $this->module->getService(LoggerInterface::class); - $logger->info('AdminSaferPayOfficialLogsController setMedia', [ - 'context' => [ - 'admin_link' => $context->getAdminLink(SaferPayOfficial::ADMIN_LOGS_CONTROLLER), - ], - ]); - Media::addJsDef([ 'saferpayofficial' => [ 'logsUrl' => $context->getAdminLink(SaferPayOfficial::ADMIN_LOGS_CONTROLLER), From ec5351e0358269ad41d7719305b6bb288b5f4a09 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 17:16:21 +0300 Subject: [PATCH 08/40] [SV-34] fix --- controllers/admin/AdminSaferPayOfficialLogsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 12cb70f7..06a2db04 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -249,7 +249,7 @@ public function displayAjaxGetLog() /** @var \Invertus\SaferPay\Repository\SaferPayLogRepository $logRepository */ $logRepository = $this->module->getService(\Invertus\SaferPay\Repository\SaferPayLogRepository::class); - /** @var Invertus\Saferpay\Context\GlobalShopContext $shopContext */ + /** @var Invertus\SaferPay\Context\GlobalShopContext $shopContext */ $globalShopContext = $this->module->getService(GlobalShopContext::class); $logId = $tools->getValueAsInt('log_id'); From a4cad9b2dea6f53930467aebabaacf8c2b461f9f Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 17:18:26 +0300 Subject: [PATCH 09/40] [SV-34] license --- .../ObjectModelEntityManager.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/EntityManager/ObjectModelEntityManager.php b/src/EntityManager/ObjectModelEntityManager.php index 8b45f16c..e135bbf5 100644 --- a/src/EntityManager/ObjectModelEntityManager.php +++ b/src/EntityManager/ObjectModelEntityManager.php @@ -1,4 +1,25 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services + */ namespace Invertus\SaferPay\EntityManager; From 1924110059544a9d027ea2d161484e5a921c0850 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 17:20:22 +0300 Subject: [PATCH 10/40] [SV-34] license --- src/Repository/PrestashopLoggerRepository.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Repository/PrestashopLoggerRepository.php b/src/Repository/PrestashopLoggerRepository.php index 30de4a91..44238993 100644 --- a/src/Repository/PrestashopLoggerRepository.php +++ b/src/Repository/PrestashopLoggerRepository.php @@ -1,4 +1,25 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services + */ namespace Invertus\SaferPay\Repository; From e4c9f691b173bf32be6be56679aebc36d63d03ef Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 17:52:20 +0300 Subject: [PATCH 11/40] [SV-37] added log to front controllers --- controllers/front/ajax.php | 13 +++++++++++++ controllers/front/creditCards.php | 9 +++++++++ controllers/front/creditCards16.php | 9 +++++++++ controllers/front/fail.php | 8 ++++++++ controllers/front/failIFrame.php | 8 ++++++++ controllers/front/failValidation.php | 8 ++++++++ controllers/front/hostedIframe.php | 8 ++++++++ controllers/front/iframe.php | 8 ++++++++ controllers/front/notify.php | 8 ++++++++ controllers/front/pendingNotify.php | 8 ++++++++ controllers/front/return.php | 8 ++++++++ controllers/front/success.php | 8 ++++++++ controllers/front/successHosted.php | 8 ++++++++ controllers/front/successIFrame.php | 8 ++++++++ controllers/front/validation.php | 8 ++++++++ 15 files changed, 127 insertions(+) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 34a66a14..5bf4f42e 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -25,6 +25,7 @@ use Invertus\SaferPay\Controller\Front\CheckoutController; use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; use Invertus\SaferPay\Enum\ControllerName; +use Invertus\Saferpay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; if (!defined('_PS_VERSION_')) { @@ -40,6 +41,11 @@ class SaferPayOfficialAjaxModuleFrontController extends ModuleFrontController public function postProcess() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + switch (Tools::getValue('action')) { case 'submitHostedFields': $this->submitHostedFields(); @@ -90,6 +96,8 @@ protected function processGetStatus() ] ), ])); + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } private function getFailControllerLink($cartId, $secureKey, $moduleId) @@ -162,6 +170,11 @@ private function submitHostedFields() 'url' => $this->getRedirectionToControllerUrl('fail'), ])); } + + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } /** diff --git a/controllers/front/creditCards.php b/controllers/front/creditCards.php index 3d1a5d58..2193ad71 100755 --- a/controllers/front/creditCards.php +++ b/controllers/front/creditCards.php @@ -23,6 +23,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; +use Invertus\Saferpay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; if (!defined('_PS_VERSION_')) { @@ -83,6 +84,11 @@ private function initCardList() public function postProcess() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $selectedCard = Tools::getValue('saved_card_id'); if ($selectedCard) { $cardAlias = new SaferPayCardAlias($selectedCard); @@ -92,6 +98,9 @@ public function postProcess() } $this->errors[] = $this->module->l('Failed to removed credit card', self::FILENAME); } + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + parent::postProcess(); } diff --git a/controllers/front/creditCards16.php b/controllers/front/creditCards16.php index 5463e470..cf612e3b 100755 --- a/controllers/front/creditCards16.php +++ b/controllers/front/creditCards16.php @@ -23,6 +23,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; +use Invertus\Saferpay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; if (!defined('_PS_VERSION_')) { @@ -91,6 +92,11 @@ private function initCardList() public function postProcess() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $selectedCard = Tools::getValue('saved_card_id'); if ($selectedCard) { $cardAlias = new SaferPayCardAlias($selectedCard); @@ -100,6 +106,9 @@ public function postProcess() } $this->errors[] = $this->module->l('Failed to removed credit card', self::FILENAME); } + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + parent::postProcess(); } diff --git a/controllers/front/fail.php b/controllers/front/fail.php index 19530f8b..4ab4e42d 100755 --- a/controllers/front/fail.php +++ b/controllers/front/fail.php @@ -24,6 +24,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Service\CartDuplicationService; +use Invertus\Saferpay\Logger\LoggerInterface; use PrestaShop\PrestaShop\Adapter\Order\OrderPresenter; if (!defined('_PS_VERSION_')) { @@ -93,6 +94,11 @@ public function initContent() { parent::initContent(); + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $orderLink = $this->context->link->getPageLink( 'order', true, @@ -117,5 +123,7 @@ public function initContent() false ) ); + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } } diff --git a/controllers/front/failIFrame.php b/controllers/front/failIFrame.php index c96b44a6..270ce42b 100755 --- a/controllers/front/failIFrame.php +++ b/controllers/front/failIFrame.php @@ -24,6 +24,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; +use Invertus\Saferpay\Logger\LoggerInterface; if (!defined('_PS_VERSION_')) { exit; @@ -48,6 +49,11 @@ public function initContent() { parent::initContent(); + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $orderLink = $this->context->link->getPageLink( 'order', true, @@ -64,6 +70,8 @@ public function initContent() 'redirectUrl' => $orderLink, ]); $this->setTemplate('loading_16.tpl'); + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } public function setMedia() diff --git a/controllers/front/failValidation.php b/controllers/front/failValidation.php index 90951a60..e93b063e 100755 --- a/controllers/front/failValidation.php +++ b/controllers/front/failValidation.php @@ -22,6 +22,7 @@ */ use Invertus\SaferPay\Controller\AbstractSaferPayController; +use Invertus\Saferpay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\CartDuplicationService; @@ -35,6 +36,11 @@ class SaferPayOfficialFailValidationModuleFrontController extends AbstractSaferP public function postProcess() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $cartId = Tools::getValue('cartId'); $orderId = Tools::getValue('orderId'); $secureKey = Tools::getValue('secureKey'); @@ -87,5 +93,7 @@ public function postProcess() ); Tools::redirect($failUrl); + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } } diff --git a/controllers/front/hostedIframe.php b/controllers/front/hostedIframe.php index b0330637..55e7c4c2 100755 --- a/controllers/front/hostedIframe.php +++ b/controllers/front/hostedIframe.php @@ -22,6 +22,7 @@ */ use Invertus\SaferPay\Config\SaferPayConfig; +use Invertus\Saferpay\Logger\LoggerInterface; use PrestaShop\PrestaShop\Core\Checkout\TermsAndConditions; if (!defined('_PS_VERSION_')) { @@ -34,6 +35,11 @@ class SaferPayOfficialHostedIframeModuleFrontController extends ModuleFrontContr public function initContent() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILENAME)); + parent::initContent(); $paymentMethod = Tools::getValue('saved_card_method'); @@ -63,6 +69,8 @@ public function initContent() '_16.tpl' ); } + + $logger->debug(sprintf('%s - Controller action ended', self::FILENAME)); } public function setMedia() diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php index 262d30a3..eceac845 100755 --- a/controllers/front/iframe.php +++ b/controllers/front/iframe.php @@ -26,6 +26,7 @@ use Invertus\SaferPay\Controller\Front\CheckoutController; use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; use Invertus\SaferPay\Enum\ControllerName; +use Invertus\Saferpay\Logger\LoggerInterface; if (!defined('_PS_VERSION_')) { exit; @@ -39,6 +40,11 @@ class SaferPayOfficialIFrameModuleFrontController extends AbstractSaferPayContro public function postProcess() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $cart = $this->context->cart; $redirectLink = $this->context->link->getPageLink( 'order', @@ -72,6 +78,8 @@ public function postProcess() if (!Validate::isLoadedObject($customer)) { Tools::redirect($redirectLink); } + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } public function initContent() diff --git a/controllers/front/notify.php b/controllers/front/notify.php index 0155c521..22408953 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -25,6 +25,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; +use Invertus\Saferpay\Logger\LoggerInterface; use Invertus\SaferPay\Processor\CheckoutProcessor; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\SaferPayOrderStatusService; @@ -45,6 +46,11 @@ class SaferPayOfficialNotifyModuleFrontController extends AbstractSaferPayContro */ public function postProcess() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $cartId = Tools::getValue('cartId'); $secureKey = Tools::getValue('secureKey'); $cart = new Cart($cartId); @@ -198,6 +204,8 @@ public function postProcess() die($this->module->l($e->getMessage(), self::FILENAME)); } + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + die($this->module->l('Success', self::FILENAME)); } diff --git a/controllers/front/pendingNotify.php b/controllers/front/pendingNotify.php index cf25f56d..fb8fafeb 100755 --- a/controllers/front/pendingNotify.php +++ b/controllers/front/pendingNotify.php @@ -24,6 +24,7 @@ use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\DTO\Response\AssertRefund\AssertRefundBody; +use Invertus\Saferpay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionRefundAssertion; @@ -42,6 +43,11 @@ class SaferPayOfficialPendingNotifyModuleFrontController extends AbstractSaferPa */ public function postProcess() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $cartId = Tools::getValue('cartId'); $secureKey = Tools::getValue('secureKey'); @@ -67,6 +73,8 @@ public function postProcess() } } + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + die($this->module->l('Success', self::FILENAME)); } diff --git a/controllers/front/return.php b/controllers/front/return.php index 1378ea7f..15f35e1d 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -27,6 +27,7 @@ use Invertus\SaferPay\DTO\Response\Assert\AssertBody; use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Exception\Api\SaferPayApiException; +use Invertus\Saferpay\Logger\LoggerInterface; use Invertus\SaferPay\Service\SaferPayOrderStatusService; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAssertion; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; @@ -41,6 +42,11 @@ class SaferPayOfficialReturnModuleFrontController extends AbstractSaferPayContro public function postProcess() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $cartId = (int) Tools::getValue('cartId'); $order = new Order($this->getOrderId($cartId)); @@ -62,6 +68,8 @@ public function postProcess() \PrestaShopLogger::addLog($e->getMessage()); // we only care if we have a response with pending status, else we skip further actions } + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } /** * @throws PrestaShopException diff --git a/controllers/front/success.php b/controllers/front/success.php index fc74b240..b49f199d 100755 --- a/controllers/front/success.php +++ b/controllers/front/success.php @@ -22,6 +22,7 @@ */ use Invertus\SaferPay\Controller\AbstractSaferPayController; +use Invertus\Saferpay\Logger\LoggerInterface; if (!defined('_PS_VERSION_')) { exit; @@ -33,6 +34,11 @@ class SaferPayOfficialSuccessModuleFrontController extends AbstractSaferPayContr public function postProcess() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $cartId = Tools::getValue('cartId'); $moduleId = Tools::getValue('moduleId'); $orderId = Tools::getValue('orderId'); @@ -64,5 +70,7 @@ public function postProcess() 'key' => $secureKey, ] )); + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } } diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index 63794782..0c4f9379 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -24,6 +24,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; +use Invertus\Saferpay\Logger\LoggerInterface; if (!defined('_PS_VERSION_')) { exit; @@ -46,6 +47,11 @@ public function init() public function postProcess() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $cartId = Tools::getValue('cartId'); $orderId = Tools::getValue('orderId'); $secureKey = Tools::getValue('secureKey'); @@ -87,6 +93,8 @@ public function postProcess() true ) ); + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } } diff --git a/controllers/front/successIFrame.php b/controllers/front/successIFrame.php index b7450363..7da4f542 100755 --- a/controllers/front/successIFrame.php +++ b/controllers/front/successIFrame.php @@ -24,6 +24,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; +use Invertus\Saferpay\Logger\LoggerInterface; if (!defined('_PS_VERSION_')) { exit; @@ -46,6 +47,11 @@ public function init() public function postProcess() // todo refactor this by the logic provided { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $cartId = Tools::getValue('cartId'); $orderId = Tools::getValue('orderId'); $secureKey = Tools::getValue('secureKey'); @@ -89,6 +95,8 @@ public function postProcess() // todo refactor this by the logic provided ) ); } + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } public function initContent() diff --git a/controllers/front/validation.php b/controllers/front/validation.php index de8d1cf2..8b3d76ec 100755 --- a/controllers/front/validation.php +++ b/controllers/front/validation.php @@ -24,6 +24,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; +use Invertus\Saferpay\Logger\LoggerInterface; use Invertus\SaferPay\Service\SaferPayExceptionService; use Invertus\SaferPay\Controller\Front\CheckoutController; @@ -43,6 +44,11 @@ class SaferPayOfficialValidationModuleFrontController extends AbstractSaferPayCo */ public function postProcess() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->debug(sprintf('%s - Controller called', self::FILE_NAME)); + $paymentMethod = Tools::getValue('saved_card_method'); $cart = $this->context->cart; $redirectLink = $this->context->link->getPageLink( @@ -116,5 +122,7 @@ public function postProcess() ); $this->redirectWithNotifications($redirectLink); } + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } } From 80155cddc15e18b93dea1bfe7dd044407c26299e Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 18:05:15 +0300 Subject: [PATCH 12/40] fix --- controllers/front/ajax.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 5bf4f42e..89478535 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -96,6 +96,8 @@ protected function processGetStatus() ] ), ])); + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } From 5acb6ebb0b281d8669cb526ba91e6f4e64b8ae76 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 18:29:20 +0300 Subject: [PATCH 13/40] [SV-34] added logs --- controllers/front/creditCards.php | 1 + controllers/front/notify.php | 18 ++++++------------ controllers/front/return.php | 2 +- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/controllers/front/creditCards.php b/controllers/front/creditCards.php index 2193ad71..dec92688 100755 --- a/controllers/front/creditCards.php +++ b/controllers/front/creditCards.php @@ -55,6 +55,7 @@ public function display() private function initCardList() { $customerId = $this->context->customer->id; + /** @var SaferPayCardAliasRepository $cardAliasRep */ $cardAliasRep = $this->module->getService(SaferPayCardAliasRepository::class); $savedCustomerCards = $cardAliasRep->getSavedCardsByCustomerId($customerId); diff --git a/controllers/front/notify.php b/controllers/front/notify.php index 22408953..0d0a4aa3 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -187,18 +187,12 @@ public function postProcess() die('canceled'); } - PrestaShopLogger::addLog( - sprintf( - '%s has caught an error: %s', - __CLASS__, - $e->getMessage() - ), - 1, - null, - null, - null, - true - ); + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + $logger->error(sprintf('%s - caught an error: %s', self::FILENAME, $e->getMessage()), [ + 'exception' => $e, + ]); + $this->releaseLock(); die($this->module->l($e->getMessage(), self::FILENAME)); diff --git a/controllers/front/return.php b/controllers/front/return.php index 15f35e1d..29d4165c 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -65,7 +65,7 @@ public function postProcess() $orderStatusService->setPending($order); } } catch (SaferPayApiException $e) { - \PrestaShopLogger::addLog($e->getMessage()); + $logger->debug(sprintf('%s - %s', self::FILE_NAME, $e->getMessage())); // we only care if we have a response with pending status, else we skip further actions } From 565bb98d77151b2505858430045167a20470d6e1 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 18:52:27 +0300 Subject: [PATCH 14/40] [SV-34] added more logs --- controllers/front/ajax.php | 7 +++++++ controllers/front/iframe.php | 4 ++++ controllers/front/notify.php | 8 ++++++++ controllers/front/success.php | 2 ++ controllers/front/successHosted.php | 13 +------------ controllers/front/successIFrame.php | 13 +------------ 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 89478535..78c69e35 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -166,6 +166,13 @@ private function submitHostedFields() 'url' => $redirectUrl, ])); } catch (Exception $e) { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + + $logger->error(sprintf('%s - Exception occurred', self::FILE_NAME), [ + 'message' => $e->getMessage(), + ]); + $this->ajaxDie(json_encode([ 'error' => true, 'message' => $e->getMessage(), diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php index eceac845..bde2246c 100755 --- a/controllers/front/iframe.php +++ b/controllers/front/iframe.php @@ -76,6 +76,10 @@ public function postProcess() } $customer = new Customer($cart->id_customer); if (!Validate::isLoadedObject($customer)) { + $logger->error(sprintf('%s - Customer not found', self::FILE_NAME), [ + 'customer' => $customer, + ]); + Tools::redirect($redirectLink); } diff --git a/controllers/front/notify.php b/controllers/front/notify.php index 0d0a4aa3..e84197ee 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -56,6 +56,10 @@ public function postProcess() $cart = new Cart($cartId); if (!Validate::isLoadedObject($cart)) { + $logger->error(sprintf('%s - Cart not found', self::FILE_NAME), [ + 'cart_id' => $cartId, + ]); + $this->ajaxDie(json_encode([ 'error_type' => 'unknown_error', 'error_text' => $this->module->l('An unknown error error occurred. Please contact support', self::FILENAME), @@ -63,6 +67,10 @@ public function postProcess() } if ($cart->secure_key !== $secureKey) { + $logger->error(sprintf('%s - Insecure cart', self::FILE_NAME), [ + 'cart_id' => $cartId, + ]); + die($this->module->l('Error. Insecure cart', self::FILENAME)); } diff --git a/controllers/front/success.php b/controllers/front/success.php index b49f199d..57dfc123 100755 --- a/controllers/front/success.php +++ b/controllers/front/success.php @@ -47,6 +47,8 @@ public function postProcess() $cart = new Cart($cartId); if ($cart->secure_key !== $secureKey) { + $logger->debug(sprintf('%s - Secure key does not match', self::FILE_NAME)); + $redirectLink = $this->context->link->getPageLink( 'order', true, diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index 0c4f9379..c4fe5ec2 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -67,18 +67,7 @@ public function postProcess() try { Tools::redirect($this->getOrderConfirmationLink($cartId, $moduleId, $orderId, $secureKey)); } catch (Exception $e) { - PrestaShopLogger::addLog( - sprintf( - '%s has caught an error: %s', - __CLASS__, - $e->getMessage() - ), - 1, - null, - null, - null, - true - ); + $logger->error(sprintf('%s - %s', self::FILE_NAME, $e->getMessage())); Tools::redirect( $this->context->link->getModuleLink( diff --git a/controllers/front/successIFrame.php b/controllers/front/successIFrame.php index 7da4f542..d7171a25 100755 --- a/controllers/front/successIFrame.php +++ b/controllers/front/successIFrame.php @@ -68,18 +68,7 @@ public function postProcess() // todo refactor this by the logic provided try { Tools::redirect($this->getOrderConfirmationLink($cartId, $moduleId, $orderId, $secureKey)); } catch (Exception $e) { - PrestaShopLogger::addLog( - sprintf( - '%s has caught an error: %s', - __CLASS__, - $e->getMessage() - ), - 1, - null, - null, - null, - true - ); + $logger->error(sprintf('%s - %s', self::FILE_NAME, $e->getMessage())); Tools::redirect( $this->context->link->getModuleLink( From d09becbac449eb5eb2644d631e6f9114b4b40bac Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 18:57:04 +0300 Subject: [PATCH 15/40] [SV-34] more logs --- src/Processor/CheckoutProcessor.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Processor/CheckoutProcessor.php b/src/Processor/CheckoutProcessor.php index 62405046..c3fb86be 100644 --- a/src/Processor/CheckoutProcessor.php +++ b/src/Processor/CheckoutProcessor.php @@ -35,6 +35,7 @@ use Invertus\SaferPay\Exception\Api\SaferPayApiException; use Invertus\SaferPay\Exception\CouldNotProcessCheckout; use Invertus\SaferPay\Factory\ModuleFactory; +use Invertus\Saferpay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\SaferPayInitialize; use Order; @@ -43,6 +44,8 @@ class CheckoutProcessor { + const FILE_NAME = 'CheckoutProcessor'; + /** @var \SaferPayOfficial */ private $module; @@ -71,7 +74,14 @@ public function run(CheckoutData $data) { $cart = new Cart($data->getCartId()); + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + if (!$cart) { + $logger->debug(sprintf('%s - Cart not found', self::FILE_NAME), [ + 'cartId' => $data->getCartId(), + ]); + throw CouldNotProcessCheckout::failedToFindCart($data->getCartId()); } @@ -109,6 +119,10 @@ public function run(CheckoutData $data) $data->getIsTransaction() ); } catch (\Exception $exception) { + $logger->debug(sprintf('%s - Failed to create SaferPay order', self::FILE_NAME), [ + 'cartId' => $data->getCartId(), + ]); + throw CouldNotProcessCheckout::failedToCreateSaferPayOrder($data->getCartId()); } From 63a4d57ffc6f0e4d0cc35dda7435dd1cd6737b4e Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 4 Oct 2024 08:53:44 +0300 Subject: [PATCH 16/40] [SV-34] removed comments --- .../AdminSaferPayOfficialLogsController.php | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 06a2db04..6ff4cea8 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -28,8 +28,11 @@ use Invertus\SaferPay\Enum\PermissionType; use Invertus\SaferPay\Logger\Formatter\LogFormatter; use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Repository\SaferPayLogRepository; +use Invertus\SaferPay\Utility\ExceptionUtility; use Invertus\SaferPay\Utility\VersionUtility; use Invertus\SaferPay\Logger\Logger; +use Invertus\SaferPay\Adapter\Tools; if (!defined('_PS_VERSION_')) { exit; @@ -243,19 +246,19 @@ public function displayAjaxGetLog() return; } - /** @var \Invertus\SaferPay\Adapter\Tools $tools */ - $tools = $this->module->getService(\Invertus\SaferPay\Adapter\Tools::class); + /** @var Invertus\SaferPay\Adapter\Tools $tools */ + $tools = $this->module->getService(Tools::class); - /** @var \Invertus\SaferPay\Repository\SaferPayLogRepository $logRepository */ - $logRepository = $this->module->getService(\Invertus\SaferPay\Repository\SaferPayLogRepository::class); + /** @var Invertus\SaferPay\Repository\SaferPayLogRepository $logRepository */ + $logRepository = $this->module->getService(SaferPayLogRepository::class); /** @var Invertus\SaferPay\Context\GlobalShopContext $shopContext */ $globalShopContext = $this->module->getService(GlobalShopContext::class); $logId = $tools->getValueAsInt('log_id'); -// /** @var LoggerInterface $logger */ -// $logger = $this->module->getService(LoggerInterface::class); + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); try { /** @var \SaferPayLog|null $log */ @@ -264,13 +267,13 @@ public function displayAjaxGetLog() 'id_shop' => $globalShopContext->getShopId(), ]); } catch (Exception $exception) { -// $logger->error('Failed to find log', [ -// 'context' => [ -// 'id_log' => $logId, -// 'id_shop' => $globalShopContext->getShopId(), -// ], -// 'exceptions' => ExceptionUtility::getExceptions($exception), -// ]); + $logger->error('Failed to find log', [ + 'context' => [ + 'id_log' => $logId, + 'id_shop' => $globalShopContext->getShopId(), + ], + 'exceptions' => ExceptionUtility::getExceptions($exception), + ]); $this->ajaxResponse(json_encode([ 'error' => true, @@ -279,13 +282,13 @@ public function displayAjaxGetLog() } if (!isset($log)) { -// $logger->error('No log information found.', [ -// 'context' => [ -// 'id_log' => $logId, -// 'id_shop' => $globalShopContext->getShopId(), -// ], -// 'exceptions' => [], -// ]); + $logger->error('No log information found.', [ + 'context' => [ + 'id_log' => $logId, + 'id_shop' => $globalShopContext->getShopId(), + ], + 'exceptions' => [], + ]); $this->ajaxRender(json_encode([ 'error' => true, From 66e507907af257f0c30d0a4bd32b403aa7ac2d1a Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 4 Oct 2024 08:57:53 +0300 Subject: [PATCH 17/40] [SV-34] removed long-tail --- .../admin/AdminSaferPayOfficialLogsController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 6ff4cea8..341e1911 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -246,13 +246,13 @@ public function displayAjaxGetLog() return; } - /** @var Invertus\SaferPay\Adapter\Tools $tools */ + /** @var Tools $tools */ $tools = $this->module->getService(Tools::class); - /** @var Invertus\SaferPay\Repository\SaferPayLogRepository $logRepository */ + /** @var SaferPayLogRepository $logRepository */ $logRepository = $this->module->getService(SaferPayLogRepository::class); - /** @var Invertus\SaferPay\Context\GlobalShopContext $shopContext */ + /** @var GlobalShopContext $shopContext */ $globalShopContext = $this->module->getService(GlobalShopContext::class); $logId = $tools->getValueAsInt('log_id'); @@ -323,8 +323,8 @@ public function processExport($textDelimiter = '"') /** @var Configuration $configuration */ $configuration = $this->module->getService(Configuration::class); - /** @var \Invertus\SaferPay\Adapter\LegacyContext $context */ - $context = $this->module->getService(\Invertus\SaferPay\Adapter\LegacyContext::class); + /** @var LegacyContext $context */ + $context = $this->module->getService(LegacyContext::class); $storeInfo = [ 'PrestaShop Version' => _PS_VERSION_, From fa3df9e49a6e0f97b1e7c40c54a57c71dce517bf Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 4 Oct 2024 08:59:03 +0300 Subject: [PATCH 18/40] [SV-34] typo --- controllers/admin/AdminSaferPayOfficialLogsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 341e1911..e9f7c8ed 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -27,7 +27,7 @@ use Invertus\SaferPay\Controller\AbstractAdminSaferPayController; use Invertus\SaferPay\Enum\PermissionType; use Invertus\SaferPay\Logger\Formatter\LogFormatter; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayLogRepository; use Invertus\SaferPay\Utility\ExceptionUtility; use Invertus\SaferPay\Utility\VersionUtility; From 1f0609a3507bc389e0ac6b9b970dd149dd002214 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 4 Oct 2024 08:59:26 +0300 Subject: [PATCH 19/40] [SV-34] typo --- src/Logger/LoggerInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Logger/LoggerInterface.php b/src/Logger/LoggerInterface.php index 0b0a588c..4477059d 100644 --- a/src/Logger/LoggerInterface.php +++ b/src/Logger/LoggerInterface.php @@ -21,7 +21,7 @@ *@license SIX Payment Services */ -namespace Invertus\Saferpay\Logger; +namespace Invertus\SaferPay\Logger; if (!defined('_PS_VERSION_')) { exit; From b39824ac2d808eeeeabfb0f2b47635059c0caec5 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 4 Oct 2024 09:00:25 +0300 Subject: [PATCH 20/40] [SV-34] typo --- src/Context/GlobalShopContext.php | 1 - src/Logger/Logger.php | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Context/GlobalShopContext.php b/src/Context/GlobalShopContext.php index 7bbb54d2..77c45368 100644 --- a/src/Context/GlobalShopContext.php +++ b/src/Context/GlobalShopContext.php @@ -24,7 +24,6 @@ namespace Invertus\SaferPay\Context; use Invertus\SaferPay\Adapter\LegacyContext; -use Invertus\SaferPay\Context\GlobalShopContextInterface; if (!defined('_PS_VERSION_')) { exit; diff --git a/src/Logger/Logger.php b/src/Logger/Logger.php index 60339fa6..af87ca47 100644 --- a/src/Logger/Logger.php +++ b/src/Logger/Logger.php @@ -26,8 +26,7 @@ use Invertus\SaferPay\Adapter\Configuration; use Invertus\SaferPay\Adapter\LegacyContext; use Invertus\SaferPay\Config\SaferPayConfig; -use Invertus\Saferpay\Context\GlobalShopContext; -use Invertus\SaferPay\EntityManager\EntityManagerInterface; +use Invertus\SaferPay\Context\GlobalShopContext; use Invertus\SaferPay\EntityManager\ObjectModelEntityManager; use Invertus\SaferPay\EntityManager\ObjectModelUnitOfWork; use Invertus\SaferPay\Logger\Formatter\LogFormatterInterface; From bb027a6cacc87235b543a883261b197470121d30 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 4 Oct 2024 09:02:40 +0300 Subject: [PATCH 21/40] [SV-34] CS-FIXER --- src/Context/GlobalShopContextInterface.php | 2 +- src/EntityManager/ObjectModelEntityManager.php | 2 +- src/Logger/LoggerInterface.php | 2 +- src/Repository/PrestashopLoggerRepository.php | 3 +-- src/Repository/PrestashopLoggerRepositoryInterface.php | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Context/GlobalShopContextInterface.php b/src/Context/GlobalShopContextInterface.php index 773a8462..b8f6e41a 100644 --- a/src/Context/GlobalShopContextInterface.php +++ b/src/Context/GlobalShopContextInterface.php @@ -47,4 +47,4 @@ public function getShopDomain(); public function getShopName(); public function isShopSingleShopContext(); -} \ No newline at end of file +} diff --git a/src/EntityManager/ObjectModelEntityManager.php b/src/EntityManager/ObjectModelEntityManager.php index e135bbf5..0ab073ab 100644 --- a/src/EntityManager/ObjectModelEntityManager.php +++ b/src/EntityManager/ObjectModelEntityManager.php @@ -83,4 +83,4 @@ public function flush() return $persistedModels; } -} \ No newline at end of file +} diff --git a/src/Logger/LoggerInterface.php b/src/Logger/LoggerInterface.php index 4477059d..9c3073cb 100644 --- a/src/Logger/LoggerInterface.php +++ b/src/Logger/LoggerInterface.php @@ -29,4 +29,4 @@ interface LoggerInterface extends \Psr\Log\LoggerInterface { -} \ No newline at end of file +} diff --git a/src/Repository/PrestashopLoggerRepository.php b/src/Repository/PrestashopLoggerRepository.php index 44238993..d7190a71 100644 --- a/src/Repository/PrestashopLoggerRepository.php +++ b/src/Repository/PrestashopLoggerRepository.php @@ -26,7 +26,6 @@ use Invertus\Knapsack\Collection; use Invertus\SaferPay\Logger\Logger; use Invertus\SaferPay\Utility\VersionUtility; -use Invertus\SaferPay\Repository\CollectionRepository; if (!defined('_PS_VERSION_')) { exit; @@ -71,4 +70,4 @@ public function prune($daysToKeep) }) ->realize(); } -} \ No newline at end of file +} diff --git a/src/Repository/PrestashopLoggerRepositoryInterface.php b/src/Repository/PrestashopLoggerRepositoryInterface.php index 3acfd3af..9acd2ff7 100644 --- a/src/Repository/PrestashopLoggerRepositoryInterface.php +++ b/src/Repository/PrestashopLoggerRepositoryInterface.php @@ -38,4 +38,4 @@ interface PrestashopLoggerRepositoryInterface extends ReadOnlyCollectionReposito public function getLogIdByObjectId($objectId, $shopId); public function prune($daysToKeep); -} \ No newline at end of file +} From 2fb129332e225261dc516a6365788cb8af5caea9 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 4 Oct 2024 09:07:23 +0300 Subject: [PATCH 22/40] [SV-34] typo --- src/ServiceProvider/BaseServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index 92a707d3..789a7f32 100755 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -29,7 +29,7 @@ use Invertus\SaferPay\Logger\Formatter\LogFormatter; use Invertus\SaferPay\Logger\Formatter\LogFormatterInterface; use Invertus\SaferPay\Logger\Logger; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Provider\BasicIdempotencyProvider; use Invertus\SaferPay\Provider\IdempotencyProviderInterface; use Invertus\SaferPay\Repository\OrderRepository; From 06db0954d40d677373f370a5b6196d356e7fa028 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 4 Oct 2024 09:29:06 +0300 Subject: [PATCH 23/40] [SV-37] more logs --- src/Processor/CheckoutProcessor.php | 8 +++++++- src/Service/SaferPayInitialize.php | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Processor/CheckoutProcessor.php b/src/Processor/CheckoutProcessor.php index c3fb86be..68585a83 100644 --- a/src/Processor/CheckoutProcessor.php +++ b/src/Processor/CheckoutProcessor.php @@ -119,7 +119,7 @@ public function run(CheckoutData $data) $data->getIsTransaction() ); } catch (\Exception $exception) { - $logger->debug(sprintf('%s - Failed to create SaferPay order', self::FILE_NAME), [ + $logger->error(sprintf('%s - Failed to create SaferPay order', self::FILE_NAME), [ 'cartId' => $data->getCartId(), ]); @@ -218,6 +218,12 @@ private function processAuthorizedOrder(CheckoutData $data, Cart $cart) $saferPayOrder->id_order = $order->id; $saferPayOrder->update(); } catch (\Exception $exception) { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + $logger->error(sprintf('%s - Failed to create order', self::FILE_NAME), [ + 'cartId' => $data->getCartId(), + ]); + throw CouldNotProcessCheckout::failedToCreateOrder($data->getCartId()); } } diff --git a/src/Service/SaferPayInitialize.php b/src/Service/SaferPayInitialize.php index e4822f7e..01e693ba 100755 --- a/src/Service/SaferPayInitialize.php +++ b/src/Service/SaferPayInitialize.php @@ -31,6 +31,7 @@ use Invertus\SaferPay\DTO\Request\Initialize\InitializeRequest; use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Exception\Api\SaferPayApiException; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; use Invertus\SaferPay\Factory\ModuleFactory; use Invertus\SaferPay\Service\Request\InitializeRequestObjectCreator; @@ -42,6 +43,7 @@ class SaferPayInitialize { + const FILE_NAME = 'SaferPayInitialize'; /** * @var SaferPayOfficial */ @@ -89,6 +91,12 @@ public function initialize(InitializeRequest $initializeRequest, $isBusinessLice try { $initialize = $this->initializeService->initialize($initializeRequest, $isBusinessLicence); } catch (Exception $e) { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + $logger->error(sprintf('%s - Initialize API failed', self::FILE_NAME), [ + 'exception' => json_encode($e->getMessage(), true), + ]); + throw new SaferPayApiException('Initialize API failed', SaferPayApiException::INITIALIZE); } From 180b3f566b91d32bb5021be215fb2c63304babaa Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Fri, 4 Oct 2024 10:05:42 +0300 Subject: [PATCH 24/40] [SV-37] typos --- controllers/front/ajax.php | 2 +- controllers/front/creditCards.php | 2 +- controllers/front/creditCards16.php | 2 +- controllers/front/fail.php | 2 +- controllers/front/failIFrame.php | 2 +- controllers/front/failValidation.php | 2 +- controllers/front/hostedIframe.php | 2 +- controllers/front/iframe.php | 2 +- controllers/front/notify.php | 2 +- controllers/front/pendingNotify.php | 2 +- controllers/front/return.php | 2 +- controllers/front/success.php | 2 +- controllers/front/successHosted.php | 2 +- controllers/front/successIFrame.php | 2 +- controllers/front/validation.php | 2 +- src/Api/ApiRequest.php | 37 ++++++++++++++++++++++------ src/Processor/CheckoutProcessor.php | 2 +- 17 files changed, 45 insertions(+), 24 deletions(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 78c69e35..12cccf8b 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -25,7 +25,7 @@ use Invertus\SaferPay\Controller\Front\CheckoutController; use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; use Invertus\SaferPay\Enum\ControllerName; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; if (!defined('_PS_VERSION_')) { diff --git a/controllers/front/creditCards.php b/controllers/front/creditCards.php index dec92688..30d48df8 100755 --- a/controllers/front/creditCards.php +++ b/controllers/front/creditCards.php @@ -23,7 +23,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; if (!defined('_PS_VERSION_')) { diff --git a/controllers/front/creditCards16.php b/controllers/front/creditCards16.php index cf612e3b..52aa7e61 100755 --- a/controllers/front/creditCards16.php +++ b/controllers/front/creditCards16.php @@ -23,7 +23,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; if (!defined('_PS_VERSION_')) { diff --git a/controllers/front/fail.php b/controllers/front/fail.php index 4ab4e42d..a568d9f6 100755 --- a/controllers/front/fail.php +++ b/controllers/front/fail.php @@ -24,7 +24,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Service\CartDuplicationService; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use PrestaShop\PrestaShop\Adapter\Order\OrderPresenter; if (!defined('_PS_VERSION_')) { diff --git a/controllers/front/failIFrame.php b/controllers/front/failIFrame.php index 270ce42b..d2efa968 100755 --- a/controllers/front/failIFrame.php +++ b/controllers/front/failIFrame.php @@ -24,7 +24,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; if (!defined('_PS_VERSION_')) { exit; diff --git a/controllers/front/failValidation.php b/controllers/front/failValidation.php index e93b063e..b9df2a1d 100755 --- a/controllers/front/failValidation.php +++ b/controllers/front/failValidation.php @@ -22,7 +22,7 @@ */ use Invertus\SaferPay\Controller\AbstractSaferPayController; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\CartDuplicationService; diff --git a/controllers/front/hostedIframe.php b/controllers/front/hostedIframe.php index 55e7c4c2..a6e33682 100755 --- a/controllers/front/hostedIframe.php +++ b/controllers/front/hostedIframe.php @@ -22,7 +22,7 @@ */ use Invertus\SaferPay\Config\SaferPayConfig; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use PrestaShop\PrestaShop\Core\Checkout\TermsAndConditions; if (!defined('_PS_VERSION_')) { diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php index bde2246c..64881f6f 100755 --- a/controllers/front/iframe.php +++ b/controllers/front/iframe.php @@ -26,7 +26,7 @@ use Invertus\SaferPay\Controller\Front\CheckoutController; use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; use Invertus\SaferPay\Enum\ControllerName; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; if (!defined('_PS_VERSION_')) { exit; diff --git a/controllers/front/notify.php b/controllers/front/notify.php index e84197ee..307a125e 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -25,7 +25,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Processor\CheckoutProcessor; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\SaferPayOrderStatusService; diff --git a/controllers/front/pendingNotify.php b/controllers/front/pendingNotify.php index fb8fafeb..da79c481 100755 --- a/controllers/front/pendingNotify.php +++ b/controllers/front/pendingNotify.php @@ -24,7 +24,7 @@ use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\DTO\Response\AssertRefund\AssertRefundBody; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionRefundAssertion; diff --git a/controllers/front/return.php b/controllers/front/return.php index 29d4165c..dcb97035 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -27,7 +27,7 @@ use Invertus\SaferPay\DTO\Response\Assert\AssertBody; use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Exception\Api\SaferPayApiException; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Service\SaferPayOrderStatusService; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAssertion; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; diff --git a/controllers/front/success.php b/controllers/front/success.php index 57dfc123..70723aca 100755 --- a/controllers/front/success.php +++ b/controllers/front/success.php @@ -22,7 +22,7 @@ */ use Invertus\SaferPay\Controller\AbstractSaferPayController; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; if (!defined('_PS_VERSION_')) { exit; diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index c4fe5ec2..6464a9e8 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -24,7 +24,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; if (!defined('_PS_VERSION_')) { exit; diff --git a/controllers/front/successIFrame.php b/controllers/front/successIFrame.php index d7171a25..110805f0 100755 --- a/controllers/front/successIFrame.php +++ b/controllers/front/successIFrame.php @@ -24,7 +24,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; if (!defined('_PS_VERSION_')) { exit; diff --git a/controllers/front/validation.php b/controllers/front/validation.php index 8b3d76ec..b4089d22 100755 --- a/controllers/front/validation.php +++ b/controllers/front/validation.php @@ -24,7 +24,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Core\Payment\DTO\CheckoutData; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Service\SaferPayExceptionService; use Invertus\SaferPay\Controller\Front\CheckoutController; diff --git a/src/Api/ApiRequest.php b/src/Api/ApiRequest.php index a005d7e9..0d3fbe8b 100755 --- a/src/Api/ApiRequest.php +++ b/src/Api/ApiRequest.php @@ -27,6 +27,7 @@ use Exception; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Exception\Api\SaferPayApiException; +use Invertus\SaferPay\Logger\LoggerInterface; use SaferPayLog; use Unirest\Request; use Unirest\Response; @@ -37,6 +38,15 @@ class ApiRequest { + const FILE_NAME = 'ApiRequest'; + /** @var LoggerInterface */ + private $logger; + + public function __construct(LoggerInterface $logger) + { + $this->logger = $logger; + } + /** * API Request Post Method. * @@ -59,10 +69,13 @@ public function post($url, $params = []) return json_decode($response->raw_body); } catch (Exception $exception) { - $logs = new SaferPayLog(); - $logs->message = $exception->getMessage() ?: "missing response"; - $logs->payload = json_encode($params); - $logs->add(); + $this->logger->error(sprintf('%s - POST request failed', self::FILE_NAME), [ + 'message' => $exception->getMessage(), + 'url' => $url, + 'headers' => json_encode($this->getHeaders()), + 'params' => json_encode($params), + ]); + throw $exception; } } @@ -88,10 +101,13 @@ public function get($url, $params = []) return json_decode($response->raw_body); } catch (Exception $exception) { - $logs = new SaferPayLog(); - $logs->message = $exception->getMessage() ?: "missing response"; - $logs->payload = json_encode($params); - $logs->add(); + $this->logger->error(sprintf('%s - GET request failed', self::FILE_NAME), [ + 'message' => $exception->getMessage(), + 'url' => $url, + 'headers' => json_encode($this->getHeaders()), + 'params' => json_encode($params), + ]); + throw $exception; } } @@ -119,6 +135,11 @@ private function getBaseUrl() private function isValidResponse(Response $response) { if ($response->code >= 300) { + $this->logger->error(sprintf('%s - API response failed', self::FILE_NAME), [ + 'response' => $response->raw_body, + 'code' => $response->code, + ]); + throw new SaferPayApiException(sprintf('Initialize API failed: %s', $response->raw_body), SaferPayApiException::INITIALIZE); } } diff --git a/src/Processor/CheckoutProcessor.php b/src/Processor/CheckoutProcessor.php index 68585a83..516e99ad 100644 --- a/src/Processor/CheckoutProcessor.php +++ b/src/Processor/CheckoutProcessor.php @@ -35,7 +35,7 @@ use Invertus\SaferPay\Exception\Api\SaferPayApiException; use Invertus\SaferPay\Exception\CouldNotProcessCheckout; use Invertus\SaferPay\Factory\ModuleFactory; -use Invertus\Saferpay\Logger\LoggerInterface; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\SaferPayInitialize; use Order; From 12d080b422746f8d6a1f9c0e2da602b957f3bf2f Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 7 Oct 2024 08:45:49 +0300 Subject: [PATCH 25/40] added logs --- controllers/front/pendingNotify.php | 7 ++++++ controllers/front/return.php | 4 +++- .../SaferPayTransactionAssertion.php | 23 +++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/controllers/front/pendingNotify.php b/controllers/front/pendingNotify.php index da79c481..e2d5c1e6 100755 --- a/controllers/front/pendingNotify.php +++ b/controllers/front/pendingNotify.php @@ -97,6 +97,13 @@ private function handleCapturedRefund($orderRefundId) /** @var SaferPayOrderRepository $saferPayOrderRepository */ $saferPayOrderRepository = $this->module->getService(SaferPayOrderRepository::class); + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + $logger->debug(sprintf('%s - Capture refund', self::FILE_NAME), [ + 'order_refund_id' => $orderRefundId, + 'method' => __METHOD__, + ]); + $orderRefund = new SaferPayOrderRefund($orderRefundId); $orderRefund->status = TransactionStatus::CAPTURED; $orderRefund->update(); diff --git a/controllers/front/return.php b/controllers/front/return.php index dcb97035..6faf20aa 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -65,7 +65,9 @@ public function postProcess() $orderStatusService->setPending($order); } } catch (SaferPayApiException $e) { - $logger->debug(sprintf('%s - %s', self::FILE_NAME, $e->getMessage())); + $logger->debug(sprintf('%s - safe exception %s', self::FILE_NAME, $e->getMessage()), [ + 'exception' => $e, + ]); // we only care if we have a response with pending status, else we skip further actions } diff --git a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php index 5fcc3549..26f45603 100755 --- a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php +++ b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php @@ -25,6 +25,7 @@ use Invertus\SaferPay\Api\Request\AssertService; use Invertus\SaferPay\DTO\Response\Assert\AssertBody; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\Request\AssertRequestObjectCreator; use SaferPayOrder; @@ -35,6 +36,7 @@ class SaferPayTransactionAssertion { + const FILE_NAME = 'SaferPayTransactionAssertion'; /** * @var AssertRequestObjectCreator */ @@ -49,15 +51,21 @@ class SaferPayTransactionAssertion * @var AssertService */ private $assertionService; + /** + * @var LoggerInterface + */ + private $logger; public function __construct( AssertRequestObjectCreator $assertRequestCreator, SaferPayOrderRepository $orderRepository, - AssertService $assertionService + AssertService $assertionService, + LoggerInterface $logger ) { $this->assertRequestCreator = $assertRequestCreator; $this->orderRepository = $orderRepository; $this->assertionService = $assertionService; + $this->logger = $logger; } /** @@ -69,7 +77,12 @@ public function __construct( public function assert($cartId, $update = true) { $saferPayOrder = new SaferPayOrder($this->orderRepository->getIdByCartId($cartId)); - \PrestaShopLogger::addLog('saferpayOrderId:' . $saferPayOrder->id); + + $this->logger->debug(sprintf('%s - assert service called',self::FILE_NAME), [ + 'cart_id' => $cartId, + 'saferpay_order_id' => $saferPayOrder->id, + 'method' => __METHOD__, + ]); $assertRequest = $this->assertRequestCreator->create($saferPayOrder->token); $assertResponse = $this->assertionService->assert($assertRequest, $saferPayOrder->id); @@ -90,6 +103,12 @@ public function assert($cartId, $update = true) $saferPayOrder->update(); } + $this->logger->debug(sprintf('%s - assert service ended',self::FILE_NAME), [ + 'cart_id' => $cartId, + 'saferpay_order_id' => $saferPayOrder->id, + 'method' => __METHOD__, + ]); + return $assertBody; } } From a6b656a30c32475bb6e97b7f75194162743bd83d Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 7 Oct 2024 09:04:00 +0300 Subject: [PATCH 26/40] edited log --- src/Api/ApiRequest.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Api/ApiRequest.php b/src/Api/ApiRequest.php index 0d3fbe8b..181e1a25 100755 --- a/src/Api/ApiRequest.php +++ b/src/Api/ApiRequest.php @@ -72,8 +72,9 @@ public function post($url, $params = []) $this->logger->error(sprintf('%s - POST request failed', self::FILE_NAME), [ 'message' => $exception->getMessage(), 'url' => $url, - 'headers' => json_encode($this->getHeaders()), - 'params' => json_encode($params), + 'headers' => $this->getHeaders(), + 'request' => $params, + 'response' => $response->body, ]); throw $exception; @@ -94,7 +95,7 @@ public function get($url, $params = []) $response = Request::get( $this->getBaseUrl() . $url, $this->getHeaders(), - json_encode($params) + $params ); $this->isValidResponse($response); @@ -104,8 +105,9 @@ public function get($url, $params = []) $this->logger->error(sprintf('%s - GET request failed', self::FILE_NAME), [ 'message' => $exception->getMessage(), 'url' => $url, - 'headers' => json_encode($this->getHeaders()), - 'params' => json_encode($params), + 'headers' => $this->getHeaders(), + 'request' => $params, + 'response' => $response->body, ]); throw $exception; @@ -136,7 +138,7 @@ private function isValidResponse(Response $response) { if ($response->code >= 300) { $this->logger->error(sprintf('%s - API response failed', self::FILE_NAME), [ - 'response' => $response->raw_body, + 'response' => $response->body, 'code' => $response->code, ]); From 26495f3406ab0f1f6006e5b878191709ddddd217 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 7 Oct 2024 09:06:22 +0300 Subject: [PATCH 27/40] edit log --- src/Api/ApiRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Api/ApiRequest.php b/src/Api/ApiRequest.php index 181e1a25..4769727c 100755 --- a/src/Api/ApiRequest.php +++ b/src/Api/ApiRequest.php @@ -70,7 +70,7 @@ public function post($url, $params = []) return json_decode($response->raw_body); } catch (Exception $exception) { $this->logger->error(sprintf('%s - POST request failed', self::FILE_NAME), [ - 'message' => $exception->getMessage(), + 'message' => json_decode($exception->getMessage()), 'url' => $url, 'headers' => $this->getHeaders(), 'request' => $params, @@ -103,7 +103,7 @@ public function get($url, $params = []) return json_decode($response->raw_body); } catch (Exception $exception) { $this->logger->error(sprintf('%s - GET request failed', self::FILE_NAME), [ - 'message' => $exception->getMessage(), + 'message' => json_decode($exception->getMessage()), 'url' => $url, 'headers' => $this->getHeaders(), 'request' => $params, From 176e6a61d393a257ce07178d071f5b7153433405 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 7 Oct 2024 15:50:56 +0300 Subject: [PATCH 28/40] [SV-37] added log --- src/Service/SaferPayObtainPaymentMethods.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Service/SaferPayObtainPaymentMethods.php b/src/Service/SaferPayObtainPaymentMethods.php index c0635d25..c229ffd6 100755 --- a/src/Service/SaferPayObtainPaymentMethods.php +++ b/src/Service/SaferPayObtainPaymentMethods.php @@ -26,7 +26,9 @@ use Exception; use Invertus\SaferPay\Api\Request\ObtainPaymentMethodsService; use Invertus\SaferPay\Exception\Api\SaferPayApiException; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Service\Request\ObtainPaymentMethodsObjectCreator; +use function Invertus\Knapsack\toArray; if (!defined('_PS_VERSION_')) { exit; @@ -34,18 +36,22 @@ class SaferPayObtainPaymentMethods { + const FILE_NAME = 'SaferPayObtainPaymentMethods'; private $obtainPaymentMethodsService; private $obtainPaymentMethodsObjectCreator; private $saferPayPaymentNotation; + private $logger; public function __construct( ObtainPaymentMethodsService $obtainPaymentMethodsService, ObtainPaymentMethodsObjectCreator $obtainPaymentMethodsObjectCreator, - SaferPayPaymentNotation $saferPayPaymentNotation + SaferPayPaymentNotation $saferPayPaymentNotation, + LoggerInterface $logger ) { $this->obtainPaymentMethodsService = $obtainPaymentMethodsService; $this->obtainPaymentMethodsObjectCreator = $obtainPaymentMethodsObjectCreator; $this->saferPayPaymentNotation = $saferPayPaymentNotation; + $this->logger = $logger; } public function obtainPaymentMethods() @@ -57,6 +63,10 @@ public function obtainPaymentMethods() $this->obtainPaymentMethodsObjectCreator->create() ); } catch (Exception $e) { + $this->logger->debug(sprintf('%s - failed to get payment methods list', self::FILE_NAME), [ + 'exception' => $e + ]); + throw new SaferPayApiException('Initialize API failed', SaferPayApiException::INITIALIZE); } From 34e06fd875eb077876233a766125a3da1d0b3c9e Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 7 Oct 2024 16:11:06 +0300 Subject: [PATCH 29/40] added log --- src/Service/SaferPayOrderStatusService.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Service/SaferPayOrderStatusService.php b/src/Service/SaferPayOrderStatusService.php index 711b837c..67a8ead7 100755 --- a/src/Service/SaferPayOrderStatusService.php +++ b/src/Service/SaferPayOrderStatusService.php @@ -36,6 +36,7 @@ use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Exception\Api\SaferPayApiException; use Invertus\SaferPay\Factory\ModuleFactory; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\Request\CancelRequestObjectCreator; use Invertus\SaferPay\Service\Request\CaptureRequestObjectCreator; @@ -51,6 +52,7 @@ class SaferPayOrderStatusService { + const FILE_NAME = 'SaferPayOrderStatusService'; /** * @var CaptureService */ @@ -89,6 +91,10 @@ class SaferPayOrderStatusService * @var SaferPayOfficial */ private $module; + /** + * @var LoggerInterface + */ + private $logger; public function __construct( CaptureService $captureService, @@ -99,7 +105,8 @@ public function __construct( RefundService $refundService, RefundRequestObjectCreator $refundRequestObjectCreator, LegacyContext $context, - ModuleFactory $module + ModuleFactory $module, + LoggerInterface $logger ) { $this->captureService = $captureService; $this->captureRequestObjectCreator = $captureRequestObjectCreator; @@ -110,6 +117,7 @@ public function __construct( $this->refundRequestObjectCreator = $refundRequestObjectCreator; $this->context = $context; $this->module = $module->getModule(); + $this->logger = $logger; } public function setPending(Order $order) @@ -155,6 +163,10 @@ public function capture(Order $order, $refundedAmount = 0, $isRefund = false) try { $captureResponse = $this->captureService->capture($captureRequest); } catch (Exception $e) { + $this->logger->error(sprintf('%s - Capture API failed', self::FILE_NAME), [ + 'exception' => $e, + ]); + throw new SaferPayApiException('Capture API failed', SaferPayApiException::CAPTURE); } @@ -191,6 +203,10 @@ public function cancel(Order $order) try { $this->cancelService->cancel($cancelRequest); } catch (Exception $e) { + $this->logger->error(sprintf('%s - Cancel API failed', self::FILE_NAME), [ + 'exception' => $e, + ]); + throw new SaferPayApiException('Cancel API failed', SaferPayApiException::CANCEL); } $order->setCurrentState(_SAFERPAY_PAYMENT_CANCELED_); @@ -243,6 +259,10 @@ public function refund(Order $order, $refundedAmount) try { $refundResponse = $this->refundService->refund($refundRequest); } catch (Exception $e) { + $this->logger->error(sprintf('%s - Refund API failed', self::FILE_NAME), [ + 'exception' => $e, + ]); + throw new SaferPayApiException('Refund API failed', SaferPayApiException::REFUND); } $saferPayOrder->refund_id = $refundResponse->Transaction->Id; From 417c4b3f8628b2a69db5d3184bbeebd8f8adc834 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 7 Oct 2024 21:54:42 +0300 Subject: [PATCH 30/40] fixed logs --- controllers/front/fail.php | 3 ++- controllers/front/failIFrame.php | 4 +++- controllers/front/failValidation.php | 4 ++-- controllers/front/hostedIframe.php | 3 ++- controllers/front/successHosted.php | 3 +-- src/Api/ApiRequest.php | 13 +++---------- 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/controllers/front/fail.php b/controllers/front/fail.php index a568d9f6..1c53cc63 100755 --- a/controllers/front/fail.php +++ b/controllers/front/fail.php @@ -110,6 +110,8 @@ public function initContent() $this->redirectWithNotifications($orderLink); } + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + $this->redirectWithNotifications( $this->context->link->getPageLink( 'cart', @@ -124,6 +126,5 @@ public function initContent() ) ); - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } } diff --git a/controllers/front/failIFrame.php b/controllers/front/failIFrame.php index d2efa968..6d6c85b8 100755 --- a/controllers/front/failIFrame.php +++ b/controllers/front/failIFrame.php @@ -64,6 +64,9 @@ public function initContent() $this->setTemplate(SaferPayConfig::SAFERPAY_TEMPLATE_LOCATION . '/front/loading.tpl'); return; } + + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + $this->context->smarty->assign([ 'cssUrl' => "{$this->module->getPathUri()}views/css/front/loading.css", 'jsUrl' => "{$this->module->getPathUri()}views/js/front/saferpay_iframe.js", @@ -71,7 +74,6 @@ public function initContent() ]); $this->setTemplate('loading_16.tpl'); - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } public function setMedia() diff --git a/controllers/front/failValidation.php b/controllers/front/failValidation.php index b9df2a1d..0572dc06 100755 --- a/controllers/front/failValidation.php +++ b/controllers/front/failValidation.php @@ -92,8 +92,8 @@ public function postProcess() true ); - Tools::redirect($failUrl); - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + + Tools::redirect($failUrl); } } diff --git a/controllers/front/hostedIframe.php b/controllers/front/hostedIframe.php index a6e33682..85b044f5 100755 --- a/controllers/front/hostedIframe.php +++ b/controllers/front/hostedIframe.php @@ -55,6 +55,8 @@ public function initContent() 'saferpay_selected_card' => $selectedCard, ]); + $logger->debug(sprintf('%s - Controller action ended', self::FILENAME)); + if (SaferPayConfig::isVersion17()) { $this->setTemplate( SaferPayConfig::SAFERPAY_HOSTED_TEMPLATE_LOCATION . @@ -70,7 +72,6 @@ public function initContent() ); } - $logger->debug(sprintf('%s - Controller action ended', self::FILENAME)); } public function setMedia() diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index 6464a9e8..859b9c90 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -82,9 +82,8 @@ public function postProcess() true ) ); - - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } /** diff --git a/src/Api/ApiRequest.php b/src/Api/ApiRequest.php index 4769727c..42bf0738 100755 --- a/src/Api/ApiRequest.php +++ b/src/Api/ApiRequest.php @@ -28,6 +28,7 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Exception\Api\SaferPayApiException; use Invertus\SaferPay\Logger\LoggerInterface; +use Invertus\SaferPay\Utility\ExceptionUtility; use SaferPayLog; use Unirest\Request; use Unirest\Response; @@ -70,11 +71,7 @@ public function post($url, $params = []) return json_decode($response->raw_body); } catch (Exception $exception) { $this->logger->error(sprintf('%s - POST request failed', self::FILE_NAME), [ - 'message' => json_decode($exception->getMessage()), - 'url' => $url, - 'headers' => $this->getHeaders(), - 'request' => $params, - 'response' => $response->body, + 'exceptions' => ExceptionUtility::getExceptions($exception) ]); throw $exception; @@ -103,11 +100,7 @@ public function get($url, $params = []) return json_decode($response->raw_body); } catch (Exception $exception) { $this->logger->error(sprintf('%s - GET request failed', self::FILE_NAME), [ - 'message' => json_decode($exception->getMessage()), - 'url' => $url, - 'headers' => $this->getHeaders(), - 'request' => $params, - 'response' => $response->body, + 'exceptions' => ExceptionUtility::getExceptions($exception) ]); throw $exception; From 5461ee728a24cf06ef84b804c85e42652dd98c54 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 7 Oct 2024 22:03:47 +0300 Subject: [PATCH 31/40] added logs --- controllers/front/return.php | 20 +++++++++++++++++++- controllers/front/success.php | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index 6faf20aa..645b57b6 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -31,6 +31,7 @@ use Invertus\SaferPay\Service\SaferPayOrderStatusService; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAssertion; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; +use Invertus\SaferPay\Utility\ExceptionUtility; if (!defined('_PS_VERSION_')) { exit; @@ -66,7 +67,8 @@ public function postProcess() } } catch (SaferPayApiException $e) { $logger->debug(sprintf('%s - safe exception %s', self::FILE_NAME, $e->getMessage()), [ - 'exception' => $e, + 'context' => [], + 'exceptions' => ExceptionUtility::getExceptions($e), ]); // we only care if we have a response with pending status, else we skip further actions } @@ -78,6 +80,9 @@ public function postProcess() */ public function initContent() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + $cartId = Tools::getValue('cartId'); $secureKey = Tools::getValue('secureKey'); $isBusinessLicence = (int) Tools::getValue(SaferPayConfig::IS_BUSINESS_LICENCE); @@ -87,6 +92,12 @@ public function initContent() $cart = new Cart($cartId); if (!Validate::isLoadedObject($cart)) { + $logger->error(sprintf('%s - Cart not found', self::FILE_NAME), [ + 'context' => [ + 'cartId' => $cartId, + ], + ]); + $this->ajaxDie(json_encode([ 'error_type' => 'unknown_error', 'error_text' => $this->module->l('An unknown error error occurred. Please contact support', self::FILENAME), @@ -94,6 +105,13 @@ public function initContent() } if ($cart->secure_key !== $secureKey) { + $logger->error(sprintf('%s - Secure key does not match', self::FILE_NAME), [ + 'context' => [ + 'cartId' => $cartId, + 'secureKey' => $secureKey, + ], + ]); + $this->ajaxDie(json_encode([ 'error_type' => 'unknown_error', 'error_text' => $this->module->l('An unknown error error occurred. Please contact support', self::FILENAME), diff --git a/controllers/front/success.php b/controllers/front/success.php index 70723aca..2fe9e45e 100755 --- a/controllers/front/success.php +++ b/controllers/front/success.php @@ -47,7 +47,7 @@ public function postProcess() $cart = new Cart($cartId); if ($cart->secure_key !== $secureKey) { - $logger->debug(sprintf('%s - Secure key does not match', self::FILE_NAME)); + $logger->error(sprintf('%s - Secure key does not match', self::FILE_NAME)); $redirectLink = $this->context->link->getPageLink( 'order', From aef6eac8ea39d282958a5c590a57fea2d6432d26 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 8 Oct 2024 09:29:22 +0300 Subject: [PATCH 32/40] fixed logs --- controllers/front/ajax.php | 4 ++- controllers/front/iframe.php | 5 ++- controllers/front/notify.php | 23 +++++++++++--- controllers/front/pendingNotify.php | 5 +-- controllers/front/return.php | 3 +- controllers/front/success.php | 6 +++- controllers/front/successHosted.php | 10 +++++- controllers/front/successIFrame.php | 6 +++- src/Api/ApiRequest.php | 12 +++++-- .../AbstractAdminSaferPayController.php | 31 ++++++++++--------- src/Processor/CheckoutProcessor.php | 11 +++++-- src/Service/SaferPayInitialize.php | 4 ++- src/Service/SaferPayObtainPaymentMethods.php | 1 + src/Service/SaferPayOrderStatusService.php | 11 +++++-- .../SaferPayTransactionAssertion.php | 7 +++-- 15 files changed, 101 insertions(+), 38 deletions(-) diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 12cccf8b..c14e23e2 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -27,6 +27,7 @@ use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; +use Invertus\SaferPay\Utility\ExceptionUtility; if (!defined('_PS_VERSION_')) { exit; @@ -170,7 +171,8 @@ private function submitHostedFields() $logger = $this->module->getService(LoggerInterface::class); $logger->error(sprintf('%s - Exception occurred', self::FILE_NAME), [ - 'message' => $e->getMessage(), + 'context' => [], + 'exceptions' => ExceptionUtility::getExceptions($e), ]); $this->ajaxDie(json_encode([ diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php index 64881f6f..724e89c3 100755 --- a/controllers/front/iframe.php +++ b/controllers/front/iframe.php @@ -77,7 +77,10 @@ public function postProcess() $customer = new Customer($cart->id_customer); if (!Validate::isLoadedObject($customer)) { $logger->error(sprintf('%s - Customer not found', self::FILE_NAME), [ - 'customer' => $customer, + 'context' => [ + 'customer' => $customer, + ], + 'exceptions' => [], ]); Tools::redirect($redirectLink); diff --git a/controllers/front/notify.php b/controllers/front/notify.php index 307a125e..4fc90d6e 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -30,6 +30,7 @@ use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\SaferPayOrderStatusService; use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAssertion; +use Invertus\SaferPay\Utility\ExceptionUtility; if (!defined('_PS_VERSION_')) { exit; @@ -57,7 +58,10 @@ public function postProcess() if (!Validate::isLoadedObject($cart)) { $logger->error(sprintf('%s - Cart not found', self::FILE_NAME), [ - 'cart_id' => $cartId, + 'context' => [ + 'cart_id' => $cartId, + ], + 'exceptions' => [], ]); $this->ajaxDie(json_encode([ @@ -68,7 +72,9 @@ public function postProcess() if ($cart->secure_key !== $secureKey) { $logger->error(sprintf('%s - Insecure cart', self::FILE_NAME), [ - 'cart_id' => $cartId, + 'context' => [ + 'cart_id' => $cartId, + ], ]); die($this->module->l('Error. Insecure cart', self::FILENAME)); @@ -131,6 +137,12 @@ public function postProcess() $orderStatusService = $this->module->getService(SaferPayOrderStatusService::class); $orderStatusService->cancel($order); + $logger->debug(sprintf('%s - Liability shift is false', self::FILE_NAME), [ + 'context' => [ + 'order' => $order, + ], + ]); + die($this->module->l('Liability shift is false', self::FILENAME)); } @@ -197,8 +209,11 @@ public function postProcess() /** @var LoggerInterface $logger */ $logger = $this->module->getService(LoggerInterface::class); - $logger->error(sprintf('%s - caught an error: %s', self::FILENAME, $e->getMessage()), [ - 'exception' => $e, + $logger->error(sprintf('%s - AccountToAccount order is declined', self::FILENAME), [ + 'context' => [ + 'orderId' => $orderId, + ], + 'exceptions' => ExceptionUtility::getExceptions($e), ]); $this->releaseLock(); diff --git a/controllers/front/pendingNotify.php b/controllers/front/pendingNotify.php index e2d5c1e6..cde3da70 100755 --- a/controllers/front/pendingNotify.php +++ b/controllers/front/pendingNotify.php @@ -100,8 +100,9 @@ private function handleCapturedRefund($orderRefundId) /** @var LoggerInterface $logger */ $logger = $this->module->getService(LoggerInterface::class); $logger->debug(sprintf('%s - Capture refund', self::FILE_NAME), [ - 'order_refund_id' => $orderRefundId, - 'method' => __METHOD__, + 'context' => [ + 'order_refund_id' => $orderRefundId, + ], ]); $orderRefund = new SaferPayOrderRefund($orderRefundId); diff --git a/controllers/front/return.php b/controllers/front/return.php index 645b57b6..bf326563 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -66,7 +66,7 @@ public function postProcess() $orderStatusService->setPending($order); } } catch (SaferPayApiException $e) { - $logger->debug(sprintf('%s - safe exception %s', self::FILE_NAME, $e->getMessage()), [ + $logger->debug(sprintf('%s - safe exception', self::FILE_NAME), [ 'context' => [], 'exceptions' => ExceptionUtility::getExceptions($e), ]); @@ -96,6 +96,7 @@ public function initContent() 'context' => [ 'cartId' => $cartId, ], + 'exceptions' => [], ]); $this->ajaxDie(json_encode([ diff --git a/controllers/front/success.php b/controllers/front/success.php index 2fe9e45e..ec46ff5e 100755 --- a/controllers/front/success.php +++ b/controllers/front/success.php @@ -47,7 +47,11 @@ public function postProcess() $cart = new Cart($cartId); if ($cart->secure_key !== $secureKey) { - $logger->error(sprintf('%s - Secure key does not match', self::FILE_NAME)); + $logger->error(sprintf('%s - Secure key does not match', self::FILE_NAME), [ + 'context' => [ + 'cartId' => $cartId, + ] + ]); $redirectLink = $this->context->link->getPageLink( 'order', diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index 859b9c90..0eb33a95 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -25,6 +25,7 @@ use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Logger\LoggerInterface; +use Invertus\SaferPay\Utility\ExceptionUtility; if (!defined('_PS_VERSION_')) { exit; @@ -67,7 +68,14 @@ public function postProcess() try { Tools::redirect($this->getOrderConfirmationLink($cartId, $moduleId, $orderId, $secureKey)); } catch (Exception $e) { - $logger->error(sprintf('%s - %s', self::FILE_NAME, $e->getMessage())); + $logger->error(sprintf('%s - failed to redirect customer', self::FILE_NAME), [ + 'context' => [ + 'cartId' => $cartId, + 'orderId' => $orderId, + 'secureKey' => $secureKey, + ], + 'exceptions' => ExceptionUtility::getExceptions($e), + ]); Tools::redirect( $this->context->link->getModuleLink( diff --git a/controllers/front/successIFrame.php b/controllers/front/successIFrame.php index 110805f0..9c485b0d 100755 --- a/controllers/front/successIFrame.php +++ b/controllers/front/successIFrame.php @@ -25,6 +25,7 @@ use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; use Invertus\SaferPay\Logger\LoggerInterface; +use Invertus\SaferPay\Utility\ExceptionUtility; if (!defined('_PS_VERSION_')) { exit; @@ -68,7 +69,10 @@ public function postProcess() // todo refactor this by the logic provided try { Tools::redirect($this->getOrderConfirmationLink($cartId, $moduleId, $orderId, $secureKey)); } catch (Exception $e) { - $logger->error(sprintf('%s - %s', self::FILE_NAME, $e->getMessage())); + $logger->error(sprintf('%s - Failed to validate security token', self::FILE_NAME), [ + 'context' => [], + 'exceptions' => ExceptionUtility::getExceptions($e), + ]); Tools::redirect( $this->context->link->getModuleLink( diff --git a/src/Api/ApiRequest.php b/src/Api/ApiRequest.php index 42bf0738..f189782e 100755 --- a/src/Api/ApiRequest.php +++ b/src/Api/ApiRequest.php @@ -71,6 +71,7 @@ public function post($url, $params = []) return json_decode($response->raw_body); } catch (Exception $exception) { $this->logger->error(sprintf('%s - POST request failed', self::FILE_NAME), [ + 'context' => [], 'exceptions' => ExceptionUtility::getExceptions($exception) ]); @@ -100,6 +101,11 @@ public function get($url, $params = []) return json_decode($response->raw_body); } catch (Exception $exception) { $this->logger->error(sprintf('%s - GET request failed', self::FILE_NAME), [ + 'context' => [ + 'headers' => $this->getHeaders(), + ], + 'request' => $params, + 'response' => json_decode($response->raw_body), 'exceptions' => ExceptionUtility::getExceptions($exception) ]); @@ -130,9 +136,11 @@ private function getBaseUrl() private function isValidResponse(Response $response) { if ($response->code >= 300) { - $this->logger->error(sprintf('%s - API response failed', self::FILE_NAME), [ + $this->logger->error(sprintf('%s - API thrown code: %d', self::FILE_NAME, $response->code), [ + 'context' => [ + 'code' => $response->code, + ], 'response' => $response->body, - 'code' => $response->code, ]); throw new SaferPayApiException(sprintf('Initialize API failed: %s', $response->raw_body), SaferPayApiException::INITIALIZE); diff --git a/src/Controller/AbstractAdminSaferPayController.php b/src/Controller/AbstractAdminSaferPayController.php index 3c62d4d1..ab264369 100644 --- a/src/Controller/AbstractAdminSaferPayController.php +++ b/src/Controller/AbstractAdminSaferPayController.php @@ -23,7 +23,9 @@ namespace Invertus\SaferPay\Controller; +use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Response\JsonResponse; +use Invertus\SaferPay\Utility\ExceptionUtility; class AbstractAdminSaferPayController extends \ModuleAdminController { @@ -31,17 +33,17 @@ class AbstractAdminSaferPayController extends \ModuleAdminController protected function ajaxResponse($value = null, $controller = null, $method = null) { -// /** @var LoggerInterface $logger */ -// $logger = $this->module->getService(LoggerInterface::class); + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); if ($value instanceof JsonResponse) { -// if ($value->getStatusCode() === JsonResponse::HTTP_INTERNAL_SERVER_ERROR) { -// $logger->error('Failed to return valid response', [ -// 'context' => [ -// 'response' => $value->getContent(), -// ], -// ]); -// } + if ($value->getStatusCode() === JsonResponse::HTTP_INTERNAL_SERVER_ERROR) { + $logger->error('Failed to return valid response', [ + 'context' => [ + 'response' => $value->getContent(), + ], + ]); + } http_response_code($value->getStatusCode()); @@ -57,12 +59,11 @@ protected function ajaxResponse($value = null, $controller = null, $method = nul $this->ajaxDie($value, $controller, $method); } catch (\Exception $exception) { -// $logger->error('Could not return ajax response', [ -// 'context' => [ -// 'response' => json_encode($value ?: []), -// 'exceptions' => ExceptionUtility::getExceptions($exception), -// ], -// ]); + $logger->error('Could not return ajax response', [ + 'context' => [], + 'response' => json_encode($value ?: []), + 'exceptions' => ExceptionUtility::getExceptions($exception), + ]); } exit; diff --git a/src/Processor/CheckoutProcessor.php b/src/Processor/CheckoutProcessor.php index 516e99ad..166e5008 100644 --- a/src/Processor/CheckoutProcessor.php +++ b/src/Processor/CheckoutProcessor.php @@ -38,6 +38,7 @@ use Invertus\SaferPay\Logger\LoggerInterface; use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\SaferPayInitialize; +use Invertus\SaferPay\Utility\ExceptionUtility; use Order; use PrestaShopException; use SaferPayOrder; @@ -79,7 +80,9 @@ public function run(CheckoutData $data) if (!$cart) { $logger->debug(sprintf('%s - Cart not found', self::FILE_NAME), [ - 'cartId' => $data->getCartId(), + 'context' => [ + 'cartId' => $data->getCartId(), + ], ]); throw CouldNotProcessCheckout::failedToFindCart($data->getCartId()); @@ -120,7 +123,10 @@ public function run(CheckoutData $data) ); } catch (\Exception $exception) { $logger->error(sprintf('%s - Failed to create SaferPay order', self::FILE_NAME), [ - 'cartId' => $data->getCartId(), + 'context' => [ + 'cartId' => $data->getCartId(), + ], + 'exceptions' => ExceptionUtility::getExceptions($exception) ]); throw CouldNotProcessCheckout::failedToCreateSaferPayOrder($data->getCartId()); @@ -221,6 +227,7 @@ private function processAuthorizedOrder(CheckoutData $data, Cart $cart) /** @var LoggerInterface $logger */ $logger = $this->module->getService(LoggerInterface::class); $logger->error(sprintf('%s - Failed to create order', self::FILE_NAME), [ + 'context' => [], 'cartId' => $data->getCartId(), ]); diff --git a/src/Service/SaferPayInitialize.php b/src/Service/SaferPayInitialize.php index 01e693ba..6236d582 100755 --- a/src/Service/SaferPayInitialize.php +++ b/src/Service/SaferPayInitialize.php @@ -35,6 +35,7 @@ use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; use Invertus\SaferPay\Factory\ModuleFactory; use Invertus\SaferPay\Service\Request\InitializeRequestObjectCreator; +use Invertus\SaferPay\Utility\ExceptionUtility; use SaferPayOfficial; if (!defined('_PS_VERSION_')) { @@ -94,7 +95,8 @@ public function initialize(InitializeRequest $initializeRequest, $isBusinessLice /** @var LoggerInterface $logger */ $logger = $this->module->getService(LoggerInterface::class); $logger->error(sprintf('%s - Initialize API failed', self::FILE_NAME), [ - 'exception' => json_encode($e->getMessage(), true), + 'context' => [], + 'exceptions' => ExceptionUtility::getExceptions($e), ]); throw new SaferPayApiException('Initialize API failed', SaferPayApiException::INITIALIZE); diff --git a/src/Service/SaferPayObtainPaymentMethods.php b/src/Service/SaferPayObtainPaymentMethods.php index c229ffd6..27a00dbe 100755 --- a/src/Service/SaferPayObtainPaymentMethods.php +++ b/src/Service/SaferPayObtainPaymentMethods.php @@ -64,6 +64,7 @@ public function obtainPaymentMethods() ); } catch (Exception $e) { $this->logger->debug(sprintf('%s - failed to get payment methods list', self::FILE_NAME), [ + 'context' => [], 'exception' => $e ]); diff --git a/src/Service/SaferPayOrderStatusService.php b/src/Service/SaferPayOrderStatusService.php index 67a8ead7..e30bbce8 100755 --- a/src/Service/SaferPayOrderStatusService.php +++ b/src/Service/SaferPayOrderStatusService.php @@ -41,6 +41,7 @@ use Invertus\SaferPay\Service\Request\CancelRequestObjectCreator; use Invertus\SaferPay\Service\Request\CaptureRequestObjectCreator; use Invertus\SaferPay\Service\Request\RefundRequestObjectCreator; +use Invertus\SaferPay\Utility\ExceptionUtility; use Order; use SaferPayAssert; use SaferPayOfficial; @@ -164,7 +165,8 @@ public function capture(Order $order, $refundedAmount = 0, $isRefund = false) $captureResponse = $this->captureService->capture($captureRequest); } catch (Exception $e) { $this->logger->error(sprintf('%s - Capture API failed', self::FILE_NAME), [ - 'exception' => $e, + 'context' => [], + 'exceptions' => ExceptionUtility::getExceptions($e), ]); throw new SaferPayApiException('Capture API failed', SaferPayApiException::CAPTURE); @@ -204,7 +206,10 @@ public function cancel(Order $order) $this->cancelService->cancel($cancelRequest); } catch (Exception $e) { $this->logger->error(sprintf('%s - Cancel API failed', self::FILE_NAME), [ - 'exception' => $e, + 'context' => [ + 'orderId' => $order->id, + ], + 'exceptions' => ExceptionUtility::getExceptions($e), ]); throw new SaferPayApiException('Cancel API failed', SaferPayApiException::CANCEL); @@ -260,7 +265,7 @@ public function refund(Order $order, $refundedAmount) $refundResponse = $this->refundService->refund($refundRequest); } catch (Exception $e) { $this->logger->error(sprintf('%s - Refund API failed', self::FILE_NAME), [ - 'exception' => $e, + 'exceptions' => ExceptionUtility::getExceptions($e), ]); throw new SaferPayApiException('Refund API failed', SaferPayApiException::REFUND); diff --git a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php index 26f45603..e917792e 100755 --- a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php +++ b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php @@ -79,9 +79,10 @@ public function assert($cartId, $update = true) $saferPayOrder = new SaferPayOrder($this->orderRepository->getIdByCartId($cartId)); $this->logger->debug(sprintf('%s - assert service called',self::FILE_NAME), [ - 'cart_id' => $cartId, - 'saferpay_order_id' => $saferPayOrder->id, - 'method' => __METHOD__, + 'context' => [ + 'cart_id' => $cartId, + 'saferpay_order_id' => $saferPayOrder->id, + ], ]); $assertRequest = $this->assertRequestCreator->create($saferPayOrder->token); From 700fd9d8e8a7b1c629625667c08114dfad9c3937 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 8 Oct 2024 10:07:59 +0300 Subject: [PATCH 33/40] added exception messages --- .../admin/AdminSaferPayOfficialLogsController.php | 2 +- controllers/front/ajax.php | 10 +++++----- controllers/front/fail.php | 1 - controllers/front/iframe.php | 4 +--- controllers/front/notify.php | 5 ++--- controllers/front/successHosted.php | 2 +- controllers/front/successIFrame.php | 2 +- src/Api/ApiRequest.php | 8 ++++---- src/Controller/AbstractAdminSaferPayController.php | 2 +- src/Processor/CheckoutProcessor.php | 4 ++-- src/Service/SaferPayInitialize.php | 2 +- src/Service/SaferPayOrderStatusService.php | 6 +++--- 12 files changed, 22 insertions(+), 26 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index e9f7c8ed..1f90d17b 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -267,7 +267,7 @@ public function displayAjaxGetLog() 'id_shop' => $globalShopContext->getShopId(), ]); } catch (Exception $exception) { - $logger->error('Failed to find log', [ + $logger->error($exception->getMessage(), [ 'context' => [ 'id_log' => $logId, 'id_shop' => $globalShopContext->getShopId(), diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index c14e23e2..7adcaf4a 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -82,6 +82,10 @@ protected function processGetStatus() ])); } + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + $this->ajaxDie(json_encode([ 'saferpayOrder' => json_encode($saferPayOrder), 'isFinished' => $saferPayOrder->authorized || $saferPayOrder->captured || $saferPayOrder->pending, @@ -97,10 +101,6 @@ protected function processGetStatus() ] ), ])); - /** @var LoggerInterface $logger */ - $logger = $this->module->getService(LoggerInterface::class); - - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } private function getFailControllerLink($cartId, $secureKey, $moduleId) @@ -170,7 +170,7 @@ private function submitHostedFields() /** @var LoggerInterface $logger */ $logger = $this->module->getService(LoggerInterface::class); - $logger->error(sprintf('%s - Exception occurred', self::FILE_NAME), [ + $logger->error($e->getMessage(), [ 'context' => [], 'exceptions' => ExceptionUtility::getExceptions($e), ]); diff --git a/controllers/front/fail.php b/controllers/front/fail.php index 1c53cc63..c676509b 100755 --- a/controllers/front/fail.php +++ b/controllers/front/fail.php @@ -125,6 +125,5 @@ public function initContent() false ) ); - } } diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php index 724e89c3..d48b0e87 100755 --- a/controllers/front/iframe.php +++ b/controllers/front/iframe.php @@ -77,9 +77,7 @@ public function postProcess() $customer = new Customer($cart->id_customer); if (!Validate::isLoadedObject($customer)) { $logger->error(sprintf('%s - Customer not found', self::FILE_NAME), [ - 'context' => [ - 'customer' => $customer, - ], + 'context' => [], 'exceptions' => [], ]); diff --git a/controllers/front/notify.php b/controllers/front/notify.php index 4fc90d6e..ec1280d9 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -58,9 +58,7 @@ public function postProcess() if (!Validate::isLoadedObject($cart)) { $logger->error(sprintf('%s - Cart not found', self::FILE_NAME), [ - 'context' => [ - 'cart_id' => $cartId, - ], + 'context' => [], 'exceptions' => [], ]); @@ -75,6 +73,7 @@ public function postProcess() 'context' => [ 'cart_id' => $cartId, ], + 'exceptions' => [], ]); die($this->module->l('Error. Insecure cart', self::FILENAME)); diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index 0eb33a95..c73f0e8d 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -68,7 +68,7 @@ public function postProcess() try { Tools::redirect($this->getOrderConfirmationLink($cartId, $moduleId, $orderId, $secureKey)); } catch (Exception $e) { - $logger->error(sprintf('%s - failed to redirect customer', self::FILE_NAME), [ + $logger->error($e->getMessage(), [ 'context' => [ 'cartId' => $cartId, 'orderId' => $orderId, diff --git a/controllers/front/successIFrame.php b/controllers/front/successIFrame.php index 9c485b0d..c8ee6c5d 100755 --- a/controllers/front/successIFrame.php +++ b/controllers/front/successIFrame.php @@ -69,7 +69,7 @@ public function postProcess() // todo refactor this by the logic provided try { Tools::redirect($this->getOrderConfirmationLink($cartId, $moduleId, $orderId, $secureKey)); } catch (Exception $e) { - $logger->error(sprintf('%s - Failed to validate security token', self::FILE_NAME), [ + $logger->error($e->getMessage(), [ 'context' => [], 'exceptions' => ExceptionUtility::getExceptions($e), ]); diff --git a/src/Api/ApiRequest.php b/src/Api/ApiRequest.php index f189782e..b8228d67 100755 --- a/src/Api/ApiRequest.php +++ b/src/Api/ApiRequest.php @@ -70,7 +70,7 @@ public function post($url, $params = []) return json_decode($response->raw_body); } catch (Exception $exception) { - $this->logger->error(sprintf('%s - POST request failed', self::FILE_NAME), [ + $this->logger->error($exception->getMessage(), [ 'context' => [], 'exceptions' => ExceptionUtility::getExceptions($exception) ]); @@ -100,12 +100,12 @@ public function get($url, $params = []) return json_decode($response->raw_body); } catch (Exception $exception) { - $this->logger->error(sprintf('%s - GET request failed', self::FILE_NAME), [ + $this->logger->error($exception->getMessage(), [ 'context' => [ 'headers' => $this->getHeaders(), + 'request' => $params, + 'response' => json_decode($response->raw_body), ], - 'request' => $params, - 'response' => json_decode($response->raw_body), 'exceptions' => ExceptionUtility::getExceptions($exception) ]); diff --git a/src/Controller/AbstractAdminSaferPayController.php b/src/Controller/AbstractAdminSaferPayController.php index ab264369..9cc6521f 100644 --- a/src/Controller/AbstractAdminSaferPayController.php +++ b/src/Controller/AbstractAdminSaferPayController.php @@ -59,7 +59,7 @@ protected function ajaxResponse($value = null, $controller = null, $method = nul $this->ajaxDie($value, $controller, $method); } catch (\Exception $exception) { - $logger->error('Could not return ajax response', [ + $logger->error($exception->getMessage(), [ 'context' => [], 'response' => json_encode($value ?: []), 'exceptions' => ExceptionUtility::getExceptions($exception), diff --git a/src/Processor/CheckoutProcessor.php b/src/Processor/CheckoutProcessor.php index 166e5008..0d0e7c2b 100644 --- a/src/Processor/CheckoutProcessor.php +++ b/src/Processor/CheckoutProcessor.php @@ -122,7 +122,7 @@ public function run(CheckoutData $data) $data->getIsTransaction() ); } catch (\Exception $exception) { - $logger->error(sprintf('%s - Failed to create SaferPay order', self::FILE_NAME), [ + $logger->error($exception->getMessage(), [ 'context' => [ 'cartId' => $data->getCartId(), ], @@ -226,7 +226,7 @@ private function processAuthorizedOrder(CheckoutData $data, Cart $cart) } catch (\Exception $exception) { /** @var LoggerInterface $logger */ $logger = $this->module->getService(LoggerInterface::class); - $logger->error(sprintf('%s - Failed to create order', self::FILE_NAME), [ + $logger->error($exception->getMessage(), [ 'context' => [], 'cartId' => $data->getCartId(), ]); diff --git a/src/Service/SaferPayInitialize.php b/src/Service/SaferPayInitialize.php index 6236d582..d44e8225 100755 --- a/src/Service/SaferPayInitialize.php +++ b/src/Service/SaferPayInitialize.php @@ -94,7 +94,7 @@ public function initialize(InitializeRequest $initializeRequest, $isBusinessLice } catch (Exception $e) { /** @var LoggerInterface $logger */ $logger = $this->module->getService(LoggerInterface::class); - $logger->error(sprintf('%s - Initialize API failed', self::FILE_NAME), [ + $logger->error($e->getMessage(), [ 'context' => [], 'exceptions' => ExceptionUtility::getExceptions($e), ]); diff --git a/src/Service/SaferPayOrderStatusService.php b/src/Service/SaferPayOrderStatusService.php index e30bbce8..0c5bab20 100755 --- a/src/Service/SaferPayOrderStatusService.php +++ b/src/Service/SaferPayOrderStatusService.php @@ -164,7 +164,7 @@ public function capture(Order $order, $refundedAmount = 0, $isRefund = false) try { $captureResponse = $this->captureService->capture($captureRequest); } catch (Exception $e) { - $this->logger->error(sprintf('%s - Capture API failed', self::FILE_NAME), [ + $this->logger->error($e->getMessage(), [ 'context' => [], 'exceptions' => ExceptionUtility::getExceptions($e), ]); @@ -205,7 +205,7 @@ public function cancel(Order $order) try { $this->cancelService->cancel($cancelRequest); } catch (Exception $e) { - $this->logger->error(sprintf('%s - Cancel API failed', self::FILE_NAME), [ + $this->logger->error($e->getMessage(), [ 'context' => [ 'orderId' => $order->id, ], @@ -264,7 +264,7 @@ public function refund(Order $order, $refundedAmount) try { $refundResponse = $this->refundService->refund($refundRequest); } catch (Exception $e) { - $this->logger->error(sprintf('%s - Refund API failed', self::FILE_NAME), [ + $this->logger->error($e->getMessage(), [ 'exceptions' => ExceptionUtility::getExceptions($e), ]); From 2bd20469be82b9af7a7922735704705c65066608 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 8 Oct 2024 10:14:49 +0300 Subject: [PATCH 34/40] fixed logs --- controllers/front/failIFrame.php | 4 ++-- controllers/front/notify.php | 2 +- controllers/front/return.php | 1 - controllers/front/successHosted.php | 4 ++-- .../TransactionFlow/SaferPayTransactionAssertion.php | 7 ++++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/controllers/front/failIFrame.php b/controllers/front/failIFrame.php index 6d6c85b8..44b71025 100755 --- a/controllers/front/failIFrame.php +++ b/controllers/front/failIFrame.php @@ -60,13 +60,13 @@ public function initContent() null ); + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + if (SaferPayConfig::isVersion17()) { $this->setTemplate(SaferPayConfig::SAFERPAY_TEMPLATE_LOCATION . '/front/loading.tpl'); return; } - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); - $this->context->smarty->assign([ 'cssUrl' => "{$this->module->getPathUri()}views/css/front/loading.css", 'jsUrl' => "{$this->module->getPathUri()}views/js/front/saferpay_iframe.js", diff --git a/controllers/front/notify.php b/controllers/front/notify.php index ec1280d9..38c7c001 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -138,7 +138,7 @@ public function postProcess() $logger->debug(sprintf('%s - Liability shift is false', self::FILE_NAME), [ 'context' => [ - 'order' => $order, + 'id_order' => $order->id, ], ]); diff --git a/controllers/front/return.php b/controllers/front/return.php index bf326563..b704965a 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -109,7 +109,6 @@ public function initContent() $logger->error(sprintf('%s - Secure key does not match', self::FILE_NAME), [ 'context' => [ 'cartId' => $cartId, - 'secureKey' => $secureKey, ], ]); diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index c73f0e8d..91c482ac 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -72,11 +72,12 @@ public function postProcess() 'context' => [ 'cartId' => $cartId, 'orderId' => $orderId, - 'secureKey' => $secureKey, ], 'exceptions' => ExceptionUtility::getExceptions($e), ]); + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + Tools::redirect( $this->context->link->getModuleLink( $this->module->name, @@ -91,7 +92,6 @@ public function postProcess() ) ); } - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } /** diff --git a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php index e917792e..bbe2cfe7 100755 --- a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php +++ b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php @@ -105,9 +105,10 @@ public function assert($cartId, $update = true) } $this->logger->debug(sprintf('%s - assert service ended',self::FILE_NAME), [ - 'cart_id' => $cartId, - 'saferpay_order_id' => $saferPayOrder->id, - 'method' => __METHOD__, + 'context' => [ + 'cart_id' => $cartId, + 'saferpay_order_id' => $saferPayOrder->id, + ], ]); return $assertBody; From bb37f94890d4379b8a37c06470fc013294acdbf2 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 8 Oct 2024 10:18:45 +0300 Subject: [PATCH 35/40] fix logs --- controllers/front/return.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index b704965a..b0883e19 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -93,9 +93,7 @@ public function initContent() if (!Validate::isLoadedObject($cart)) { $logger->error(sprintf('%s - Cart not found', self::FILE_NAME), [ - 'context' => [ - 'cartId' => $cartId, - ], + 'context' => [], 'exceptions' => [], ]); From f1af89341f287eaa5db5c97bc0d2d8dfc505fce2 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 8 Oct 2024 11:05:37 +0300 Subject: [PATCH 36/40] fixes --- .../admin/AdminSaferPayOfficialLogsController.php | 6 +++--- controllers/front/ajax.php | 13 +++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 1f90d17b..290cdf58 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -246,13 +246,13 @@ public function displayAjaxGetLog() return; } - /** @var Tools $tools */ + /** @var Invertus\SaferPay\Adapter\Tools $tools */ $tools = $this->module->getService(Tools::class); - /** @var SaferPayLogRepository $logRepository */ + /** @var Invertus\SaferPay\Repository\SaferPayLogRepository $logRepository */ $logRepository = $this->module->getService(SaferPayLogRepository::class); - /** @var GlobalShopContext $shopContext */ + /** @var Invertus\SaferPay\Context\GlobalShopContext $shopContext */ $globalShopContext = $this->module->getService(GlobalShopContext::class); $logId = $tools->getValueAsInt('log_id'); diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index 7adcaf4a..5b6528db 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -134,6 +134,9 @@ private function getSuccessControllerName($isBusinessLicence, $fieldToken) private function submitHostedFields() { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + try { if (Order::getOrderByCartId($this->context->cart->id)) { $this->ajaxDie(json_encode([ @@ -162,14 +165,13 @@ private function submitHostedFields() $redirectUrl = $this->getRedirectionToControllerUrl('successHosted'); } + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + $this->ajaxDie(json_encode([ 'error' => false, 'url' => $redirectUrl, ])); } catch (Exception $e) { - /** @var LoggerInterface $logger */ - $logger = $this->module->getService(LoggerInterface::class); - $logger->error($e->getMessage(), [ 'context' => [], 'exceptions' => ExceptionUtility::getExceptions($e), @@ -181,11 +183,6 @@ private function submitHostedFields() 'url' => $this->getRedirectionToControllerUrl('fail'), ])); } - - /** @var LoggerInterface $logger */ - $logger = $this->module->getService(LoggerInterface::class); - - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } /** From 24ed687b6304d572032cf52a560d4786c138357c Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 8 Oct 2024 11:13:22 +0300 Subject: [PATCH 37/40] fix --- controllers/front/fail.php | 4 ++-- controllers/front/return.php | 2 +- controllers/front/success.php | 4 ++-- controllers/front/successIFrame.php | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/controllers/front/fail.php b/controllers/front/fail.php index c676509b..24bce504 100755 --- a/controllers/front/fail.php +++ b/controllers/front/fail.php @@ -106,12 +106,12 @@ public function initContent() ); $this->warning[] = $this->module->l('We couldn\'t authorize your payment. Please try again.', self::FILENAME); + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + if (!SaferPayConfig::isVersion17()) { $this->redirectWithNotifications($orderLink); } - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); - $this->redirectWithNotifications( $this->context->link->getPageLink( 'cart', diff --git a/controllers/front/return.php b/controllers/front/return.php index b0883e19..92cf3634 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -66,7 +66,7 @@ public function postProcess() $orderStatusService->setPending($order); } } catch (SaferPayApiException $e) { - $logger->debug(sprintf('%s - safe exception', self::FILE_NAME), [ + $logger->debug(sprintf('%s - Safe exception', self::FILE_NAME), [ 'context' => [], 'exceptions' => ExceptionUtility::getExceptions($e), ]); diff --git a/controllers/front/success.php b/controllers/front/success.php index ec46ff5e..80c41c09 100755 --- a/controllers/front/success.php +++ b/controllers/front/success.php @@ -65,6 +65,8 @@ public function postProcess() Tools::redirect($redirectLink); } + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + Tools::redirect($this->context->link->getPageLink( 'order-confirmation', true, @@ -76,7 +78,5 @@ public function postProcess() 'key' => $secureKey, ] )); - - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } } diff --git a/controllers/front/successIFrame.php b/controllers/front/successIFrame.php index c8ee6c5d..c783340d 100755 --- a/controllers/front/successIFrame.php +++ b/controllers/front/successIFrame.php @@ -67,6 +67,8 @@ public function postProcess() // todo refactor this by the logic provided } try { + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + Tools::redirect($this->getOrderConfirmationLink($cartId, $moduleId, $orderId, $secureKey)); } catch (Exception $e) { $logger->error($e->getMessage(), [ @@ -88,8 +90,6 @@ public function postProcess() // todo refactor this by the logic provided ) ); } - - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } public function initContent() From f0951a8b64d97d6acbc19e3a870d896a450c81f1 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 8 Oct 2024 11:14:01 +0300 Subject: [PATCH 38/40] fix --- controllers/front/validation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/front/validation.php b/controllers/front/validation.php index b4089d22..1a59393a 100755 --- a/controllers/front/validation.php +++ b/controllers/front/validation.php @@ -96,6 +96,8 @@ public function postProcess() $redirectLink = $checkoutController->execute($checkoutData); + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + Tools::redirect($redirectLink); } catch (\Exception $exception) { /** @var SaferPayExceptionService $exceptionService */ @@ -122,7 +124,5 @@ public function postProcess() ); $this->redirectWithNotifications($redirectLink); } - - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); } } From fe4137ccebe6eb64e65c209efb784962490978b5 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 8 Oct 2024 11:18:33 +0300 Subject: [PATCH 39/40] removed status code --- src/Api/ApiRequest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Api/ApiRequest.php b/src/Api/ApiRequest.php index b8228d67..6844f030 100755 --- a/src/Api/ApiRequest.php +++ b/src/Api/ApiRequest.php @@ -137,9 +137,7 @@ private function isValidResponse(Response $response) { if ($response->code >= 300) { $this->logger->error(sprintf('%s - API thrown code: %d', self::FILE_NAME, $response->code), [ - 'context' => [ - 'code' => $response->code, - ], + 'context' => [], 'response' => $response->body, ]); From f15c4fa0c90465a570bd5a44e36d37c250b08e70 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 8 Oct 2024 11:22:33 +0300 Subject: [PATCH 40/40] safe exception message from exception --- controllers/front/return.php | 2 +- controllers/front/successHosted.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/front/return.php b/controllers/front/return.php index 92cf3634..0d5fc2d6 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -66,7 +66,7 @@ public function postProcess() $orderStatusService->setPending($order); } } catch (SaferPayApiException $e) { - $logger->debug(sprintf('%s - Safe exception', self::FILE_NAME), [ + $logger->debug($e->getMessage(), [ 'context' => [], 'exceptions' => ExceptionUtility::getExceptions($e), ]); diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index 91c482ac..fb26d493 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -66,6 +66,8 @@ public function postProcess() } try { + $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); + Tools::redirect($this->getOrderConfirmationLink($cartId, $moduleId, $orderId, $secureKey)); } catch (Exception $e) { $logger->error($e->getMessage(), [ @@ -76,8 +78,6 @@ public function postProcess() 'exceptions' => ExceptionUtility::getExceptions($e), ]); - $logger->debug(sprintf('%s - Controller action ended', self::FILE_NAME)); - Tools::redirect( $this->context->link->getModuleLink( $this->module->name,