From a650fb2b86f26daf72f6a2dd69db8d6cde68a7fe Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 11:34:11 +0300 Subject: [PATCH 01/90] [SV-35] init --- .../admin/AdminSaferPayOfficialSettingsController.php | 7 +++++++ src/Config/SaferPayConfig.php | 1 + 2 files changed, 8 insertions(+) diff --git a/controllers/admin/AdminSaferPayOfficialSettingsController.php b/controllers/admin/AdminSaferPayOfficialSettingsController.php index fdd33062..3b25d8e8 100755 --- a/controllers/admin/AdminSaferPayOfficialSettingsController.php +++ b/controllers/admin/AdminSaferPayOfficialSettingsController.php @@ -402,6 +402,13 @@ private function displayConfigurationSettings() 'desc' => 'This description is visible in payment page also in payment confirmation email', 'class' => 'fixed-width-xxl' ], + SaferPayConfig::SAFERPAY_DEBUG_MODE => [ + 'title' => $this->module->l('Debug mode', self::FILE_NAME), + 'validation' => 'isBool', + 'cast' => 'intval', + 'type' => 'bool', + 'desc' => 'Enable debug mode to see more information in logs', + ], ], 'buttons' => [ 'save_and_connect' => [ diff --git a/src/Config/SaferPayConfig.php b/src/Config/SaferPayConfig.php index c2c31af4..e56fc101 100755 --- a/src/Config/SaferPayConfig.php +++ b/src/Config/SaferPayConfig.php @@ -264,6 +264,7 @@ class SaferPayConfig const PAYMENT_BEHAVIOR_WITHOUT_3D_AUTHORIZE = 1; const SAFERPAY_CARDFORM_HOLDERNAME_REQUIRENCE = 'MANDATORY'; + const SAFERPAY_DEBUG_MODE = 'SAFERPAY_DEBUG_MODE'; public static function supportsOrderCapture(string $paymentMethod) { From a640c52b784d0f3dcf49a636a5ae9af69be5be15 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 13:05:22 +0300 Subject: [PATCH 02/90] [SV-35] fix --- controllers/admin/AdminSaferPayOfficialSettingsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/admin/AdminSaferPayOfficialSettingsController.php b/controllers/admin/AdminSaferPayOfficialSettingsController.php index 3b25d8e8..c8734fa7 100755 --- a/controllers/admin/AdminSaferPayOfficialSettingsController.php +++ b/controllers/admin/AdminSaferPayOfficialSettingsController.php @@ -407,7 +407,7 @@ private function displayConfigurationSettings() 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', - 'desc' => 'Enable debug mode to see more information in logs', + 'desc' => $this->module->l('Enable debug mode to see more information in logs', self::FILE_NAME), ], ], 'buttons' => [ From c41483393fe583760ac6271167c3e076be184cd7 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 13:22:19 +0300 Subject: [PATCH 03/90] [SV-33] init --- src/Entity/SaferPayLog.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Entity/SaferPayLog.php b/src/Entity/SaferPayLog.php index c5842965..2ee828a6 100755 --- a/src/Entity/SaferPayLog.php +++ b/src/Entity/SaferPayLog.php @@ -27,18 +27,32 @@ class SaferPayLog extends ObjectModel { - public $message; + public $id_saferpay_log; - public $date_add; + public $id_log; + + public $id_shop; + + public $correlation_id; + + public $message; public $payload; + public $context; + + public $date_add; + public static $definition = [ 'table' => 'saferpay_log', 'primary' => 'id_saferpay_log', 'fields' => [ + 'id_log' => ['type' => self::TYPE_INT, 'validate' => 'isInt'], + 'id_shop' => ['type' => self::TYPE_INT, 'validate' => 'isInt'], + 'correlation_id' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'message' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'payload' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], + 'context' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'], ], ]; From df3e22a9b5fd89dc2377fc3ad0b88b9d2764f618 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 13:25:22 +0300 Subject: [PATCH 04/90] [SV-33] fix --- src/Entity/SaferPayLog.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Entity/SaferPayLog.php b/src/Entity/SaferPayLog.php index 2ee828a6..f9774c27 100755 --- a/src/Entity/SaferPayLog.php +++ b/src/Entity/SaferPayLog.php @@ -33,8 +33,6 @@ class SaferPayLog extends ObjectModel public $id_shop; - public $correlation_id; - public $message; public $payload; @@ -49,7 +47,6 @@ class SaferPayLog extends ObjectModel 'fields' => [ 'id_log' => ['type' => self::TYPE_INT, 'validate' => 'isInt'], 'id_shop' => ['type' => self::TYPE_INT, 'validate' => 'isInt'], - 'correlation_id' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'message' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'payload' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'context' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], From 80ba7403806554848f612670b41b8847dbe10500 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 13:33:16 +0300 Subject: [PATCH 05/90] [SV-33] edit sql --- src/Entity/SaferPayLog.php | 3 ++- src/Install/Installer.php | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Entity/SaferPayLog.php b/src/Entity/SaferPayLog.php index f9774c27..10069edd 100755 --- a/src/Entity/SaferPayLog.php +++ b/src/Entity/SaferPayLog.php @@ -48,7 +48,8 @@ class SaferPayLog extends ObjectModel 'id_log' => ['type' => self::TYPE_INT, 'validate' => 'isInt'], 'id_shop' => ['type' => self::TYPE_INT, 'validate' => 'isInt'], 'message' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], - 'payload' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], + 'request' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], + 'response' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'context' => ['type' => self::TYPE_STRING, 'validate' => 'isString'], 'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'], ], diff --git a/src/Install/Installer.php b/src/Install/Installer.php index d005c53b..2c1b1382 100755 --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -299,10 +299,14 @@ private function installSaferPayCardAlias() private function installSaferPayLog() { return Db::getInstance()->execute( - 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'saferpay_log' . '( + 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . pSQL(\SaferPayLog::$definition['table']) . '( `id_saferpay_log` INTEGER(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, + `id_log` INTEGER(10) DEFAULT 0, + `id_shop` INTEGER(10) DEFAULT 0, `message` TEXT NOT NULL, - `payload` TEXT NOT NULL, + `request` TEXT NOT NULL, + `response` TEXT NOT NULL, + `context` TEXT NOT NULL, `date_add` datetime NOT NULL ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' ); From 8d802e97ce611d38348ccc3dce09b7142968d534 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 13:37:27 +0300 Subject: [PATCH 06/90] [SV-33] add upgrade file --- upgrade/install-1.2.4.php | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 upgrade/install-1.2.4.php diff --git a/upgrade/install-1.2.4.php b/upgrade/install-1.2.4.php new file mode 100644 index 00000000..07ac45fe --- /dev/null +++ b/upgrade/install-1.2.4.php @@ -0,0 +1,42 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +use Invertus\SaferPay\Config\SaferPayConfig; +use Invertus\SaferPay\DTO\Request\RequestHeader; + +if (!defined('_PS_VERSION_')) { + exit; +} + +function upgrade_module_1_2_3(SaferPayOfficial $module) +{ + $installer = new \Invertus\SaferPay\Install\Installer($module); + + return + $installer->createPendingOrderStatus() && + Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'saferpay_order ADD COLUMN `pending` TINYINT(1) DEFAULT 0') && + $module->registerHook('displayOrderConfirmation') && + $module->unregisterHook('actionOrderHistoryAddAfter') && + Configuration::updateValue(RequestHeader::SPEC_VERSION, SaferPayConfig::API_VERSION) && + Configuration::updateValue(RequestHeader::SPEC_REFUND_VERSION, SaferPayConfig::API_VERSION); +} From 366b99c637aa8332ee5ff338cd27889eb1d785cf Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 13:41:12 +0300 Subject: [PATCH 07/90] [SV-33] on upgrade update sql --- upgrade/install-1.2.4.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/upgrade/install-1.2.4.php b/upgrade/install-1.2.4.php index 07ac45fe..aaa03aa6 100644 --- a/upgrade/install-1.2.4.php +++ b/upgrade/install-1.2.4.php @@ -32,11 +32,12 @@ function upgrade_module_1_2_3(SaferPayOfficial $module) { $installer = new \Invertus\SaferPay\Install\Installer($module); - return - $installer->createPendingOrderStatus() && - Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'saferpay_order ADD COLUMN `pending` TINYINT(1) DEFAULT 0') && - $module->registerHook('displayOrderConfirmation') && - $module->unregisterHook('actionOrderHistoryAddAfter') && - Configuration::updateValue(RequestHeader::SPEC_VERSION, SaferPayConfig::API_VERSION) && - Configuration::updateValue(RequestHeader::SPEC_REFUND_VERSION, SaferPayConfig::API_VERSION); + return Db::getInstance()->execute( + 'ALTER TABLE ' . _DB_PREFIX_ . SaferPayLog::$definition['table'] . ' + ADD COLUMN `id_log` INTEGER(10) DEFAULT 0, + ADD COLUMN `id_shop` INTEGER(10) DEFAULT 0, + CHANGE `payload` `request` TEXT, + ADD COLUMN `response` TEXT, + ADD COLUMN `context` TEXT;' + ); } From ea35f11d16064d939ff30d8161b790a43218deae Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 13:43:48 +0300 Subject: [PATCH 08/90] [SV-33] add --- upgrade/install-1.2.4.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/upgrade/install-1.2.4.php b/upgrade/install-1.2.4.php index aaa03aa6..997f11bf 100644 --- a/upgrade/install-1.2.4.php +++ b/upgrade/install-1.2.4.php @@ -28,10 +28,8 @@ exit; } -function upgrade_module_1_2_3(SaferPayOfficial $module) +function upgrade_module_1_2_4(SaferPayOfficial $module) { - $installer = new \Invertus\SaferPay\Install\Installer($module); - return Db::getInstance()->execute( 'ALTER TABLE ' . _DB_PREFIX_ . SaferPayLog::$definition['table'] . ' ADD COLUMN `id_log` INTEGER(10) DEFAULT 0, From 79bb14b773056095369908c0e69928e11ff6a32f Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 13:47:29 +0300 Subject: [PATCH 09/90] [SV-33] added repo to composer --- composer.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index cd10dd9a..fc0e2d57 100755 --- a/composer.json +++ b/composer.json @@ -21,13 +21,17 @@ "php": "5.6" } }, - "repositories": [ - { + "repositories": { + "knapsack": { + "type": "vcs", + "url": "https://github.com/Invertus/Knapsack.git" + }, + "0": { "type": "vcs", "url": "https://github.com/Invertus/lock.git", "no-api": true } - ], + }, "require": { "vlucas/phpdotenv": "^3.6", "symfony/expression-language": "^3.4", From 2cc8983d4195b5145901998e25217459dd6efce3 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 13:53:18 +0300 Subject: [PATCH 10/90] [SV-33] add --- composer.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index fc0e2d57..8f43ad93 100755 --- a/composer.json +++ b/composer.json @@ -41,14 +41,16 @@ "apimatic/unirest-php": "^2.3", "symfony/yaml": "^3.4", "league/container": "2.5.0", - "invertus/lock": "^1.0.0" + "invertus/lock": "^1.0.0", + "invertus/knapsack": "^10.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "*", "phpunit/phpunit": "*", "behat/behat": "*", "symfony/translation": "*", - "prestashop/php-dev-tools": "^3.16" + "prestashop/php-dev-tools": "^3.16", + "invertus/knapsack": "^10.0" }, "scripts": { "test-integration": "./vendor/bin/phpunit --configuration ./tests/Integration/phpunit.xml", From be9cc6b5317318a7b5cd3a2b4bc62d2bbee90bad Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 15:35:51 +0300 Subject: [PATCH 11/90] [SV-33] increase version --- saferpayofficial.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saferpayofficial.php b/saferpayofficial.php index a4a4e230..4437fc62 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -40,7 +40,7 @@ public function __construct($name = null) { $this->name = 'saferpayofficial'; $this->author = 'Invertus'; - $this->version = '1.2.3'; + $this->version = '1.2.4'; $this->module_key = '3d3506c3e184a1fe63b936b82bda1bdf'; $this->displayName = 'SaferpayOfficial'; $this->description = 'Saferpay Payment module'; From 52406cdc803b73c49658496adee8ece6dd8f986b Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 16:50:20 +0300 Subject: [PATCH 12/90] [SV-34] updated Logger page --- .../AdminSaferPayOfficialLogsController.php | 36 ++++++++++++++++--- .../templates/admin/logs/severity_levels.tpl | 34 ++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 views/templates/admin/logs/severity_levels.tpl diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index e20dcbb8..a30e5896 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -27,6 +27,8 @@ class AdminSaferPayOfficialLogsController extends ModuleAdminController { + const FILE_NAME = 'AdminSaferPayOfficialLogsController'; + public function __construct() { parent::__construct(); @@ -34,6 +36,9 @@ public function __construct() $this->table = SaferPayLog::$definition['table']; $this->bootstrap = true; $this->list_no_link = true; + $this->lang = false; + $this->noLink = true; + $this->allow_export = true; $this->initList(); } @@ -42,6 +47,9 @@ public function initContent() if ($this->module instanceof SaferPayOfficial) { $this->content .= $this->module->displayNavigationTop(); } + + $this->content .= $this->displaySeverityInformation(); + parent::initContent(); } @@ -49,21 +57,32 @@ public function initList() { $this->fields_list = [ 'id_saferpay_log' => [ - 'title' => $this->l('ID'), + 'title' => $this->module->l('ID', self::FILE_NAME), 'align' => 'center', ], - 'payload' => [ - 'title' => $this->l('Payload'), + 'severity' => [ + 'title' => $this->module->l('Severity (1-4)', self::FILE_NAME), + 'align' => 'text-center', + 'class' => 'fixed-width-xs', + 'callback' => 'printSeverityLevel', + ], + 'request' => [ + 'title' => $this->module->l('Payload', self::FILE_NAME), + 'align' => 'center', + 'class' => 'saferpay-text-break', + ], + 'response' => [ + 'title' => $this->module->l('Response', self::FILE_NAME), 'align' => 'center', 'class' => 'saferpay-text-break', ], 'message' => [ 'align' => 'center', - 'title' => $this->l('Message'), + 'title' => $this->module->l('Message', self::FILE_NAME), 'class' => 'saferpay-text-break', ], 'date_add' => [ - 'title' => $this->l('Date'), + 'title' => $this->module->l('Date', self::FILE_NAME), 'type' => 'datetime', ], ]; @@ -85,4 +104,11 @@ public function setMedia($isNewTheme = false) $this->addCSS("{$this->module->getPathUri()}views/css/admin/logs_tab.css"); parent::setMedia($isNewTheme); } + + public function displaySeverityInformation() + { + return $this->context->smarty->fetch( + "{$this->module->getLocalPath()}views/templates/admin/logs/severity_levels.tpl" + ); + } } diff --git a/views/templates/admin/logs/severity_levels.tpl b/views/templates/admin/logs/severity_levels.tpl new file mode 100644 index 00000000..13eb624a --- /dev/null +++ b/views/templates/admin/logs/severity_levels.tpl @@ -0,0 +1,34 @@ +{** + *NOTICE OF LICENSE + * + *This source file is subject to the Open Software License (OSL 3.0) + *that is bundled with this package in the file LICENSE.txt. + *It is also available through the world-wide-web at this URL: + *http://opensource.org/licenses/osl-3.0.php + *If you did not receive a copy of the license and are unable to + *obtain it through the world-wide-web, please send an email + *to license@prestashop.com so we can send you a copy immediately. + * + *DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer + *versions in the future. If you wish to customize PrestaShop for your + *needs please refer to http://www.prestashop.com for more information. + * + *@author INVERTUS UAB www.invertus.eu + *@copyright SIX Payment Services + *@license SIX Payment Services + *} +
+

+ + {l s='Severity levels:' mod='klarnapayment'} +

+

{l s='Meaning of severity levels:' mod='klarnapayment'}

+
    +
  1. {l s='Info' mod='klarnapayment'}
  2. +
  3. {l s='Warning' mod='klarnapayment'}
  4. +
  5. {l s='Error' mod='klarnapayment'}
  6. +
  7. {l s='Fatal' mod='klarnapayment'}
  8. +
+
\ No newline at end of file From e77a116aff8f03cd19466668433c0b7346cc8bb8 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 17:22:17 +0300 Subject: [PATCH 13/90] [SV-33] update schema --- src/Install/Installer.php | 18 +++++++++--------- upgrade/install-1.2.4.php | 7 ++++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Install/Installer.php b/src/Install/Installer.php index 2c1b1382..a35017d5 100755 --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -300,15 +300,15 @@ private function installSaferPayLog() { return Db::getInstance()->execute( 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . pSQL(\SaferPayLog::$definition['table']) . '( - `id_saferpay_log` INTEGER(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, - `id_log` INTEGER(10) DEFAULT 0, - `id_shop` INTEGER(10) DEFAULT 0, - `message` TEXT NOT NULL, - `request` TEXT NOT NULL, - `response` TEXT NOT NULL, - `context` TEXT NOT NULL, - `date_add` datetime NOT NULL - ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' + `id_saferpay_log` INTEGER(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, + `id_log` INTEGER(10) DEFAULT 0, + `id_shop` INTEGER(10) DEFAULT 1, + `message` TEXT NOT NULL DEFAULT "", + `request` TEXT NOT NULL DEFAULT "", + `response` TEXT NOT NULL DEFAULT "", + `context` TEXT NOT NULL DEFAULT "", + `date_add` datetime NOT NULL DEFAULT NOW() + ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' ); } diff --git a/upgrade/install-1.2.4.php b/upgrade/install-1.2.4.php index 997f11bf..ac08bd24 100644 --- a/upgrade/install-1.2.4.php +++ b/upgrade/install-1.2.4.php @@ -33,9 +33,10 @@ function upgrade_module_1_2_4(SaferPayOfficial $module) return Db::getInstance()->execute( 'ALTER TABLE ' . _DB_PREFIX_ . SaferPayLog::$definition['table'] . ' ADD COLUMN `id_log` INTEGER(10) DEFAULT 0, - ADD COLUMN `id_shop` INTEGER(10) DEFAULT 0, + ADD COLUMN `id_shop` INTEGER(10) DEFAULT 1, CHANGE `payload` `request` TEXT, - ADD COLUMN `response` TEXT, - ADD COLUMN `context` TEXT;' + ADD COLUMN `response` TEXT DEFAULT "", + ADD COLUMN `context` TEXT DEFAULT "", + ADD PRIMARY KEY (`id_log`, `id_shop`);' ); } From 9dd4370e52a4d903af36d8fc4e4671c6373e53a5 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Mon, 30 Sep 2024 17:30:22 +0300 Subject: [PATCH 14/90] [SV-34] update name --- 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 a30e5896..076ede2a 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -67,7 +67,7 @@ public function initList() 'callback' => 'printSeverityLevel', ], 'request' => [ - 'title' => $this->module->l('Payload', self::FILE_NAME), + 'title' => $this->module->l('Request', self::FILE_NAME), 'align' => 'center', 'class' => 'saferpay-text-break', ], From f87c447f0996be024dbedcb52ee4990609b42c54 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 07:41:08 +0300 Subject: [PATCH 15/90] [SV-34] added VersionUtility --- .../AdminSaferPayOfficialLogsController.php | 17 +++++- src/Utility/VersionUtility.php | 61 +++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 src/Utility/VersionUtility.php diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 076ede2a..9eac95ba 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -31,15 +31,26 @@ class AdminSaferPayOfficialLogsController extends ModuleAdminController public function __construct() { - parent::__construct(); - $this->className = SaferPayLog::class; - $this->table = SaferPayLog::$definition['table']; + $this->table = 'log'; + $this->className = 'PrestaShopLogger'; $this->bootstrap = true; $this->list_no_link = true; $this->lang = false; $this->noLink = true; $this->allow_export = true; + $this->toolbar_btn = []; + parent::__construct(); $this->initList(); + + $shopIdCheck = ''; + + if (VersionUtility::isPsVersionGreaterOrEqualTo('1.7.8.0')) { + $shopIdCheck = ' AND kpl.id_shop = a.id_shop'; + } + + $this->_join .= ' JOIN ' . _DB_PREFIX_ . 'saferpay_log kpl ON (kpl.id_log = a.id_log' . $shopIdCheck . ' AND a.object_type = "' . pSQL(Logger::LOG_OBJECT_TYPE) . '")'; + $this->_use_found_rows = false; + $this->list_no_link = true; } public function initContent() diff --git a/src/Utility/VersionUtility.php b/src/Utility/VersionUtility.php new file mode 100644 index 00000000..8f076e6a --- /dev/null +++ b/src/Utility/VersionUtility.php @@ -0,0 +1,61 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +namespace Invertus\SaferPay\Utility; + +if (!defined('_PS_VERSION_')) { + exit; +} + +class VersionUtility +{ + public static function isPsVersionLessThan($version): ?int + { + return version_compare(_PS_VERSION_, $version, '<'); + } + + public static function isPsVersionGreaterThan($version): ?int + { + return version_compare(_PS_VERSION_, $version, '>'); + } + + public static function isPsVersionGreaterOrEqualTo($version): ?int + { + return version_compare(_PS_VERSION_, $version, '>='); + } + + public static function isPsVersionLessThanOrEqualTo($version): ?int + { + return version_compare(_PS_VERSION_, $version, '<='); + } + + public static function isPsVersionEqualTo($version): ?int + { + return version_compare(_PS_VERSION_, $version, '='); + } + + public static function current(): string + { + return _PS_VERSION_; + } +} From 86ac36aeef4d816973532212d2c7e2f93b2818f3 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 07:44:32 +0300 Subject: [PATCH 16/90] [SV-34] added Logger class --- controllers/admin/AdminSaferPayOfficialLogsController.php | 3 +++ src/Logger/Logger.php | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 src/Logger/Logger.php diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 9eac95ba..78deaec5 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -21,6 +21,9 @@ *@license SIX Payment Services */ +use Invertus\SaferPay\Utility\VersionUtility; +use Invertus\SaferPay\Logger\Logger; + if (!defined('_PS_VERSION_')) { exit; } diff --git a/src/Logger/Logger.php b/src/Logger/Logger.php new file mode 100644 index 00000000..cf8e9e41 --- /dev/null +++ b/src/Logger/Logger.php @@ -0,0 +1,8 @@ + Date: Tue, 1 Oct 2024 08:38:25 +0300 Subject: [PATCH 17/90] [SV-34] added LogFormatter and sql query for parsing logs --- .../AdminSaferPayOfficialLogsController.php | 10 ++++- src/Logger/Formatter/LogFormatter.php | 17 +++++++++ .../Formatter/LogFormatterInterface.php | 38 +++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/Logger/Formatter/LogFormatter.php create mode 100644 src/Logger/Formatter/LogFormatterInterface.php diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 78deaec5..c3d7501d 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -21,6 +21,7 @@ *@license SIX Payment Services */ +use Invertus\SaferPay\Logger\Formatter\LogFormatter; use Invertus\SaferPay\Utility\VersionUtility; use Invertus\SaferPay\Logger\Logger; @@ -45,13 +46,18 @@ public function __construct() parent::__construct(); $this->initList(); + $this->_select .= ' + REPLACE(a.`message`, "' . LogFormatter::SAFERPAY_LOG_PREFIX . '", "") as message, + spl.request, spl.response, spl.context + '; + $shopIdCheck = ''; if (VersionUtility::isPsVersionGreaterOrEqualTo('1.7.8.0')) { - $shopIdCheck = ' AND kpl.id_shop = a.id_shop'; + $shopIdCheck = ' AND spl.id_shop = a.id_shop'; } - $this->_join .= ' JOIN ' . _DB_PREFIX_ . 'saferpay_log kpl ON (kpl.id_log = a.id_log' . $shopIdCheck . ' AND a.object_type = "' . pSQL(Logger::LOG_OBJECT_TYPE) . '")'; + $this->_join .= ' JOIN ' . _DB_PREFIX_ . SaferPayLog::$definition['table'] . ' spl ON (spl.id_log = a.id_log' . $shopIdCheck . ' AND a.object_type = "' . pSQL(Logger::LOG_OBJECT_TYPE) . '")'; $this->_use_found_rows = false; $this->list_no_link = true; } diff --git a/src/Logger/Formatter/LogFormatter.php b/src/Logger/Formatter/LogFormatter.php new file mode 100644 index 00000000..d2d099ca --- /dev/null +++ b/src/Logger/Formatter/LogFormatter.php @@ -0,0 +1,17 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +namespace Invertus\SaferPay\Logger\Formatter; + +if (!defined('_PS_VERSION_')) { + exit; +} + +interface LogFormatterInterface +{ + /** + * @param string $message - an actual error message + * + * @return string + */ + public function getMessage(string $message): string; +} \ No newline at end of file From f92b38eeb9fc5ddc2bd432c821985508c30f2418 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 08:53:45 +0300 Subject: [PATCH 18/90] [SV-34] added severity show --- .../AdminSaferPayOfficialLogsController.php | 23 +++++++++++++ .../admin/logs/severity_level_column.tpl | 32 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 views/templates/admin/logs/severity_level_column.tpl diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index c3d7501d..d10bdf1e 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -131,4 +131,27 @@ public function displaySeverityInformation() "{$this->module->getLocalPath()}views/templates/admin/logs/severity_levels.tpl" ); } + + public function printSeverityLevel(int $level) + { + $this->context->smarty->assign([ + 'log_severity_level' => $level, + 'log_severity_level_informative' => defined('\PrestaShopLogger::LOG_SEVERITY_LEVEL_INFORMATIVE') ? + PrestaShopLogger::LOG_SEVERITY_LEVEL_INFORMATIVE : + Config::LOG_SEVERITY_LEVEL_INFORMATIVE, + 'log_severity_level_warning' => defined('\PrestaShopLogger::LOG_SEVERITY_LEVEL_WARNING') ? + PrestaShopLogger::LOG_SEVERITY_LEVEL_WARNING : + Config::LOG_SEVERITY_LEVEL_WARNING, + 'log_severity_level_error' => defined('\PrestaShopLogger::LOG_SEVERITY_LEVEL_ERROR') ? + PrestaShopLogger::LOG_SEVERITY_LEVEL_ERROR : + Config::LOG_SEVERITY_LEVEL_ERROR, + 'log_severity_level_major' => defined('\PrestaShopLogger::LOG_SEVERITY_LEVEL_MAJOR') ? + PrestaShopLogger::LOG_SEVERITY_LEVEL_MAJOR : + Config::LOG_SEVERITY_LEVEL_MAJOR, + ]); + + return $this->context->smarty->fetch( + "{$this->module->getLocalPath()}views/templates/admin/logs/severity_level_column.tpl" + ); + } } diff --git a/views/templates/admin/logs/severity_level_column.tpl b/views/templates/admin/logs/severity_level_column.tpl new file mode 100644 index 00000000..10f94f44 --- /dev/null +++ b/views/templates/admin/logs/severity_level_column.tpl @@ -0,0 +1,32 @@ +{** + *NOTICE OF LICENSE + * + *This source file is subject to the Open Software License (OSL 3.0) + *that is bundled with this package in the file LICENSE.txt. + *It is also available through the world-wide-web at this URL: + *http://opensource.org/licenses/osl-3.0.php + *If you did not receive a copy of the license and are unable to + *obtain it through the world-wide-web, please send an email + *to license@prestashop.com so we can send you a copy immediately. + * + *DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer + *versions in the future. If you wish to customize PrestaShop for your + *needs please refer to http://www.prestashop.com for more information. + * + *@author INVERTUS UAB www.invertus.eu + *@copyright SIX Payment Services + *@license SIX Payment Services + *} +{if $log_severity_level == $log_severity_level_informative} + {l s='Informative only' mod='klarnapayment'} ({$log_severity_level|intval}) +{elseif $log_severity_level == $log_severity_level_warning} + {l s='Warning' mod='klarnapayment'} ({$log_severity_level|intval}) +{elseif $log_severity_level == $log_severity_level_error} + {l s='Error' mod='klarnapayment'} ({$log_severity_level|intval}) +{elseif $log_severity_level == $log_severity_level_major} + {l s='Major issue (crash)!' mod='klarnapayment'} ({$log_severity_level|intval}) +{else} + {$log_severity_level|escape:'htmlall':'UTF-8'} +{/if} \ No newline at end of file From 726345a978b13c01ca4670575d6a856f458ff80b Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 09:40:55 +0300 Subject: [PATCH 19/90] [SV-34] fixed logs controller --- .../AdminSaferPayOfficialLogsController.php | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index d10bdf1e..145b1561 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -38,12 +38,13 @@ public function __construct() $this->table = 'log'; $this->className = 'PrestaShopLogger'; $this->bootstrap = true; - $this->list_no_link = true; $this->lang = false; $this->noLink = true; $this->allow_export = true; - $this->toolbar_btn = []; + parent::__construct(); + + $this->toolbar_btn = []; $this->initList(); $this->_select .= ' @@ -76,9 +77,10 @@ public function initContent() public function initList() { $this->fields_list = [ - 'id_saferpay_log' => [ + 'id_log' => [ 'title' => $this->module->l('ID', self::FILE_NAME), - 'align' => 'center', + 'align' => 'text-center', + 'class' => 'fixed-width-xs', ], 'severity' => [ 'title' => $this->module->l('Severity (1-4)', self::FILE_NAME), @@ -88,22 +90,36 @@ public function initList() ], 'request' => [ 'title' => $this->module->l('Request', self::FILE_NAME), - 'align' => 'center', - 'class' => 'saferpay-text-break', + 'align' => 'text-center', + 'callback' => 'printRequestButton', + 'orderby' => false, + 'search' => false, + 'remove_onclick' => true, ], 'response' => [ 'title' => $this->module->l('Response', self::FILE_NAME), - 'align' => 'center', - 'class' => 'saferpay-text-break', + 'align' => 'text-center', + 'callback' => 'printResponseButton', + 'orderby' => false, + 'search' => false, + 'remove_onclick' => true, ], 'message' => [ - 'align' => 'center', 'title' => $this->module->l('Message', self::FILE_NAME), - 'class' => 'saferpay-text-break', + ], + 'context' => [ + 'title' => $this->module->l('Context', self::FILE_NAME), + 'align' => 'text-center', + 'callback' => 'printContextButton', + 'orderby' => false, + 'search' => false, + 'remove_onclick' => true, ], 'date_add' => [ 'title' => $this->module->l('Date', self::FILE_NAME), + 'align' => 'right', 'type' => 'datetime', + 'filter_key' => 'a!date_add', ], ]; From 478b63ff6e70562762f18496c90b6447a1130c8c Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 10:07:25 +0300 Subject: [PATCH 20/90] [SV-34] added function to context adapter --- .../AdminSaferPayOfficialLogsController.php | 49 ++++++++++++++++- src/Adapter/LegacyContext.php | 6 +++ views/js/admin/log.js | 53 +++++++++++++++++++ views/templates/admin/logs/log_modal.tpl | 32 +++++++++++ 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 views/js/admin/log.js create mode 100644 views/templates/admin/logs/log_modal.tpl diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 145b1561..704f3122 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -32,6 +32,9 @@ class AdminSaferPayOfficialLogsController extends ModuleAdminController { const FILE_NAME = 'AdminSaferPayOfficialLogsController'; + const LOG_INFORMATION_TYPE_REQUEST = 'request'; + const LOG_INFORMATION_TYPE_RESPONSE = 'response'; + const LOG_INFORMATION_TYPE_CONTEXT = 'context'; public function __construct() { @@ -137,8 +140,16 @@ public function renderList() public function setMedia($isNewTheme = false) { - $this->addCSS("{$this->module->getPathUri()}views/css/admin/logs_tab.css"); parent::setMedia($isNewTheme); + + Media::addJsDef([ + 'klarnapayment' => [ + 'logsUrl' => $context->getAdminLink(ModuleTabs::LOGS_MODULE_TAB_CONTROLLER_NAME), + ], + ]); + + $this->addCSS("{$this->module->getPathUri()}views/css/admin/logs_tab.css"); + $this->addJS($this->module->getPathUri() . 'views/js/admin/log.js', false); } public function displaySeverityInformation() @@ -170,4 +181,40 @@ public function printSeverityLevel(int $level) "{$this->module->getLocalPath()}views/templates/admin/logs/severity_level_column.tpl" ); } + + public function getDisplayButton(int $logId, string $data, string $logInformationType) + { + $unserializedData = json_decode($data); + + if (empty($unserializedData)) { + return '--'; + } + + $this->context->smarty->assign([ + 'log_id' => $logId, + 'log_information_type' => $logInformationType, + ]); + + return $this->context->smarty->fetch( + "{$this->module->getLocalPath()}views/templates/admin/logs/log_modal.tpl" + ); + } + + /** + * @param string $request + * @param array $data + * + * @return false|string + * + * @throws SmartyException + */ + public function printRequestButton(string $request, array $data) + { + return $this->getDisplayButton($data['id_log'], $request, self::LOG_INFORMATION_TYPE_REQUEST); + } + + public function printResponseButton(string $response, array $data) + { + return $this->getDisplayButton($data['id_log'], $response, self::LOG_INFORMATION_TYPE_RESPONSE); + } } diff --git a/src/Adapter/LegacyContext.php b/src/Adapter/LegacyContext.php index 618d21cf..500e9f59 100755 --- a/src/Adapter/LegacyContext.php +++ b/src/Adapter/LegacyContext.php @@ -78,4 +78,10 @@ public function getDeviceDetect() { return (int) $this->getContext()->getDevice(); } + + public function getAdminLink($controllerName, array $params = []): string + { + /* @noinspection PhpMethodParametersCountMismatchInspection - its valid for PS1.7 */ + return (string) Context::getContext()->link->getAdminLink($controllerName, true, [], $params); + } } diff --git a/views/js/admin/log.js b/views/js/admin/log.js new file mode 100644 index 00000000..9a7f31cb --- /dev/null +++ b/views/js/admin/log.js @@ -0,0 +1,53 @@ +/** + * NOTICE OF LICENSE + * + * @author Klarna Bank AB www.klarna.com + * @copyright Copyright (c) permanent, Klarna Bank AB + * @license ISC + * @see /LICENSE + * + * International Registered Trademark & Property of Klarna Bank AB + */ +$(document).ready(function () { + $('.log-modal-overlay').on('click', function (event) { + $('.modal.open').removeClass('open'); + event.preventDefault(); + }); + + $('.js-log-button').on('click', function (event) { + var logId = $(this).data('log-id'); + var informationType = $(this).data('information-type'); + + // NOTE: opening modal + $('#' + $(this).data('target')).addClass('open'); + + // NOTE: if information has been set already we don't need to call ajax again. + if (!$('#log-modal-' + logId + '-' + informationType + ' .log-modal-content-data').hasClass('hidden')) { + return; + } + + $('.log-modal-content-spinner').removeClass('hidden'); + + $.ajax({ + type: 'POST', + url: klarnapayment.logsUrl, + data: { + ajax: true, + action: 'getLog', + log_id: logId + } + }) + .then(response => jQuery.parseJSON(response)) + .then(data => { + $('.log-modal-content-spinner').addClass('hidden') + + $('#log-modal-' + logId + '-request .log-modal-content-data').removeClass('hidden').html(prettyJson(data.log.request)); + $('#log-modal-' + logId + '-response .log-modal-content-data').removeClass('hidden').html(prettyJson(data.log.response)); + $('#log-modal-' + logId + '-context .log-modal-content-data').removeClass('hidden').html(prettyJson(data.log.context)); + }) + }); +}); + +function prettyJson(json) { + return JSON.stringify(jQuery.parseJSON(json), null, 2) +} diff --git a/views/templates/admin/logs/log_modal.tpl b/views/templates/admin/logs/log_modal.tpl new file mode 100644 index 00000000..f5533368 --- /dev/null +++ b/views/templates/admin/logs/log_modal.tpl @@ -0,0 +1,32 @@ +
+ {l s='View' mod='saferpayofficial'} +
+ + \ No newline at end of file From 3304b4a7c5c476d1e61f89c90a5530da01d3e350 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 10:17:57 +0300 Subject: [PATCH 21/90] [SV-34] fix --- .../AdminSaferPayOfficialLogsController.php | 6 ++-- views/js/admin/log.js | 29 ++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 704f3122..00d40aac 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -142,9 +142,11 @@ public function setMedia($isNewTheme = false) { parent::setMedia($isNewTheme); + $context = $this->module->getService(\Invertus\SaferPay\Adapter\LegacyContext::class); + Media::addJsDef([ - 'klarnapayment' => [ - 'logsUrl' => $context->getAdminLink(ModuleTabs::LOGS_MODULE_TAB_CONTROLLER_NAME), + 'saferpayofficial' => [ + 'logsUrl' => $context->getAdminLink(SaferPayOfficial::ADMIN_LOGS_CONTROLLER), ], ]); diff --git a/views/js/admin/log.js b/views/js/admin/log.js index 9a7f31cb..9c7ba8ac 100644 --- a/views/js/admin/log.js +++ b/views/js/admin/log.js @@ -1,13 +1,25 @@ /** - * NOTICE OF LICENSE + *NOTICE OF LICENSE * - * @author Klarna Bank AB www.klarna.com - * @copyright Copyright (c) permanent, Klarna Bank AB - * @license ISC - * @see /LICENSE + *This source file is subject to the Open Software License (OSL 3.0) + *that is bundled with this package in the file LICENSE.txt. + *It is also available through the world-wide-web at this URL: + *http://opensource.org/licenses/osl-3.0.php + *If you did not receive a copy of the license and are unable to + *obtain it through the world-wide-web, please send an email + *to license@prestashop.com so we can send you a copy immediately. * - * International Registered Trademark & Property of Klarna Bank AB + *DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer + *versions in the future. If you wish to customize PrestaShop for your + *needs please refer to http://www.prestashop.com for more information. + * + *@author INVERTUS UAB www.invertus.eu + *@copyright SIX Payment Services + *@license SIX Payment Services */ + $(document).ready(function () { $('.log-modal-overlay').on('click', function (event) { $('.modal.open').removeClass('open'); @@ -30,7 +42,7 @@ $(document).ready(function () { $.ajax({ type: 'POST', - url: klarnapayment.logsUrl, + url: saferpayofficial.logsUrl, data: { ajax: true, action: 'getLog', @@ -49,5 +61,6 @@ $(document).ready(function () { }); function prettyJson(json) { - return JSON.stringify(jQuery.parseJSON(json), null, 2) + var parsed = jQuery.parseJSON(json); // Using older jQuery to parse JSON + return JSON.stringify(parsed, null, 2); } From d45adb604bbda7987666b1d7b25018693793c488 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 11:27:35 +0300 Subject: [PATCH 22/90] [SV-34] added dependencies --- .../AdminSaferPayOfficialLogsController.php | 72 ++++++++- src/Adapter/LegacyContext.php | 79 ++++++++- src/Adapter/Tools.php | 150 ++++++++++++++++++ src/Context/GlobalShopContext.php | 59 +++++++ src/Context/GlobalShopContextInterface.php | 50 ++++++ .../AbstractAdminSaferPayController.php | 72 +++++++++ src/Enum/PermissionType.php | 13 ++ src/Repository/CollectionRepository.php | 46 ++++++ .../ReadOnlyCollectionRepositoryInterface.php | 29 ++++ src/Repository/SaferPayLogRepository.php | 29 ++++ .../SaferPayLogRepositoryInterface.php | 12 ++ src/Response/JsonResponse.php | 76 +++++++++ src/Utility/ExceptionUtility.php | 57 +++++++ views/js/admin/log.js | 13 +- 14 files changed, 747 insertions(+), 10 deletions(-) create mode 100644 src/Adapter/Tools.php create mode 100644 src/Context/GlobalShopContext.php create mode 100644 src/Context/GlobalShopContextInterface.php create mode 100644 src/Controller/AbstractAdminSaferPayController.php create mode 100644 src/Enum/PermissionType.php create mode 100644 src/Repository/CollectionRepository.php create mode 100644 src/Repository/ReadOnlyCollectionRepositoryInterface.php create mode 100644 src/Repository/SaferPayLogRepository.php create mode 100644 src/Repository/SaferPayLogRepositoryInterface.php create mode 100644 src/Response/JsonResponse.php create mode 100644 src/Utility/ExceptionUtility.php diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 00d40aac..747a95a3 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -21,6 +21,9 @@ *@license SIX Payment Services */ +use Invertus\Saferpay\Context\GlobalShopContextInterface; +use Invertus\SaferPay\Controller\AbstractAdminSaferPayController; +use Invertus\SaferPay\Enum\PermissionType; use Invertus\SaferPay\Logger\Formatter\LogFormatter; use Invertus\SaferPay\Utility\VersionUtility; use Invertus\SaferPay\Logger\Logger; @@ -29,7 +32,7 @@ exit; } -class AdminSaferPayOfficialLogsController extends ModuleAdminController +class AdminSaferPayOfficialLogsController extends AbstractAdminSaferPayController { const FILE_NAME = 'AdminSaferPayOfficialLogsController'; const LOG_INFORMATION_TYPE_REQUEST = 'request'; @@ -219,4 +222,71 @@ public function printResponseButton(string $response, array $data) { return $this->getDisplayButton($data['id_log'], $response, self::LOG_INFORMATION_TYPE_RESPONSE); } + + public function displayAjaxGetLog() + { + if (!$this->ensureHasPermissions([PermissionType::EDIT, PermissionType::VIEW], true)) { + return; + } + + /** @var \Invertus\SaferPay\Adapter\Tools $tools */ + $tools = $this->module->getService(\Invertus\SaferPay\Adapter\Tools::class); + + /** @var \Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface $logRepository */ + $logRepository = $this->module->getService(\Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface::class); + + /** @var GlobalShopContextInterface $globalShopContext */ + $globalShopContext = $this->module->getService(GlobalShopContextInterface::class); + + $logId = $tools->getValueAsInt('log_id'); + +// /** @var LoggerInterface $logger */ +// $logger = $this->module->getService(LoggerInterface::class); + + try { + /** @var \SaferPayLog|null $log */ + $log = $logRepository->findOneBy([ + 'id_log' => $logId, + '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), +// ]); + + $this->ajaxResponse(json_encode([ + 'error' => true, + 'message' => $this->module->l('Failed to find log.', self::FILE_NAME), + ])); + } + + if (!isset($log)) { +// $logger->error('No log information found.', [ +// 'context' => [ +// 'id_log' => $logId, +// 'id_shop' => $globalShopContext->getShopId(), +// ], +// 'exceptions' => [], +// ]); + + $this->ajaxRender(json_encode([ + 'error' => true, + 'message' => $this->module->l('No log information found.', self::FILE_NAME), + ])); + } + $this->ajaxRender($log); + + $this->ajaxResponse(json_encode([ + 'error' => false, + 'log' => [ + self::LOG_INFORMATION_TYPE_REQUEST => $log->request, + self::LOG_INFORMATION_TYPE_RESPONSE => $log->response, + self::LOG_INFORMATION_TYPE_CONTEXT => $log->context, + ], + ])); + } } diff --git a/src/Adapter/LegacyContext.php b/src/Adapter/LegacyContext.php index 500e9f59..ffa80be1 100755 --- a/src/Adapter/LegacyContext.php +++ b/src/Adapter/LegacyContext.php @@ -38,7 +38,17 @@ public function getContext() public function getShopId() { - return $this->getContext()->shop->id; + return (int) $this->getContext()->shop->id; + } + + public function getLanguageId() + { + return (int) $this->getContext()->language->id; + } + + public function getLanguageIso() + { + return (string) $this->getContext()->language->iso_code ?: 'en'; } public function getCurrencyIsoCode() @@ -79,9 +89,74 @@ public function getDeviceDetect() return (int) $this->getContext()->getDevice(); } - public function getAdminLink($controllerName, array $params = []): string + public function getAdminLink($controllerName, array $params = []) { /* @noinspection PhpMethodParametersCountMismatchInspection - its valid for PS1.7 */ return (string) Context::getContext()->link->getAdminLink($controllerName, true, [], $params); } + + public function getLanguageCode() + { + return (string) $this->getContext()->language->language_code ?: 'en-us'; + } + + public function getCurrencyIso() + { + if (!$this->getContext()->currency) { + return ''; + } + + return (string) $this->getContext()->currency->iso_code; + } + + public function getCountryIso() + { + if (!$this->getContext()->country) { + return ''; + } + + return (string) $this->getContext()->country->iso_code; + } + + public function getCurrency() + { + return $this->getContext()->currency; + } + + public function getCustomerId() + { + if (!$this->getContext()->customer) { + return 0; + } + + return (int) $this->getContext()->customer->id; + } + + public function isCustomerLoggedIn() + { + if (!$this->getContext()->customer) { + return false; + } + + return (bool) $this->getContext()->customer->isLogged(); + } + + public function getCustomerEmail() + { + if (!$this->getContext()->customer) { + return ''; + } + + return $this->getContext()->customer->email; + } + + public function getShopDomain() + { + return (string) $this->getContext()->shop->domain; + } + + public function getShopName() + { + return (string) $this->getContext()->shop->name; + } } diff --git a/src/Adapter/Tools.php b/src/Adapter/Tools.php new file mode 100644 index 00000000..4fbd588a --- /dev/null +++ b/src/Adapter/Tools.php @@ -0,0 +1,150 @@ +getValue($value, $defaultValue); + + if (in_array($result, ['false', '0', null, false, 0], true)) { + return false; + } + + return (bool) $result; + } + + /** + * @param string $value + * @param string|false $defaultValue + * + * @return bool + */ + public function getValueAsInteger($value, $defaultValue = false) + { + $result = $this->getValue($value, $defaultValue); + + if (in_array($result, ['false', '0', null, false, 0], true)) { + return 0; + } + + return (int) $result; + } + + public function getAllValues() + { + return PrestashopTools::getAllValues(); + } + + public function getValueAsInt($value, $defaultValue = 0) + { + return (int) PrestashopTools::getValue($value, $defaultValue); + } + + public function getShopDomain() + { + return PrestashopTools::getShopDomain(); + } + + public function displayPrice($price, $currency = null, $no_utf8 = false, PrestashopContext $context = null) + { + return PrestashopTools::displayPrice($price, $currency, $no_utf8, $context); + } + + public function ps_round($value, $precision = 0, $round_mode = null) + { + return PrestashopTools::ps_round($value, $precision, $round_mode); + } + + public function getToken($page = true, PrestashopContext $context = null) + { + return PrestashopTools::getToken($page, $context); + } + + public function convertPriceFull($amount, \Currency $currency_from = null, \Currency $currency_to = null) + { + return PrestashopTools::convertPriceFull($amount, $currency_from, $currency_to); + } +} \ No newline at end of file diff --git a/src/Context/GlobalShopContext.php b/src/Context/GlobalShopContext.php new file mode 100644 index 00000000..ce056401 --- /dev/null +++ b/src/Context/GlobalShopContext.php @@ -0,0 +1,59 @@ +context = $context; + } + + public function getShopId() + { + return $this->context->getShopId(); + } + + public function getLanguageId() + { + return $this->context->getLanguageId(); + } + + public function getLanguageIso() + { + return $this->context->getLanguageIso(); + } + + public function getCurrencyIso() + { + return $this->context->getCurrencyIso(); + } + + public function getCurrency() + { + return $this->context->getCurrency(); + } + + public function getShopDomain() + { + return $this->context->getShopDomain(); + } + + public function getShopName() + { + return $this->context->getShopName(); + } + + public function isShopSingleShopContext() + { + return \Shop::getContext() === \Shop::CONTEXT_SHOP; + } +} \ No newline at end of file diff --git a/src/Context/GlobalShopContextInterface.php b/src/Context/GlobalShopContextInterface.php new file mode 100644 index 00000000..2733f44f --- /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/Controller/AbstractAdminSaferPayController.php b/src/Controller/AbstractAdminSaferPayController.php new file mode 100644 index 00000000..fb716da7 --- /dev/null +++ b/src/Controller/AbstractAdminSaferPayController.php @@ -0,0 +1,72 @@ +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(), +// ], +// ]); + } + + http_response_code($value->getStatusCode()); + + $value = $value->getContent(); + } + + try { + if (method_exists(\ControllerCore::class, 'ajaxRender')) { + $this->ajaxRender($value, $controller, $method); + + exit; + } + + $this->ajaxDie($value, $controller, $method); + } catch (\Exception $exception) { +// $logger->error('Could not return ajax response', [ +// 'context' => [ +// 'response' => json_encode($value ?: []), +// 'exceptions' => ExceptionUtility::getExceptions($exception), +// ], +// ]); + } + + exit; + } + + public function ensureHasPermissions(array $permissions, bool $ajax = false): bool + { + foreach ($permissions as $permission) { + if (!$this->access($permission)) { + if ($ajax) { + $this->ajaxResponse(json_encode([ + 'error' => true, + 'message' => $this->module->l('Unauthorized.', self::FILE_NAME), + ]), JsonResponse::HTTP_UNAUTHORIZED); + } else { + $this->errors[] = $this->module->l( + 'You do not have permission to view this.', + self::FILE_NAME + ); + } + + return false; + } + } + + return true; + } +} \ No newline at end of file diff --git a/src/Enum/PermissionType.php b/src/Enum/PermissionType.php new file mode 100644 index 00000000..42cccc95 --- /dev/null +++ b/src/Enum/PermissionType.php @@ -0,0 +1,13 @@ +fullyClassifiedClassName = $fullyClassifiedClassName; + } + + public function findAllInCollection($langId = null): \PrestaShopCollection + { + return new \PrestaShopCollection($this->fullyClassifiedClassName, $langId); + } + + /** + * @param array $keyValueCriteria + * @param int|null $langId + * + * @return \ObjectModel|null + * + * @throws \PrestaShopException + */ + public function findOneBy(array $keyValueCriteria, $langId = null): ?\ObjectModel + { + $psCollection = new \PrestaShopCollection($this->fullyClassifiedClassName, $langId); + + foreach ($keyValueCriteria as $field => $value) { + $psCollection = $psCollection->where($field, '=', $value); + } + + $first = $psCollection->getFirst(); + + return false === $first ? null : $first; + } +} \ No newline at end of file diff --git a/src/Repository/ReadOnlyCollectionRepositoryInterface.php b/src/Repository/ReadOnlyCollectionRepositoryInterface.php new file mode 100644 index 00000000..4fdb7828 --- /dev/null +++ b/src/Repository/ReadOnlyCollectionRepositoryInterface.php @@ -0,0 +1,29 @@ +name is string instead of multidimensional array where key is id_language. + * Always pass language id + * unless there is a special need not to. Synchronization or smth. + * It saves quite a lot performance wise. + * + * @return \PrestaShopCollection + */ + public function findAllInCollection($langId = null): \PrestaShopCollection; + + /** + * @param array $keyValueCriteria - e.g [ 'id_cart' => 5 ] + * @param int|null $langId + * + * @return \ObjectModel|null + */ + public function findOneBy(array $keyValueCriteria, $langId = null): ?\ObjectModel; +} \ No newline at end of file diff --git a/src/Repository/SaferPayLogRepository.php b/src/Repository/SaferPayLogRepository.php new file mode 100644 index 00000000..228ecee9 --- /dev/null +++ b/src/Repository/SaferPayLogRepository.php @@ -0,0 +1,29 @@ +findAllInCollection() + ->sqlWhere('DATEDIFF(NOW(),date_add) >= ' . $daysToKeep) + ) + ->each(function (\KlarnaPaymentLog $log) { + $log->delete(); + }) + ->realize(); + } +} \ No newline at end of file diff --git a/src/Repository/SaferPayLogRepositoryInterface.php b/src/Repository/SaferPayLogRepositoryInterface.php new file mode 100644 index 00000000..5057202e --- /dev/null +++ b/src/Repository/SaferPayLogRepositoryInterface.php @@ -0,0 +1,12 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +namespace Invertus\SaferPay\Response; + +use Symfony\Component\HttpFoundation\JsonResponse as BaseJsonResponse; + +if (!defined('_PS_VERSION_')) { + exit; +} + +class JsonResponse extends BaseJsonResponse +{ + /** + * @param mixed $data + */ + public function __construct($data = null, int $status = 200, array $headers = []) + { + parent::__construct($data, $status, $headers); + } + + public static function success(array $data, int $status = 200): self + { + return new self([ + 'success' => true, + 'errors' => [], + 'data' => $data, + ], $status); + } + + /** + * @param string|array $error + * @param int $status + * + * @return static + */ + public static function error($error, int $status = 400): self + { + if ($status === JsonResponse::HTTP_UNPROCESSABLE_ENTITY) { + // NOTE: removing rule name. ['required' => 'message'] becomes [0 => 'message'] + foreach ($error as $key => $messages) { + $error[$key] = array_values($messages); + } + } + + if (!is_array($error)) { + $error = [$error]; + } + + return new self([ + 'success' => false, + 'errors' => $error, + 'data' => [], + ], $status); + } +} diff --git a/src/Utility/ExceptionUtility.php b/src/Utility/ExceptionUtility.php new file mode 100644 index 00000000..52361fca --- /dev/null +++ b/src/Utility/ExceptionUtility.php @@ -0,0 +1,57 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +namespace Invertus\SaferPay\Utility; + +if (!defined('_PS_VERSION_')) { + exit; +} + +class ExceptionUtility +{ + public static function getExceptions(\Throwable $exception) + { + if (method_exists($exception, 'getExceptions')) { + return $exception->getExceptions(); + } + + return [self::toArray($exception)]; + } + + public static function toArray(\Throwable $exception): array + { + if (method_exists($exception, 'getContext')) { + $context = $exception->getContext(); + } else { + $context = []; + } + + return [ + 'message' => (string) $exception->getMessage(), + 'code' => (int) $exception->getCode(), + 'file' => (string) $exception->getFile(), + 'line' => (int) $exception->getLine(), + 'context' => $context, + ]; + } +} diff --git a/views/js/admin/log.js b/views/js/admin/log.js index 9c7ba8ac..43d9c061 100644 --- a/views/js/admin/log.js +++ b/views/js/admin/log.js @@ -53,14 +53,13 @@ $(document).ready(function () { .then(data => { $('.log-modal-content-spinner').addClass('hidden') - $('#log-modal-' + logId + '-request .log-modal-content-data').removeClass('hidden').html(prettyJson(data.log.request)); - $('#log-modal-' + logId + '-response .log-modal-content-data').removeClass('hidden').html(prettyJson(data.log.response)); - $('#log-modal-' + logId + '-context .log-modal-content-data').removeClass('hidden').html(prettyJson(data.log.context)); + $('#log-modal-' + logId + '-request .log-modal-content-data').removeClass('hidden').html(data.log.request); + $('#log-modal-' + logId + '-response .log-modal-content-data').removeClass('hidden').html(data.log.response); + $('#log-modal-' + logId + '-context .log-modal-content-data').removeClass('hidden').html(data.log.context); }) }); }); -function prettyJson(json) { - var parsed = jQuery.parseJSON(json); // Using older jQuery to parse JSON - return JSON.stringify(parsed, null, 2); -} +// function prettyJson(json) { +// return JSON.stringify(JSON.parse(json), null, 2) +// } From ca27963d82524543452e60c179526164193aa655 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 11:48:15 +0300 Subject: [PATCH 23/90] [SV-34] removed return types --- src/Adapter/Tools.php | 21 +++++++++++++++++++ src/Repository/CollectionRepository.php | 4 ++-- .../ReadOnlyCollectionRepositoryInterface.php | 4 ++-- .../SaferPayLogRepositoryInterface.php | 21 +++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/Adapter/Tools.php b/src/Adapter/Tools.php index 4fbd588a..e5bd24d1 100644 --- a/src/Adapter/Tools.php +++ b/src/Adapter/Tools.php @@ -1,4 +1,25 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services + */ namespace Invertus\SaferPay\Adapter; diff --git a/src/Repository/CollectionRepository.php b/src/Repository/CollectionRepository.php index c15485f3..0387bd36 100644 --- a/src/Repository/CollectionRepository.php +++ b/src/Repository/CollectionRepository.php @@ -18,7 +18,7 @@ public function __construct(string $fullyClassifiedClassName) $this->fullyClassifiedClassName = $fullyClassifiedClassName; } - public function findAllInCollection($langId = null): \PrestaShopCollection + public function findAllInCollection($langId = null) { return new \PrestaShopCollection($this->fullyClassifiedClassName, $langId); } @@ -31,7 +31,7 @@ public function findAllInCollection($langId = null): \PrestaShopCollection * * @throws \PrestaShopException */ - public function findOneBy(array $keyValueCriteria, $langId = null): ?\ObjectModel + public function findOneBy(array $keyValueCriteria, $langId = null) { $psCollection = new \PrestaShopCollection($this->fullyClassifiedClassName, $langId); diff --git a/src/Repository/ReadOnlyCollectionRepositoryInterface.php b/src/Repository/ReadOnlyCollectionRepositoryInterface.php index 4fdb7828..150a3e38 100644 --- a/src/Repository/ReadOnlyCollectionRepositoryInterface.php +++ b/src/Repository/ReadOnlyCollectionRepositoryInterface.php @@ -17,7 +17,7 @@ interface ReadOnlyCollectionRepositoryInterface * * @return \PrestaShopCollection */ - public function findAllInCollection($langId = null): \PrestaShopCollection; + public function findAllInCollection($langId = null); /** * @param array $keyValueCriteria - e.g [ 'id_cart' => 5 ] @@ -25,5 +25,5 @@ public function findAllInCollection($langId = null): \PrestaShopCollection; * * @return \ObjectModel|null */ - public function findOneBy(array $keyValueCriteria, $langId = null): ?\ObjectModel; + public function findOneBy(array $keyValueCriteria, $langId = null); } \ No newline at end of file diff --git a/src/Repository/SaferPayLogRepositoryInterface.php b/src/Repository/SaferPayLogRepositoryInterface.php index 5057202e..e09737bf 100644 --- a/src/Repository/SaferPayLogRepositoryInterface.php +++ b/src/Repository/SaferPayLogRepositoryInterface.php @@ -1,4 +1,25 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services + */ namespace Invertus\SaferPay\Repository; From 6204393e44e2ab20eb79d4992cadc8ce9b407721 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 12:02:39 +0300 Subject: [PATCH 24/90] [SV-34] added licences --- .../AdminSaferPayOfficialLogsController.php | 5 ++-- src/Context/GlobalShopContext.php | 11 +++++++++ .../AbstractAdminSaferPayController.php | 11 +++++++++ src/Enum/PermissionType.php | 11 +++++++++ src/Logger/Formatter/LogFormatter.php | 21 +++++++++++++++++ src/Logger/Logger.php | 21 +++++++++++++++++ src/Repository/CollectionRepository.php | 21 +++++++++++++++++ .../ReadOnlyCollectionRepositoryInterface.php | 21 +++++++++++++++++ src/Repository/SaferPayLogRepository.php | 23 ++++++++++++++++++- views/templates/admin/logs/log_modal.tpl | 21 +++++++++++++++++ 10 files changed, 163 insertions(+), 3 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 747a95a3..e2f3a85b 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -27,6 +27,7 @@ use Invertus\SaferPay\Logger\Formatter\LogFormatter; use Invertus\SaferPay\Utility\VersionUtility; use Invertus\SaferPay\Logger\Logger; +use Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface; if (!defined('_PS_VERSION_')) { exit; @@ -232,8 +233,8 @@ public function displayAjaxGetLog() /** @var \Invertus\SaferPay\Adapter\Tools $tools */ $tools = $this->module->getService(\Invertus\SaferPay\Adapter\Tools::class); - /** @var \Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface $logRepository */ - $logRepository = $this->module->getService(\Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface::class); +// /** @var \Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface $logRepository */ +// $logRepository = $this->module->getService(\Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface::class); /** @var GlobalShopContextInterface $globalShopContext */ $globalShopContext = $this->module->getService(GlobalShopContextInterface::class); diff --git a/src/Context/GlobalShopContext.php b/src/Context/GlobalShopContext.php index ce056401..8e4980be 100644 --- a/src/Context/GlobalShopContext.php +++ b/src/Context/GlobalShopContext.php @@ -1,4 +1,15 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services + */ namespace Invertus\SaferPay\Logger\Formatter; diff --git a/src/Logger/Logger.php b/src/Logger/Logger.php index cf8e9e41..f6201dd7 100644 --- a/src/Logger/Logger.php +++ b/src/Logger/Logger.php @@ -1,4 +1,25 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services + */ namespace Invertus\SaferPay\Logger; diff --git a/src/Repository/CollectionRepository.php b/src/Repository/CollectionRepository.php index 0387bd36..e695b644 100644 --- a/src/Repository/CollectionRepository.php +++ b/src/Repository/CollectionRepository.php @@ -1,4 +1,25 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services + */ namespace Invertus\SaferPay\Repository; diff --git a/src/Repository/ReadOnlyCollectionRepositoryInterface.php b/src/Repository/ReadOnlyCollectionRepositoryInterface.php index 150a3e38..357a1704 100644 --- a/src/Repository/ReadOnlyCollectionRepositoryInterface.php +++ b/src/Repository/ReadOnlyCollectionRepositoryInterface.php @@ -1,4 +1,25 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services + */ namespace Invertus\SaferPay\Repository; diff --git a/src/Repository/SaferPayLogRepository.php b/src/Repository/SaferPayLogRepository.php index 228ecee9..1f06708c 100644 --- a/src/Repository/SaferPayLogRepository.php +++ b/src/Repository/SaferPayLogRepository.php @@ -1,4 +1,25 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services + */ use Invertus\Knapsack\Collection; use Invertus\SaferPay\Repository\CollectionRepository; @@ -8,7 +29,7 @@ exit; } -class KlarnaPaymentLogRepository extends CollectionRepository implements SaferPayLogRepositoryInterface +class SaferPayLogRepository extends CollectionRepository implements SaferPayLogRepositoryInterface { public function __construct() { diff --git a/views/templates/admin/logs/log_modal.tpl b/views/templates/admin/logs/log_modal.tpl index f5533368..62cb43dd 100644 --- a/views/templates/admin/logs/log_modal.tpl +++ b/views/templates/admin/logs/log_modal.tpl @@ -1,3 +1,24 @@ +{** + *NOTICE OF LICENSE + * + *This source file is subject to the Open Software License (OSL 3.0) + *that is bundled with this package in the file LICENSE.txt. + *It is also available through the world-wide-web at this URL: + *http://opensource.org/licenses/osl-3.0.php + *If you did not receive a copy of the license and are unable to + *obtain it through the world-wide-web, please send an email + *to license@prestashop.com so we can send you a copy immediately. + * + *DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer + *versions in the future. If you wish to customize PrestaShop for your + *needs please refer to http://www.prestashop.com for more information. + * + *@author INVERTUS UAB www.invertus.eu + *@copyright SIX Payment Services + *@license SIX Payment Services + *}
Date: Tue, 1 Oct 2024 12:06:00 +0300 Subject: [PATCH 25/90] [SV-34] minor changes --- controllers/admin/AdminSaferPayOfficialLogsController.php | 4 ++-- src/Repository/SaferPayLogRepository.php | 2 ++ src/Repository/SaferPayLogRepositoryInterface.php | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index e2f3a85b..70304273 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -233,8 +233,8 @@ public function displayAjaxGetLog() /** @var \Invertus\SaferPay\Adapter\Tools $tools */ $tools = $this->module->getService(\Invertus\SaferPay\Adapter\Tools::class); -// /** @var \Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface $logRepository */ -// $logRepository = $this->module->getService(\Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface::class); + /** @var SaferPayLogRepositoryInterface $logRepository */ + $logRepository = $this->module->getService(SaferPayLogRepositoryInterface::class); /** @var GlobalShopContextInterface $globalShopContext */ $globalShopContext = $this->module->getService(GlobalShopContextInterface::class); diff --git a/src/Repository/SaferPayLogRepository.php b/src/Repository/SaferPayLogRepository.php index 1f06708c..79589b33 100644 --- a/src/Repository/SaferPayLogRepository.php +++ b/src/Repository/SaferPayLogRepository.php @@ -21,6 +21,8 @@ *@license SIX Payment Services */ +namespace Invertus\SaferPay\Repository; + use Invertus\Knapsack\Collection; use Invertus\SaferPay\Repository\CollectionRepository; use Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface; diff --git a/src/Repository/SaferPayLogRepositoryInterface.php b/src/Repository/SaferPayLogRepositoryInterface.php index e09737bf..5b7b38c0 100644 --- a/src/Repository/SaferPayLogRepositoryInterface.php +++ b/src/Repository/SaferPayLogRepositoryInterface.php @@ -23,6 +23,8 @@ namespace Invertus\SaferPay\Repository; +use Invertus\SaferPay\Repository\ReadOnlyCollectionRepositoryInterface; + if (!defined('_PS_VERSION_')) { exit; } From 8604a809bbdd9a6be17ba9cd5ef94c2c1b116357 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 14:35:44 +0300 Subject: [PATCH 26/90] [SV-34] fix --- .../admin/AdminSaferPayOfficialLogsController.php | 9 +++++---- src/Context/GlobalShopContext.php | 6 +++--- src/Context/GlobalShopContextInterface.php | 1 - src/ServiceProvider/BaseServiceProvider.php | 5 +++++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 70304273..a3ed4f59 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -21,10 +21,12 @@ *@license SIX Payment Services */ +use Invertus\Saferpay\Context\GlobalShopContext; use Invertus\Saferpay\Context\GlobalShopContextInterface; use Invertus\SaferPay\Controller\AbstractAdminSaferPayController; use Invertus\SaferPay\Enum\PermissionType; use Invertus\SaferPay\Logger\Formatter\LogFormatter; +use Invertus\SaferPay\Repository\SaferPayLogRepository; use Invertus\SaferPay\Utility\VersionUtility; use Invertus\SaferPay\Logger\Logger; use Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface; @@ -233,11 +235,10 @@ public function displayAjaxGetLog() /** @var \Invertus\SaferPay\Adapter\Tools $tools */ $tools = $this->module->getService(\Invertus\SaferPay\Adapter\Tools::class); - /** @var SaferPayLogRepositoryInterface $logRepository */ + /** @var SaferPayLogRepository $logRepository */ $logRepository = $this->module->getService(SaferPayLogRepositoryInterface::class); - /** @var GlobalShopContextInterface $globalShopContext */ - $globalShopContext = $this->module->getService(GlobalShopContextInterface::class); + /* GlobalShopContext service */ $logId = $tools->getValueAsInt('log_id'); @@ -248,7 +249,7 @@ public function displayAjaxGetLog() /** @var \SaferPayLog|null $log */ $log = $logRepository->findOneBy([ 'id_log' => $logId, - 'id_shop' => $globalShopContext->getShopId(), + 'id_shop' => Context::getContext()->shop->id, ]); } catch (Exception $exception) { // $logger->error('Failed to find log', [ diff --git a/src/Context/GlobalShopContext.php b/src/Context/GlobalShopContext.php index 8e4980be..8c6ef5e2 100644 --- a/src/Context/GlobalShopContext.php +++ b/src/Context/GlobalShopContext.php @@ -13,17 +13,17 @@ namespace Invertus\Saferpay\Context; -use Invertus\SaferPay\Adapter\LegacyContext as Context; +use Invertus\SaferPay\Adapter\LegacyContext; if (!defined('_PS_VERSION_')) { exit; } -final class GlobalShopContext implements GlobalShopContextInterface +class GlobalShopContext { private $context; - public function __construct(Context $context) + public function __construct(LegacyContext $context) { $this->context = $context; } diff --git a/src/Context/GlobalShopContextInterface.php b/src/Context/GlobalShopContextInterface.php index 2733f44f..429af612 100644 --- a/src/Context/GlobalShopContextInterface.php +++ b/src/Context/GlobalShopContextInterface.php @@ -46,5 +46,4 @@ public function getShopDomain(); public function getShopName(); - public function isShopSingleShopContext(); } \ No newline at end of file diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index fb547e64..734d482d 100755 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -23,10 +23,14 @@ namespace Invertus\SaferPay\ServiceProvider; +use Invertus\Saferpay\Context\GlobalShopContext; +use Invertus\Saferpay\Context\GlobalShopContextInterface; use Invertus\SaferPay\Provider\BasicIdempotencyProvider; use Invertus\SaferPay\Provider\IdempotencyProviderInterface; use Invertus\SaferPay\Repository\OrderRepository; use Invertus\SaferPay\Repository\OrderRepositoryInterface; +use Invertus\SaferPay\Repository\SaferPayLogRepository; +use Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface; use League\Container\Container; if (!defined('_PS_VERSION_')) { @@ -49,6 +53,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)); } private function addService(Container $container, $className, $service) From 8604eaedd53fefbc1ff2831e17eea7bb0e8b5f6a Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 14:53:42 +0300 Subject: [PATCH 27/90] [SV-34] minor --- .../admin/AdminSaferPayOfficialLogsController.php | 7 +++++-- src/ServiceProvider/BaseServiceProvider.php | 9 +++++++-- views/js/admin/log.js | 12 ++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index a3ed4f59..54bddd34 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -226,6 +226,11 @@ public function printResponseButton(string $response, array $data) return $this->getDisplayButton($data['id_log'], $response, self::LOG_INFORMATION_TYPE_RESPONSE); } + public function printContextButton(string $context, array $data) + { + return $this->getDisplayButton($data['id_log'], $context, self::LOG_INFORMATION_TYPE_CONTEXT); + } + public function displayAjaxGetLog() { if (!$this->ensureHasPermissions([PermissionType::EDIT, PermissionType::VIEW], true)) { @@ -238,8 +243,6 @@ public function displayAjaxGetLog() /** @var SaferPayLogRepository $logRepository */ $logRepository = $this->module->getService(SaferPayLogRepositoryInterface::class); - /* GlobalShopContext service */ - $logId = $tools->getValueAsInt('log_id'); // /** @var LoggerInterface $logger */ diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index 734d482d..48a3c1b8 100755 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -23,8 +23,9 @@ namespace Invertus\SaferPay\ServiceProvider; -use Invertus\Saferpay\Context\GlobalShopContext; -use Invertus\Saferpay\Context\GlobalShopContextInterface; +use Invertus\SaferPay\Adapter\LegacyContext; +use Invertus\SaferPay\Context\GlobalShopContext; +use Invertus\SaferPay\Context\GlobalShopContextInterface; use Invertus\SaferPay\Provider\BasicIdempotencyProvider; use Invertus\SaferPay\Provider\IdempotencyProviderInterface; use Invertus\SaferPay\Repository\OrderRepository; @@ -51,6 +52,10 @@ public function __construct($extendedServices) public function register(Container $container) { + $container->add(GlobalShopContext::class, function() { + return new GlobalShopContext($this->getService(LegacyContext::class, new LegacyContext())); + }); + $this->addService($container, GlobalShopContextInterface::class, $container->get(GlobalShopContext::class)); $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)); diff --git a/views/js/admin/log.js b/views/js/admin/log.js index 43d9c061..4a8eb769 100644 --- a/views/js/admin/log.js +++ b/views/js/admin/log.js @@ -53,13 +53,13 @@ $(document).ready(function () { .then(data => { $('.log-modal-content-spinner').addClass('hidden') - $('#log-modal-' + logId + '-request .log-modal-content-data').removeClass('hidden').html(data.log.request); - $('#log-modal-' + logId + '-response .log-modal-content-data').removeClass('hidden').html(data.log.response); - $('#log-modal-' + logId + '-context .log-modal-content-data').removeClass('hidden').html(data.log.context); + $('#log-modal-' + logId + '-request .log-modal-content-data').removeClass('hidden').html(prettyJson(data.log.request)); + $('#log-modal-' + logId + '-response .log-modal-content-data').removeClass('hidden').html(prettyJson(data.log.response)); + $('#log-modal-' + logId + '-context .log-modal-content-data').removeClass('hidden').html(prettyJson(data.log.context)); }) }); }); -// function prettyJson(json) { -// return JSON.stringify(JSON.parse(json), null, 2) -// } +function prettyJson(json) { + return JSON.stringify(JSON.parse(json), null, 2) +} From 8d62c307ae377329fd12163e59b257f608a180ad Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 15:00:19 +0300 Subject: [PATCH 28/90] [SV-34] added CSS --- views/css/admin/logs_tab.css | 90 +++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/views/css/admin/logs_tab.css b/views/css/admin/logs_tab.css index f679c02c..5bb36a92 100755 --- a/views/css/admin/logs_tab.css +++ b/views/css/admin/logs_tab.css @@ -22,4 +22,92 @@ .saferpay-text-break { word-break: break-all; width: 700px; -} \ No newline at end of file +} + +.button { + cursor: pointer; +} + +.log-modal-overlay { + transition: opacity 0.2s ease-out; + pointer-events: none; + background: rgba(15, 23, 42, 0.8); + position: fixed; + opacity: 0; + bottom: 0; + right: 0; + left: 0; + top: 0; +} + +.modal.open .log-modal-overlay { + pointer-events: all; + opacity: 0.5; +} + +.log-modal-window { + position: relative; + width: 50%; + margin: 10% auto; + + background: #ffffff; + border-radius: 0.5em; + box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2); + pointer-events: all; + text-align: left; + max-height: 100vh; + min-height: 60vh; + display: flex; + flex-direction: column; + + overflow: auto; +} + +.open { + display: block; +} + +.log-modal-title { + color: #111827; + padding: 3px; + border-bottom: solid 1px grey; + pointer-events: all; + display: flex; + justify-content: center; + max-height: 10vh; +} + +.log-modal-content { + padding: 15px; + height: 50vh; +} + +.log-modal-content-spinner { + min-height: 50vh; +} + +.log-modal-content-spinner:not(.hidden) { + display: flex; + justify-content: center; + align-items: center; +} + +.log-modal-content-spinner::after { + content: ""; + width: 40px; + height: 40px; + border: 2px solid #f3f3f3; + border-top: 3px solid #f25a41; + border-radius: 100%; + will-change: transform; + animation: spin 1s infinite linear +} + +@keyframes spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} From 58276b53a2b07aa8f80c2378a9f924714a606e53 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 15:20:35 +0300 Subject: [PATCH 29/90] [SV-33] fixed issues --- src/Install/Installer.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Install/Installer.php b/src/Install/Installer.php index a35017d5..69136f0e 100755 --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -300,15 +300,17 @@ private function installSaferPayLog() { return Db::getInstance()->execute( 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . pSQL(\SaferPayLog::$definition['table']) . '( - `id_saferpay_log` INTEGER(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, - `id_log` INTEGER(10) DEFAULT 0, - `id_shop` INTEGER(10) DEFAULT 1, + `id_saferpay_log` INTEGER(10) UNSIGNED AUTO_INCREMENT, + `id_log` INT(10) DEFAULT 0, + `id_shop` INT(10) DEFAULT ' . Configuration::get('PS_SHOP_DEFAULT') . ', `message` TEXT NOT NULL DEFAULT "", `request` TEXT NOT NULL DEFAULT "", `response` TEXT NOT NULL DEFAULT "", `context` TEXT NOT NULL DEFAULT "", - `date_add` datetime NOT NULL DEFAULT NOW() - ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' + `date_add` datetime NOT NULL DEFAULT NOW(), + PRIMARY KEY (`id_saferpay_log`, `id_log`, `id_shop`), + INDEX (`id_log`) + ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' ); } From cf80e8cd93fb8fce047d1919a36a47b55b5bf899 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 15:53:09 +0300 Subject: [PATCH 30/90] [SV-33] updated schema --- upgrade/install-1.2.4.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/upgrade/install-1.2.4.php b/upgrade/install-1.2.4.php index ac08bd24..0350697f 100644 --- a/upgrade/install-1.2.4.php +++ b/upgrade/install-1.2.4.php @@ -31,12 +31,14 @@ function upgrade_module_1_2_4(SaferPayOfficial $module) { return Db::getInstance()->execute( - 'ALTER TABLE ' . _DB_PREFIX_ . SaferPayLog::$definition['table'] . ' - ADD COLUMN `id_log` INTEGER(10) DEFAULT 0, - ADD COLUMN `id_shop` INTEGER(10) DEFAULT 1, - CHANGE `payload` `request` TEXT, - ADD COLUMN `response` TEXT DEFAULT "", - ADD COLUMN `context` TEXT DEFAULT "", - ADD PRIMARY KEY (`id_log`, `id_shop`);' + 'ALTER TABLE ' . _DB_PREFIX_ . pSQL(SaferPayLog::$definition['table']) . ' + ADD COLUMN `id_log` INT(10) DEFAULT 0, + ADD COLUMN `id_shop` INT(10) DEFAULT ' . Configuration::get('PS_SHOP_DEFAULT') . ', + CHANGE `payload` `request` TEXT, + ADD COLUMN `response` TEXT DEFAULT "", + ADD COLUMN `context` TEXT DEFAULT "", + DROP PRIMARY KEY, + ADD PRIMARY KEY (`id_log`, `id_shop`), + ADD INDEX (`id_log`),' ); } From c21c69e3e8cc5f9ce5550f5f3ad14f82ab7c2938 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 15:55:42 +0300 Subject: [PATCH 31/90] [SV-33] fix --- src/Install/Installer.php | 8 ++++---- upgrade/install-1.2.4.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Install/Installer.php b/src/Install/Installer.php index 69136f0e..681c5e19 100755 --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -303,10 +303,10 @@ private function installSaferPayLog() `id_saferpay_log` INTEGER(10) UNSIGNED AUTO_INCREMENT, `id_log` INT(10) DEFAULT 0, `id_shop` INT(10) DEFAULT ' . Configuration::get('PS_SHOP_DEFAULT') . ', - `message` TEXT NOT NULL DEFAULT "", - `request` TEXT NOT NULL DEFAULT "", - `response` TEXT NOT NULL DEFAULT "", - `context` TEXT NOT NULL DEFAULT "", + `message` TEXT DEFAULT NULL, + `request` MEDIUMTEXT DEFAULT NULL, + `response` MEDIUMTEXT DEFAULT NULL, + `context` TEXT DEFAULT NULL, `date_add` datetime NOT NULL DEFAULT NOW(), PRIMARY KEY (`id_saferpay_log`, `id_log`, `id_shop`), INDEX (`id_log`) diff --git a/upgrade/install-1.2.4.php b/upgrade/install-1.2.4.php index 0350697f..9a268518 100644 --- a/upgrade/install-1.2.4.php +++ b/upgrade/install-1.2.4.php @@ -35,8 +35,8 @@ function upgrade_module_1_2_4(SaferPayOfficial $module) ADD COLUMN `id_log` INT(10) DEFAULT 0, ADD COLUMN `id_shop` INT(10) DEFAULT ' . Configuration::get('PS_SHOP_DEFAULT') . ', CHANGE `payload` `request` TEXT, - ADD COLUMN `response` TEXT DEFAULT "", - ADD COLUMN `context` TEXT DEFAULT "", + ADD COLUMN `response` MEDIUMTEXT DEFAULT NULL, + ADD COLUMN `context` MEDIUMTEXT DEFAULT NULL, DROP PRIMARY KEY, ADD PRIMARY KEY (`id_log`, `id_shop`), ADD INDEX (`id_log`),' From 996535735a2912e6c914de38221c9aacf687b602 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 16:54:53 +0300 Subject: [PATCH 32/90] [SV-34] removed useless code --- .../AdminSaferPayOfficialLogsController.php | 12 +++-- src/Config/SaferPayConfig.php | 8 +++ src/Context/GlobalShopContext.php | 5 +- src/Context/GlobalShopContextInterface.php | 49 ------------------- 4 files changed, 20 insertions(+), 54 deletions(-) delete mode 100644 src/Context/GlobalShopContextInterface.php diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 54bddd34..25c41726 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -21,6 +21,7 @@ *@license SIX Payment Services */ +use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\Saferpay\Context\GlobalShopContext; use Invertus\Saferpay\Context\GlobalShopContextInterface; use Invertus\SaferPay\Controller\AbstractAdminSaferPayController; @@ -173,16 +174,16 @@ public function printSeverityLevel(int $level) 'log_severity_level' => $level, 'log_severity_level_informative' => defined('\PrestaShopLogger::LOG_SEVERITY_LEVEL_INFORMATIVE') ? PrestaShopLogger::LOG_SEVERITY_LEVEL_INFORMATIVE : - Config::LOG_SEVERITY_LEVEL_INFORMATIVE, + SaferPayConfig::LOG_SEVERITY_LEVEL_INFORMATIVE, 'log_severity_level_warning' => defined('\PrestaShopLogger::LOG_SEVERITY_LEVEL_WARNING') ? PrestaShopLogger::LOG_SEVERITY_LEVEL_WARNING : - Config::LOG_SEVERITY_LEVEL_WARNING, + SaferPayConfig::LOG_SEVERITY_LEVEL_WARNING, 'log_severity_level_error' => defined('\PrestaShopLogger::LOG_SEVERITY_LEVEL_ERROR') ? PrestaShopLogger::LOG_SEVERITY_LEVEL_ERROR : - Config::LOG_SEVERITY_LEVEL_ERROR, + SaferPayConfig::LOG_SEVERITY_LEVEL_ERROR, 'log_severity_level_major' => defined('\PrestaShopLogger::LOG_SEVERITY_LEVEL_MAJOR') ? PrestaShopLogger::LOG_SEVERITY_LEVEL_MAJOR : - Config::LOG_SEVERITY_LEVEL_MAJOR, + SaferPayConfig::LOG_SEVERITY_LEVEL_MAJOR, ]); return $this->context->smarty->fetch( @@ -243,6 +244,9 @@ public function displayAjaxGetLog() /** @var SaferPayLogRepository $logRepository */ $logRepository = $this->module->getService(SaferPayLogRepositoryInterface::class); + /** @var GlobalShopContext $shopContext */ + $shopContext = $this->module->getService(GlobalShopContext::class); + $logId = $tools->getValueAsInt('log_id'); // /** @var LoggerInterface $logger */ diff --git a/src/Config/SaferPayConfig.php b/src/Config/SaferPayConfig.php index e56fc101..fd84f2df 100755 --- a/src/Config/SaferPayConfig.php +++ b/src/Config/SaferPayConfig.php @@ -266,6 +266,14 @@ class SaferPayConfig const SAFERPAY_CARDFORM_HOLDERNAME_REQUIRENCE = 'MANDATORY'; const SAFERPAY_DEBUG_MODE = 'SAFERPAY_DEBUG_MODE'; + public const LOG_SEVERITY_LEVEL_INFORMATIVE = 1; + + public const LOG_SEVERITY_LEVEL_WARNING = 2; + + public const LOG_SEVERITY_LEVEL_ERROR = 3; + + public const LOG_SEVERITY_LEVEL_MAJOR = 4; + public static function supportsOrderCapture(string $paymentMethod) { //payments that DOES NOT SUPPORT capture diff --git a/src/Context/GlobalShopContext.php b/src/Context/GlobalShopContext.php index 8c6ef5e2..751403a9 100644 --- a/src/Context/GlobalShopContext.php +++ b/src/Context/GlobalShopContext.php @@ -18,7 +18,10 @@ if (!defined('_PS_VERSION_')) { exit; } - +/** + * Gets shop context data + * NOTE: Done without interface because throwing error in the module + */ class GlobalShopContext { private $context; diff --git a/src/Context/GlobalShopContextInterface.php b/src/Context/GlobalShopContextInterface.php deleted file mode 100644 index 429af612..00000000 --- a/src/Context/GlobalShopContextInterface.php +++ /dev/null @@ -1,49 +0,0 @@ - - *@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(); - -} \ No newline at end of file From 88c14d88a64150f11c628ddd0ff0f0891c172423 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Tue, 1 Oct 2024 17:00:19 +0300 Subject: [PATCH 33/90] [SV-34] removed Services as interface --- src/ServiceProvider/BaseServiceProvider.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index 48a3c1b8..5b600aa3 100755 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -23,9 +23,6 @@ namespace Invertus\SaferPay\ServiceProvider; -use Invertus\SaferPay\Adapter\LegacyContext; -use Invertus\SaferPay\Context\GlobalShopContext; -use Invertus\SaferPay\Context\GlobalShopContextInterface; use Invertus\SaferPay\Provider\BasicIdempotencyProvider; use Invertus\SaferPay\Provider\IdempotencyProviderInterface; use Invertus\SaferPay\Repository\OrderRepository; @@ -52,10 +49,6 @@ public function __construct($extendedServices) public function register(Container $container) { - $container->add(GlobalShopContext::class, function() { - return new GlobalShopContext($this->getService(LegacyContext::class, new LegacyContext())); - }); - $this->addService($container, GlobalShopContextInterface::class, $container->get(GlobalShopContext::class)); $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)); From 7f73740fe196301cc2b46e91bdf34793b4a6d288 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 13:37:03 +0300 Subject: [PATCH 34/90] [SV-33] fix datetime --- src/Install/Installer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Install/Installer.php b/src/Install/Installer.php index 681c5e19..a5f673b4 100755 --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -307,7 +307,7 @@ private function installSaferPayLog() `request` MEDIUMTEXT DEFAULT NULL, `response` MEDIUMTEXT DEFAULT NULL, `context` TEXT DEFAULT NULL, - `date_add` datetime NOT NULL DEFAULT NOW(), + `date_add` datetime NOT NULL, PRIMARY KEY (`id_saferpay_log`, `id_log`, `id_shop`), INDEX (`id_log`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' From 2a9167ea66dbb1bf0f9e2095e4a6efadba91759b Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 13:37:40 +0300 Subject: [PATCH 35/90] [SV-33] casted default shop value --- src/Install/Installer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Install/Installer.php b/src/Install/Installer.php index a5f673b4..e7b3c727 100755 --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -302,7 +302,7 @@ private function installSaferPayLog() 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . pSQL(\SaferPayLog::$definition['table']) . '( `id_saferpay_log` INTEGER(10) UNSIGNED AUTO_INCREMENT, `id_log` INT(10) DEFAULT 0, - `id_shop` INT(10) DEFAULT ' . Configuration::get('PS_SHOP_DEFAULT') . ', + `id_shop` INT(10) DEFAULT ' . (int) Configuration::get('PS_SHOP_DEFAULT') . ', `message` TEXT DEFAULT NULL, `request` MEDIUMTEXT DEFAULT NULL, `response` MEDIUMTEXT DEFAULT NULL, From ce41823c8b34b571078fad3e995ed25f64bf3129 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 13:38:17 +0300 Subject: [PATCH 36/90] [SV-33] cast --- upgrade/install-1.2.4.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upgrade/install-1.2.4.php b/upgrade/install-1.2.4.php index 9a268518..ef32a6f3 100644 --- a/upgrade/install-1.2.4.php +++ b/upgrade/install-1.2.4.php @@ -33,7 +33,7 @@ function upgrade_module_1_2_4(SaferPayOfficial $module) return Db::getInstance()->execute( 'ALTER TABLE ' . _DB_PREFIX_ . pSQL(SaferPayLog::$definition['table']) . ' ADD COLUMN `id_log` INT(10) DEFAULT 0, - ADD COLUMN `id_shop` INT(10) DEFAULT ' . Configuration::get('PS_SHOP_DEFAULT') . ', + ADD COLUMN `id_shop` INT(10) DEFAULT ' . (int) Configuration::get('PS_SHOP_DEFAULT') . ', CHANGE `payload` `request` TEXT, ADD COLUMN `response` MEDIUMTEXT DEFAULT NULL, ADD COLUMN `context` MEDIUMTEXT DEFAULT NULL, From d063401787af0de01a4b2f57fe2fec739dfd2e5c Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 13:39:43 +0300 Subject: [PATCH 37/90] [SV-33] removed classes --- upgrade/install-1.2.4.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/upgrade/install-1.2.4.php b/upgrade/install-1.2.4.php index ef32a6f3..066f249b 100644 --- a/upgrade/install-1.2.4.php +++ b/upgrade/install-1.2.4.php @@ -21,9 +21,6 @@ *@license SIX Payment Services */ -use Invertus\SaferPay\Config\SaferPayConfig; -use Invertus\SaferPay\DTO\Request\RequestHeader; - if (!defined('_PS_VERSION_')) { exit; } From 6910eecc3e95cbc921141e54b39bbd40389cdd53 Mon Sep 17 00:00:00 2001 From: Marijus <106698165+MarijusCoding@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:15:41 +0300 Subject: [PATCH 38/90] Update composer.json Co-authored-by: Gytautas Zumaras <96050852+GytisZum@users.noreply.github.com> --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8f43ad93..7f887c40 100755 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "type": "vcs", "url": "https://github.com/Invertus/Knapsack.git" }, - "0": { + "lock": { "type": "vcs", "url": "https://github.com/Invertus/lock.git", "no-api": true From 7ba3bdec715c2d60207bda5952701b0ad19d4e99 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 14:16:56 +0300 Subject: [PATCH 39/90] [SV-33] fixed db --- upgrade/install-1.2.4.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upgrade/install-1.2.4.php b/upgrade/install-1.2.4.php index 066f249b..e3ced5e0 100644 --- a/upgrade/install-1.2.4.php +++ b/upgrade/install-1.2.4.php @@ -35,7 +35,7 @@ function upgrade_module_1_2_4(SaferPayOfficial $module) ADD COLUMN `response` MEDIUMTEXT DEFAULT NULL, ADD COLUMN `context` MEDIUMTEXT DEFAULT NULL, DROP PRIMARY KEY, - ADD PRIMARY KEY (`id_log`, `id_shop`), + PRIMARY KEY (`id_saferpay_log`, `id_log`, `id_shop`), ADD INDEX (`id_log`),' ); } From 0bcee4bc39bb59c7e2292a96945c1260fa3816c7 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 17:15:09 +0300 Subject: [PATCH 40/90] [SV-34] added entity items and shown log --- controllers/admin/AdminSaferPayOfficialLogsController.php | 4 ---- src/Entity/SaferPayLog.php | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 25c41726..19d9a9a4 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -244,9 +244,6 @@ public function displayAjaxGetLog() /** @var SaferPayLogRepository $logRepository */ $logRepository = $this->module->getService(SaferPayLogRepositoryInterface::class); - /** @var GlobalShopContext $shopContext */ - $shopContext = $this->module->getService(GlobalShopContext::class); - $logId = $tools->getValueAsInt('log_id'); // /** @var LoggerInterface $logger */ @@ -287,7 +284,6 @@ public function displayAjaxGetLog() 'message' => $this->module->l('No log information found.', self::FILE_NAME), ])); } - $this->ajaxRender($log); $this->ajaxResponse(json_encode([ 'error' => false, diff --git a/src/Entity/SaferPayLog.php b/src/Entity/SaferPayLog.php index 10069edd..7cc44fff 100755 --- a/src/Entity/SaferPayLog.php +++ b/src/Entity/SaferPayLog.php @@ -35,7 +35,9 @@ class SaferPayLog extends ObjectModel public $message; - public $payload; + public $request; + + public $response; public $context; From bb52eb961299f46c6f9fae943fed51ae02d114fe Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 17:31:09 +0300 Subject: [PATCH 41/90] [SV-34] fixed GlobalShopContext --- .../admin/AdminSaferPayOfficialLogsController.php | 13 ++++++------- src/ServiceProvider/BaseServiceProvider.php | 2 ++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 19d9a9a4..dd7f7a54 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -22,15 +22,11 @@ */ use Invertus\SaferPay\Config\SaferPayConfig; -use Invertus\Saferpay\Context\GlobalShopContext; -use Invertus\Saferpay\Context\GlobalShopContextInterface; use Invertus\SaferPay\Controller\AbstractAdminSaferPayController; use Invertus\SaferPay\Enum\PermissionType; use Invertus\SaferPay\Logger\Formatter\LogFormatter; -use Invertus\SaferPay\Repository\SaferPayLogRepository; use Invertus\SaferPay\Utility\VersionUtility; use Invertus\SaferPay\Logger\Logger; -use Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface; if (!defined('_PS_VERSION_')) { exit; @@ -241,8 +237,11 @@ public function displayAjaxGetLog() /** @var \Invertus\SaferPay\Adapter\Tools $tools */ $tools = $this->module->getService(\Invertus\SaferPay\Adapter\Tools::class); - /** @var SaferPayLogRepository $logRepository */ - $logRepository = $this->module->getService(SaferPayLogRepositoryInterface::class); + /** @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); $logId = $tools->getValueAsInt('log_id'); @@ -253,7 +252,7 @@ public function displayAjaxGetLog() /** @var \SaferPayLog|null $log */ $log = $logRepository->findOneBy([ 'id_log' => $logId, - 'id_shop' => Context::getContext()->shop->id, + 'id_shop' => $globalShopContext->getShopId(), ]); } catch (Exception $exception) { // $logger->error('Failed to find log', [ diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index 5b600aa3..922b7419 100755 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -23,12 +23,14 @@ namespace Invertus\SaferPay\ServiceProvider; +use Invertus\Saferpay\Context\GlobalShopContextInterface; use Invertus\SaferPay\Provider\BasicIdempotencyProvider; use Invertus\SaferPay\Provider\IdempotencyProviderInterface; use Invertus\SaferPay\Repository\OrderRepository; use Invertus\SaferPay\Repository\OrderRepositoryInterface; use Invertus\SaferPay\Repository\SaferPayLogRepository; use Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface; +use KlarnaPayment\Module\Infrastructure\Context\GlobalShopContext; use League\Container\Container; if (!defined('_PS_VERSION_')) { From ff085ae6293716fdfe65806a624060f5f146391d Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 17:50:08 +0300 Subject: [PATCH 42/90] [SV-34] added custom export --- .../AdminSaferPayOfficialLogsController.php | 97 +++++++++++++++++++ src/Adapter/LegacyContext.php | 58 +++++++++++ 2 files changed, 155 insertions(+) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index dd7f7a54..bfa94924 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -293,4 +293,101 @@ public function displayAjaxGetLog() ], ])); } + + public function processExport($textDelimiter = '"') + { + // clean buffer + if (ob_get_level() && ob_get_length() > 0) { + ob_clean(); + } + + header('Content-type: text/csv'); + header('Content-Type: application/force-download; charset=UTF-8'); + header('Cache-Control: no-store, no-cache'); + header('Content-disposition: attachment; filename="' . $this->table . '_' . date('Y-m-d_His') . '.csv"'); + + $fd = fopen('php://output', 'wb'); + + /** @var Configuration $configuration */ + $configuration = $this->module->getService(Configuration::class); + + /** @var \Invertus\SaferPay\Adapter\LegacyContext $context */ + $context = $this->module->getService(\Invertus\SaferPay\Adapter\LegacyContext::class); + + $storeInfo = [ + 'PrestaShop Version' => _PS_VERSION_, + 'PHP Version' => phpversion(), + 'Module Version' => $this->module->version, + 'MySQL Version' => \Db::getInstance()->getVersion(), + 'Shop URL' => $context->getShopDomain(), + 'Shop Name' => $context->getShopName(), + ]; + + $moduleConfigurations = [ + 'Test mode' => SaferPayConfig::isTestMode() ? 'Yes' : 'No', + ]; + + $psSettings = [ + 'Default country' => $configuration->get('PS_COUNTRY_DEFAULT'), + 'Default currency' => $configuration->get('PS_CURRENCY_DEFAULT'), + 'Default language' => $configuration->get('PS_LANG_DEFAULT'), + 'Round mode' => $configuration->get('PS_PRICE_ROUND_MODE'), + 'Round type' => $configuration->get('PS_ROUND_TYPE'), + 'Current theme name' => $context->getShopThemeName(), + 'PHP memory limit' => ini_get('memory_limit'), + ]; + + $moduleConfigurationsInfo = "**Module configurations:**\n"; + foreach ($moduleConfigurations as $key => $value) { + $moduleConfigurationsInfo .= "- $key: $value\n"; + } + + $psSettingsInfo = "**Prestashop settings:**\n"; + foreach ($psSettings as $key => $value) { + $psSettingsInfo .= "- $key: $value\n"; + } + + fputcsv($fd, array_keys($storeInfo), ';', $textDelimiter); + fputcsv($fd, $storeInfo, ';', $textDelimiter); + fputcsv($fd, [], ';', $textDelimiter); + + fputcsv($fd, [$moduleConfigurationsInfo], ';', $textDelimiter); + fputcsv($fd, [$psSettingsInfo], ';', $textDelimiter); + + $query = new \DbQuery(); + + $query + ->select('spl.id_log, l.severity, l.message, spl.request, spl.response, spl.context, spl.date_add') + ->from('saferpay_log', 'spl') + ->leftJoin('log', 'l', 'spl.id_log = l.id_log') + ->orderBy('spl.id_log DESC') + ->limit(1000); + + $result = \Db::getInstance()->executeS($query); + + $firstRow = $result[0]; + $headers = []; + + foreach ($firstRow as $key => $value) { + $headers[] = strtoupper($key); + } + + $fd = fopen('php://output', 'wb'); + + fputcsv($fd, $headers, ';', $textDelimiter); + + $content = !empty($result) ? $result : []; + + foreach ($content as $row) { + $rowValues = []; + foreach ($row as $key => $value) { + $rowValues[] = $value; + } + + fputcsv($fd, $rowValues, ';', $textDelimiter); + } + + @fclose($fd); + die; + } } diff --git a/src/Adapter/LegacyContext.php b/src/Adapter/LegacyContext.php index ffa80be1..4afc02a1 100755 --- a/src/Adapter/LegacyContext.php +++ b/src/Adapter/LegacyContext.php @@ -159,4 +159,62 @@ public function getShopName() { return (string) $this->getContext()->shop->name; } + + public function getController() + { + return $this->getContext()->controller; + } + + /** + * @throws \Throwable + */ + public function setCurrentCart(\Cart $cart) + { + $this->getContext()->cart = $cart; + $this->getContext()->cart->update(); + + $this->getContext()->cookie->__set('id_cart', (int) $cart->id); + $this->getContext()->cookie->write(); + } + + public function setCountry(\Country $country) + { + $this->getContext()->country = $country; + } + + public function setCurrency(\Currency $currency) + { + $this->getContext()->currency = $currency; + } + + public function getBaseLink(int $shopId = null, bool $ssl = null) + { + return (string) $this->getContext()->link->getBaseLink($shopId, $ssl); + } + + public function getCartProducts() + { + $cart = $this->getContext()->cart; + + if (!$cart) { + return []; + } + + return $cart->getProducts(); + } + + public function getCart() + { + return $this->getContext()->cart ?? null; + } + + public function getShopThemeName() + { + return $this->getContext()->shop->theme_name; + } + + public function updateCustomer(\Customer $customer) + { + $this->getContext()->updateCustomer($customer); + } } From 0ff5d0ded8ff7f8796d066ebc30415bbf4118346 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 18:02:45 +0300 Subject: [PATCH 43/90] [SV-34] removed types --- .../admin/AdminSaferPayOfficialLogsController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index bfa94924..7f2dbb2b 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -164,7 +164,7 @@ public function displaySeverityInformation() ); } - public function printSeverityLevel(int $level) + public function printSeverityLevel($level) { $this->context->smarty->assign([ 'log_severity_level' => $level, @@ -187,7 +187,7 @@ public function printSeverityLevel(int $level) ); } - public function getDisplayButton(int $logId, string $data, string $logInformationType) + public function getDisplayButton($logId, $data, $logInformationType) { $unserializedData = json_decode($data); @@ -213,17 +213,17 @@ public function getDisplayButton(int $logId, string $data, string $logInformatio * * @throws SmartyException */ - public function printRequestButton(string $request, array $data) + public function printRequestButton($request, $data) { return $this->getDisplayButton($data['id_log'], $request, self::LOG_INFORMATION_TYPE_REQUEST); } - public function printResponseButton(string $response, array $data) + public function printResponseButton($response, $data) { return $this->getDisplayButton($data['id_log'], $response, self::LOG_INFORMATION_TYPE_RESPONSE); } - public function printContextButton(string $context, array $data) + public function printContextButton($context, $data) { return $this->getDisplayButton($data['id_log'], $context, self::LOG_INFORMATION_TYPE_CONTEXT); } From db181fdf09f302890b814118591a8e998cd564af Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Wed, 2 Oct 2024 18:07:27 +0300 Subject: [PATCH 44/90] [SV-34] whitespaces --- controllers/admin/AdminSaferPayOfficialLogsController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php index 7f2dbb2b..228a50ab 100755 --- a/controllers/admin/AdminSaferPayOfficialLogsController.php +++ b/controllers/admin/AdminSaferPayOfficialLogsController.php @@ -35,8 +35,11 @@ class AdminSaferPayOfficialLogsController extends AbstractAdminSaferPayController { const FILE_NAME = 'AdminSaferPayOfficialLogsController'; + const LOG_INFORMATION_TYPE_REQUEST = 'request'; + const LOG_INFORMATION_TYPE_RESPONSE = 'response'; + const LOG_INFORMATION_TYPE_CONTEXT = 'context'; public function __construct() @@ -51,6 +54,7 @@ public function __construct() parent::__construct(); $this->toolbar_btn = []; + $this->initList(); $this->_select .= ' @@ -138,6 +142,7 @@ public function initList() public function renderList() { unset($this->toolbar_btn['new']); + return parent::renderList(); } From c016a04796a26f31ae18b8f504f79d966b02416c Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 11:15:54 +0300 Subject: [PATCH 45/90] [SV-34] types, klarna --- src/Config/SaferPayConfig.php | 12 ++++----- src/Context/GlobalShopContext.php | 22 +++++++++++----- .../AbstractAdminSaferPayController.php | 26 +++++++++++++------ src/Enum/PermissionType.php | 26 +++++++++++++------ src/Logger/Formatter/LogFormatter.php | 2 +- .../Formatter/LogFormatterInterface.php | 2 +- src/Repository/CollectionRepository.php | 4 +-- .../ReadOnlyCollectionRepositoryInterface.php | 2 +- src/Repository/SaferPayLogRepository.php | 4 +-- .../SaferPayLogRepositoryInterface.php | 2 +- src/Response/JsonResponse.php | 6 ++--- src/ServiceProvider/BaseServiceProvider.php | 2 -- src/Utility/ExceptionUtility.php | 4 +-- src/Utility/VersionUtility.php | 12 ++++----- .../admin/logs/severity_level_column.tpl | 8 +++--- .../templates/admin/logs/severity_levels.tpl | 12 ++++----- 16 files changed, 86 insertions(+), 60 deletions(-) diff --git a/src/Config/SaferPayConfig.php b/src/Config/SaferPayConfig.php index fd84f2df..cb8997a6 100755 --- a/src/Config/SaferPayConfig.php +++ b/src/Config/SaferPayConfig.php @@ -266,15 +266,15 @@ class SaferPayConfig const SAFERPAY_CARDFORM_HOLDERNAME_REQUIRENCE = 'MANDATORY'; const SAFERPAY_DEBUG_MODE = 'SAFERPAY_DEBUG_MODE'; - public const LOG_SEVERITY_LEVEL_INFORMATIVE = 1; + const LOG_SEVERITY_LEVEL_INFORMATIVE = 1; - public const LOG_SEVERITY_LEVEL_WARNING = 2; + const LOG_SEVERITY_LEVEL_WARNING = 2; - public const LOG_SEVERITY_LEVEL_ERROR = 3; + const LOG_SEVERITY_LEVEL_ERROR = 3; - public const LOG_SEVERITY_LEVEL_MAJOR = 4; + const LOG_SEVERITY_LEVEL_MAJOR = 4; - public static function supportsOrderCapture(string $paymentMethod) + public static function supportsOrderCapture($paymentMethod) { //payments that DOES NOT SUPPORT capture $unsupportedCapturePayments = [ @@ -285,7 +285,7 @@ public static function supportsOrderCapture(string $paymentMethod) return !in_array($paymentMethod, $unsupportedCapturePayments); } - public static function supportsOrderCancel(string $paymentMethod) + public static function supportsOrderCancel($paymentMethod) { //payments that DOES NOT SUPPORT order cancel $unsupportedCancelPayments = [ diff --git a/src/Context/GlobalShopContext.php b/src/Context/GlobalShopContext.php index 751403a9..4de1cc4d 100644 --- a/src/Context/GlobalShopContext.php +++ b/src/Context/GlobalShopContext.php @@ -1,14 +1,24 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services */ namespace Invertus\Saferpay\Context; diff --git a/src/Controller/AbstractAdminSaferPayController.php b/src/Controller/AbstractAdminSaferPayController.php index 9d634766..44a734a4 100644 --- a/src/Controller/AbstractAdminSaferPayController.php +++ b/src/Controller/AbstractAdminSaferPayController.php @@ -1,14 +1,24 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services */ namespace Invertus\SaferPay\Controller; @@ -19,7 +29,7 @@ class AbstractAdminSaferPayController extends \ModuleAdminController { const FILE_NAME = 'AbstractAdminSaferPayController'; - protected function ajaxResponse($value = null, $controller = null, $method = null): void + protected function ajaxResponse($value = null, $controller = null, $method = null) { // /** @var LoggerInterface $logger */ // $logger = $this->module->getService(LoggerInterface::class); @@ -58,7 +68,7 @@ protected function ajaxResponse($value = null, $controller = null, $method = nul exit; } - public function ensureHasPermissions(array $permissions, bool $ajax = false): bool + public function ensureHasPermissions($permissions, $ajax = false) { foreach ($permissions as $permission) { if (!$this->access($permission)) { diff --git a/src/Enum/PermissionType.php b/src/Enum/PermissionType.php index 4bbfdb88..20a958e0 100644 --- a/src/Enum/PermissionType.php +++ b/src/Enum/PermissionType.php @@ -1,14 +1,24 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services */ namespace Invertus\SaferPay\Enum; @@ -19,6 +29,6 @@ class PermissionType { - public const VIEW = 'view'; - public const EDIT = 'edit'; + const VIEW = 'view'; + const EDIT = 'edit'; } \ No newline at end of file diff --git a/src/Logger/Formatter/LogFormatter.php b/src/Logger/Formatter/LogFormatter.php index dbee9e23..ea19716f 100644 --- a/src/Logger/Formatter/LogFormatter.php +++ b/src/Logger/Formatter/LogFormatter.php @@ -31,7 +31,7 @@ class LogFormatter implements LogFormatterInterface { const SAFERPAY_LOG_PREFIX = 'SAFERPAY_MODULE_LOG:'; - public function getMessage(string $message): string + public function getMessage($message) { return self::SAFERPAY_LOG_PREFIX . ' ' . $message; } diff --git a/src/Logger/Formatter/LogFormatterInterface.php b/src/Logger/Formatter/LogFormatterInterface.php index 6e6e5a57..f3926d67 100644 --- a/src/Logger/Formatter/LogFormatterInterface.php +++ b/src/Logger/Formatter/LogFormatterInterface.php @@ -34,5 +34,5 @@ interface LogFormatterInterface * * @return string */ - public function getMessage(string $message): string; + public function getMessage($message); } \ No newline at end of file diff --git a/src/Repository/CollectionRepository.php b/src/Repository/CollectionRepository.php index e695b644..53fab7f8 100644 --- a/src/Repository/CollectionRepository.php +++ b/src/Repository/CollectionRepository.php @@ -34,7 +34,7 @@ class CollectionRepository implements ReadOnlyCollectionRepositoryInterface */ private $fullyClassifiedClassName; - public function __construct(string $fullyClassifiedClassName) + public function __construct($fullyClassifiedClassName) { $this->fullyClassifiedClassName = $fullyClassifiedClassName; } @@ -52,7 +52,7 @@ public function findAllInCollection($langId = null) * * @throws \PrestaShopException */ - public function findOneBy(array $keyValueCriteria, $langId = null) + public function findOneBy($keyValueCriteria, $langId = null) { $psCollection = new \PrestaShopCollection($this->fullyClassifiedClassName, $langId); diff --git a/src/Repository/ReadOnlyCollectionRepositoryInterface.php b/src/Repository/ReadOnlyCollectionRepositoryInterface.php index 357a1704..fd8e91f5 100644 --- a/src/Repository/ReadOnlyCollectionRepositoryInterface.php +++ b/src/Repository/ReadOnlyCollectionRepositoryInterface.php @@ -46,5 +46,5 @@ public function findAllInCollection($langId = null); * * @return \ObjectModel|null */ - public function findOneBy(array $keyValueCriteria, $langId = null); + public function findOneBy($keyValueCriteria, $langId = null); } \ No newline at end of file diff --git a/src/Repository/SaferPayLogRepository.php b/src/Repository/SaferPayLogRepository.php index 79589b33..6036db5c 100644 --- a/src/Repository/SaferPayLogRepository.php +++ b/src/Repository/SaferPayLogRepository.php @@ -24,8 +24,6 @@ namespace Invertus\SaferPay\Repository; use Invertus\Knapsack\Collection; -use Invertus\SaferPay\Repository\CollectionRepository; -use Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface; if (!defined('_PS_VERSION_')) { exit; @@ -38,7 +36,7 @@ public function __construct() parent::__construct(\SaferPayLog::class); } - public function prune(int $daysToKeep) + public function prune($daysToKeep) { Collection::from( $this->findAllInCollection() diff --git a/src/Repository/SaferPayLogRepositoryInterface.php b/src/Repository/SaferPayLogRepositoryInterface.php index 5b7b38c0..38052f3f 100644 --- a/src/Repository/SaferPayLogRepositoryInterface.php +++ b/src/Repository/SaferPayLogRepositoryInterface.php @@ -31,5 +31,5 @@ interface SaferPayLogRepositoryInterface extends ReadOnlyCollectionRepositoryInterface { - public function prune(int $daysToKeep); + public function prune($daysToKeep); } \ No newline at end of file diff --git a/src/Response/JsonResponse.php b/src/Response/JsonResponse.php index ada9a1e2..9dbb60af 100644 --- a/src/Response/JsonResponse.php +++ b/src/Response/JsonResponse.php @@ -34,12 +34,12 @@ class JsonResponse extends BaseJsonResponse /** * @param mixed $data */ - public function __construct($data = null, int $status = 200, array $headers = []) + public function __construct($data = null, $status = 200, $headers = []) { parent::__construct($data, $status, $headers); } - public static function success(array $data, int $status = 200): self + public static function success($data, $status = 200) { return new self([ 'success' => true, @@ -54,7 +54,7 @@ public static function success(array $data, int $status = 200): self * * @return static */ - public static function error($error, int $status = 400): self + public static function error($error, $status = 400) { if ($status === JsonResponse::HTTP_UNPROCESSABLE_ENTITY) { // NOTE: removing rule name. ['required' => 'message'] becomes [0 => 'message'] diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php index 922b7419..5b600aa3 100755 --- a/src/ServiceProvider/BaseServiceProvider.php +++ b/src/ServiceProvider/BaseServiceProvider.php @@ -23,14 +23,12 @@ namespace Invertus\SaferPay\ServiceProvider; -use Invertus\Saferpay\Context\GlobalShopContextInterface; use Invertus\SaferPay\Provider\BasicIdempotencyProvider; use Invertus\SaferPay\Provider\IdempotencyProviderInterface; use Invertus\SaferPay\Repository\OrderRepository; use Invertus\SaferPay\Repository\OrderRepositoryInterface; use Invertus\SaferPay\Repository\SaferPayLogRepository; use Invertus\SaferPay\Repository\SaferPayLogRepositoryInterface; -use KlarnaPayment\Module\Infrastructure\Context\GlobalShopContext; use League\Container\Container; if (!defined('_PS_VERSION_')) { diff --git a/src/Utility/ExceptionUtility.php b/src/Utility/ExceptionUtility.php index 52361fca..f6366f1a 100644 --- a/src/Utility/ExceptionUtility.php +++ b/src/Utility/ExceptionUtility.php @@ -29,7 +29,7 @@ class ExceptionUtility { - public static function getExceptions(\Throwable $exception) + public static function getExceptions($exception) { if (method_exists($exception, 'getExceptions')) { return $exception->getExceptions(); @@ -38,7 +38,7 @@ public static function getExceptions(\Throwable $exception) return [self::toArray($exception)]; } - public static function toArray(\Throwable $exception): array + public static function toArray( $exception) { if (method_exists($exception, 'getContext')) { $context = $exception->getContext(); diff --git a/src/Utility/VersionUtility.php b/src/Utility/VersionUtility.php index 8f076e6a..d19b7ac7 100644 --- a/src/Utility/VersionUtility.php +++ b/src/Utility/VersionUtility.php @@ -29,32 +29,32 @@ class VersionUtility { - public static function isPsVersionLessThan($version): ?int + public static function isPsVersionLessThan($version) { return version_compare(_PS_VERSION_, $version, '<'); } - public static function isPsVersionGreaterThan($version): ?int + public static function isPsVersionGreaterThan($version) { return version_compare(_PS_VERSION_, $version, '>'); } - public static function isPsVersionGreaterOrEqualTo($version): ?int + public static function isPsVersionGreaterOrEqualTo($version) { return version_compare(_PS_VERSION_, $version, '>='); } - public static function isPsVersionLessThanOrEqualTo($version): ?int + public static function isPsVersionLessThanOrEqualTo($version) { return version_compare(_PS_VERSION_, $version, '<='); } - public static function isPsVersionEqualTo($version): ?int + public static function isPsVersionEqualTo($version) { return version_compare(_PS_VERSION_, $version, '='); } - public static function current(): string + public static function current() { return _PS_VERSION_; } diff --git a/views/templates/admin/logs/severity_level_column.tpl b/views/templates/admin/logs/severity_level_column.tpl index 10f94f44..1629dc07 100644 --- a/views/templates/admin/logs/severity_level_column.tpl +++ b/views/templates/admin/logs/severity_level_column.tpl @@ -20,13 +20,13 @@ *@license SIX Payment Services *} {if $log_severity_level == $log_severity_level_informative} - {l s='Informative only' mod='klarnapayment'} ({$log_severity_level|intval}) + {l s='Informative only' mod='saferpayofficial'} ({$log_severity_level|intval}) {elseif $log_severity_level == $log_severity_level_warning} - {l s='Warning' mod='klarnapayment'} ({$log_severity_level|intval}) + {l s='Warning' mod='saferpayofficial'} ({$log_severity_level|intval}) {elseif $log_severity_level == $log_severity_level_error} - {l s='Error' mod='klarnapayment'} ({$log_severity_level|intval}) + {l s='Error' mod='saferpayofficial'} ({$log_severity_level|intval}) {elseif $log_severity_level == $log_severity_level_major} - {l s='Major issue (crash)!' mod='klarnapayment'} ({$log_severity_level|intval}) + {l s='Major issue (crash)!' mod='saferpayofficial'} ({$log_severity_level|intval}) {else} {$log_severity_level|escape:'htmlall':'UTF-8'} {/if} \ No newline at end of file diff --git a/views/templates/admin/logs/severity_levels.tpl b/views/templates/admin/logs/severity_levels.tpl index 13eb624a..c6ab90fa 100644 --- a/views/templates/admin/logs/severity_levels.tpl +++ b/views/templates/admin/logs/severity_levels.tpl @@ -22,13 +22,13 @@

- {l s='Severity levels:' mod='klarnapayment'} + {l s='Severity levels:' mod='saferpayofficial'}

-

{l s='Meaning of severity levels:' mod='klarnapayment'}

+

{l s='Meaning of severity levels:' mod='saferpayofficial'}

    -
  1. {l s='Info' mod='klarnapayment'}
  2. -
  3. {l s='Warning' mod='klarnapayment'}
  4. -
  5. {l s='Error' mod='klarnapayment'}
  6. -
  7. {l s='Fatal' mod='klarnapayment'}
  8. +
  9. {l s='Info' mod='saferpayofficial'}
  10. +
  11. {l s='Warning' mod='saferpayofficial'}
  12. +
  13. {l s='Error' mod='saferpayofficial'}
  14. +
  15. {l s='Fatal' mod='saferpayofficial'}
\ No newline at end of file From f7584af33599344c67c2521b666494000aa1a7d4 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 11:17:43 +0300 Subject: [PATCH 46/90] [SV-34] types --- src/Adapter/Tools.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Adapter/Tools.php b/src/Adapter/Tools.php index e5bd24d1..0e36a4cd 100644 --- a/src/Adapter/Tools.php +++ b/src/Adapter/Tools.php @@ -32,42 +32,42 @@ class Tools { - public function linkRewrite(string $str): string + public function linkRewrite($str) { return PrestashopTools::str2url($str); } - public function redirectAdmin(string $controller): void + public function redirectAdmin($controller) { PrestashopTools::redirectAdmin($controller); } - public function redirect(string $url): void + public function redirect($url) { PrestashopTools::redirect($url); } - public function isSubmit(string $form): bool + public function isSubmit($form) { return PrestashopTools::isSubmit($form); } - public function strtoupper(string $string): string + public function strtoupper($string) { return PrestashopTools::strtoupper($string); } - public function strtolower(string $string): string + public function strtolower($string) { return PrestashopTools::strtolower($string); } - public function encrypt(string $string): string + public function encrypt($string) { return PrestashopTools::encrypt($string); } - public function passwdGen(int $length = 8, string $flag = 'ALPHANUMERIC'): string + public function passwdGen($length = 8, $flag = 'ALPHANUMERIC') { return PrestashopTools::passwdGen($length, $flag); } From 4bad4f258ed6c217504137cf9a50912e57aa28fc Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 11:34:12 +0300 Subject: [PATCH 47/90] [SV-34] types --- src/Adapter/LegacyContext.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Adapter/LegacyContext.php b/src/Adapter/LegacyContext.php index 4afc02a1..d2265259 100755 --- a/src/Adapter/LegacyContext.php +++ b/src/Adapter/LegacyContext.php @@ -89,7 +89,7 @@ public function getDeviceDetect() return (int) $this->getContext()->getDevice(); } - public function getAdminLink($controllerName, array $params = []) + public function getAdminLink($controllerName, $params = []) { /* @noinspection PhpMethodParametersCountMismatchInspection - its valid for PS1.7 */ return (string) Context::getContext()->link->getAdminLink($controllerName, true, [], $params); @@ -187,7 +187,7 @@ public function setCurrency(\Currency $currency) $this->getContext()->currency = $currency; } - public function getBaseLink(int $shopId = null, bool $ssl = null) + public function getBaseLink($shopId = null, $ssl = null) { return (string) $this->getContext()->link->getBaseLink($shopId, $ssl); } @@ -205,7 +205,7 @@ public function getCartProducts() public function getCart() { - return $this->getContext()->cart ?? null; + return isset($this->getContext()->cart) ? $this->getContext()->cart : null; } public function getShopThemeName() From fe8c910714ebb2eb7e0ae7aff12675e8e994f914 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 11:38:48 +0300 Subject: [PATCH 48/90] [SV-34] types --- src/Adapter/LegacyContext.php | 2 +- src/Repository/CollectionRepository.php | 2 +- src/Repository/ReadOnlyCollectionRepositoryInterface.php | 2 +- src/Response/JsonResponse.php | 2 +- src/Utility/ExceptionUtility.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Adapter/LegacyContext.php b/src/Adapter/LegacyContext.php index d2265259..91434eec 100755 --- a/src/Adapter/LegacyContext.php +++ b/src/Adapter/LegacyContext.php @@ -89,7 +89,7 @@ public function getDeviceDetect() return (int) $this->getContext()->getDevice(); } - public function getAdminLink($controllerName, $params = []) + public function getAdminLink($controllerName, array $params = []) { /* @noinspection PhpMethodParametersCountMismatchInspection - its valid for PS1.7 */ return (string) Context::getContext()->link->getAdminLink($controllerName, true, [], $params); diff --git a/src/Repository/CollectionRepository.php b/src/Repository/CollectionRepository.php index 53fab7f8..7ea712d8 100644 --- a/src/Repository/CollectionRepository.php +++ b/src/Repository/CollectionRepository.php @@ -52,7 +52,7 @@ public function findAllInCollection($langId = null) * * @throws \PrestaShopException */ - public function findOneBy($keyValueCriteria, $langId = null) + public function findOneBy(array $keyValueCriteria, $langId = null) { $psCollection = new \PrestaShopCollection($this->fullyClassifiedClassName, $langId); diff --git a/src/Repository/ReadOnlyCollectionRepositoryInterface.php b/src/Repository/ReadOnlyCollectionRepositoryInterface.php index fd8e91f5..357a1704 100644 --- a/src/Repository/ReadOnlyCollectionRepositoryInterface.php +++ b/src/Repository/ReadOnlyCollectionRepositoryInterface.php @@ -46,5 +46,5 @@ public function findAllInCollection($langId = null); * * @return \ObjectModel|null */ - public function findOneBy($keyValueCriteria, $langId = null); + public function findOneBy(array $keyValueCriteria, $langId = null); } \ No newline at end of file diff --git a/src/Response/JsonResponse.php b/src/Response/JsonResponse.php index 9dbb60af..28936f9f 100644 --- a/src/Response/JsonResponse.php +++ b/src/Response/JsonResponse.php @@ -34,7 +34,7 @@ class JsonResponse extends BaseJsonResponse /** * @param mixed $data */ - public function __construct($data = null, $status = 200, $headers = []) + public function __construct($data = null, $status = 200, array $headers = []) { parent::__construct($data, $status, $headers); } diff --git a/src/Utility/ExceptionUtility.php b/src/Utility/ExceptionUtility.php index f6366f1a..2ee3495c 100644 --- a/src/Utility/ExceptionUtility.php +++ b/src/Utility/ExceptionUtility.php @@ -38,7 +38,7 @@ public static function getExceptions($exception) return [self::toArray($exception)]; } - public static function toArray( $exception) + public static function toArray($exception) { if (method_exists($exception, 'getContext')) { $context = $exception->getContext(); From ac197de33ace950f93de2aca3796618262c3edce Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 13:43:33 +0300 Subject: [PATCH 49/90] [SV-34] fix --- src/Controller/AbstractAdminSaferPayController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controller/AbstractAdminSaferPayController.php b/src/Controller/AbstractAdminSaferPayController.php index 44a734a4..fa329160 100644 --- a/src/Controller/AbstractAdminSaferPayController.php +++ b/src/Controller/AbstractAdminSaferPayController.php @@ -35,13 +35,13 @@ protected function ajaxResponse($value = null, $controller = null, $method = nul // $logger = $this->module->getService(LoggerInterface::class); if ($value instanceof JsonResponse) { - if ($value->getStatusCode() === JsonResponse::HTTP_INTERNAL_SERVER_ERROR) { +// if ($value->getStatusCode() === JsonResponse::HTTP_INTERNAL_SERVER_ERROR) { // $logger->error('Failed to return valid response', [ // 'context' => [ // 'response' => $value->getContent(), // ], // ]); - } +// } http_response_code($value->getStatusCode()); From d526b75d7f9876f0fff9dc7c455caa15a0c7a1d6 Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 13:45:47 +0300 Subject: [PATCH 50/90] csfixer --- ...dminSaferPayOfficialSettingsController.php | 2 +- controllers/front/ajax.php | 4 +-- controllers/front/iframe.php | 1 - controllers/front/notify.php | 8 ++--- controllers/front/return.php | 5 ++- controllers/front/successHosted.php | 3 -- controllers/front/successIFrame.php | 4 --- saferpayofficial.php | 4 +-- src/Adapter/Tools.php | 2 +- src/Api/Request/AssertService.php | 3 +- src/Context/GlobalShopContext.php | 2 +- .../AbstractAdminSaferPayController.php | 2 +- src/Controller/AbstractSaferPayController.php | 1 - src/Controller/Front/index.php | 2 +- .../Order/Action/UpdateOrderStatusAction.php | 1 - src/Core/Payment/DTO/CheckoutData.php | 34 +++++++++---------- src/Enum/PermissionType.php | 2 +- src/Exception/CouldNotProcessCheckout.php | 2 +- src/Exception/SaferPayException.php | 5 ++- src/Logger/Formatter/LogFormatter.php | 2 +- .../Formatter/LogFormatterInterface.php | 2 +- src/Logger/Logger.php | 2 +- src/Processor/CheckoutProcessor.php | 9 +++-- src/Processor/index.php | 2 +- src/Repository/CollectionRepository.php | 2 +- .../ReadOnlyCollectionRepositoryInterface.php | 2 +- src/Repository/SaferPayLogRepository.php | 2 +- .../SaferPayLogRepositoryInterface.php | 4 +-- .../InitializeRequestObjectCreator.php | 2 -- src/Service/SaferPayInitialize.php | 2 -- .../SaferPayTransactionAuthorization.php | 1 - upgrade/install-1.1.8.php | 2 +- upgrade/install-1.2.2.php | 1 - 33 files changed, 49 insertions(+), 73 deletions(-) diff --git a/controllers/admin/AdminSaferPayOfficialSettingsController.php b/controllers/admin/AdminSaferPayOfficialSettingsController.php index c8734fa7..421d6c12 100755 --- a/controllers/admin/AdminSaferPayOfficialSettingsController.php +++ b/controllers/admin/AdminSaferPayOfficialSettingsController.php @@ -400,7 +400,7 @@ private function displayConfigurationSettings() 'title' => $this->module->l('Description', self::FILE_NAME), 'type' => 'text', 'desc' => 'This description is visible in payment page also in payment confirmation email', - 'class' => 'fixed-width-xxl' + 'class' => 'fixed-width-xxl', ], SaferPayConfig::SAFERPAY_DEBUG_MODE => [ 'title' => $this->module->l('Debug mode', self::FILE_NAME), diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php index f221d68e..34a66a14 100755 --- a/controllers/front/ajax.php +++ b/controllers/front/ajax.php @@ -71,7 +71,7 @@ protected function processGetStatus() if (!$saferPayOrder->id || $saferPayOrder->canceled) { $this->ajaxDie(json_encode([ 'isFinished' => true, - 'href' => $this->getFailControllerLink($cartId, $secureKey, $moduleId) + 'href' => $this->getFailControllerLink($cartId, $secureKey, $moduleId), ])); } @@ -88,7 +88,7 @@ protected function processGetStatus() 'secureKey' => $secureKey, 'selectedCard' => $selectedCard, ] - ) + ), ])); } diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php index 7fb34709..262d30a3 100755 --- a/controllers/front/iframe.php +++ b/controllers/front/iframe.php @@ -98,7 +98,6 @@ public function initContent() ); $redirectUrl = $checkoutController->execute($checkoutData); - } catch (\Exception $exception) { $redirectUrl = $this->context->link->getModuleLink( $this->module->name, diff --git a/controllers/front/notify.php b/controllers/front/notify.php index d9fcaf5a..0155c521 100755 --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -201,7 +201,8 @@ public function postProcess() die($this->module->l('Success', self::FILENAME)); } - private function assertTransaction($cartId) { + private function assertTransaction($cartId) + { /** @var SaferPayTransactionAssertion $transactionAssert */ $transactionAssert = $this->module->getService(SaferPayTransactionAssertion::class); @@ -217,10 +218,9 @@ private function getOrderId($cartId) { if (method_exists('Order', 'getIdByCartId')) { return Order::getIdByCartId($cartId); - } else { - // For PrestaShop 1.6 use the alternative method - return Order::getOrderByCartId($cartId); } + // For PrestaShop 1.6 use the alternative method + return Order::getOrderByCartId($cartId); } protected function displayMaintenancePage() diff --git a/controllers/front/return.php b/controllers/front/return.php index 1ce79fd0..1378ea7f 100755 --- a/controllers/front/return.php +++ b/controllers/front/return.php @@ -184,9 +184,8 @@ private function getOrderId($cartId) { if (method_exists('Order', 'getIdByCartId')) { return Order::getIdByCartId($cartId); - } else { - // For PrestaShop 1.6 use the alternative method - return Order::getOrderByCartId($cartId); } + // For PrestaShop 1.6 use the alternative method + return Order::getOrderByCartId($cartId); } } diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php index 9998633d..63794782 100755 --- a/controllers/front/successHosted.php +++ b/controllers/front/successHosted.php @@ -21,12 +21,9 @@ *@license SIX Payment Services */ -use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; -use Invertus\SaferPay\Service\SaferPayOrderStatusService; -use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; if (!defined('_PS_VERSION_')) { exit; diff --git a/controllers/front/successIFrame.php b/controllers/front/successIFrame.php index a7ce3b5d..b7450363 100755 --- a/controllers/front/successIFrame.php +++ b/controllers/front/successIFrame.php @@ -21,13 +21,9 @@ *@license SIX Payment Services */ -use Invertus\SaferPay\Api\Enum\TransactionStatus; use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Controller\AbstractSaferPayController; use Invertus\SaferPay\Enum\ControllerName; -use Invertus\SaferPay\Exception\Api\SaferPayApiException; -use Invertus\SaferPay\Service\SaferPayOrderStatusService; -use Invertus\SaferPay\Service\TransactionFlow\SaferPayTransactionAuthorization; if (!defined('_PS_VERSION_')) { exit; diff --git a/saferpayofficial.php b/saferpayofficial.php index 4437fc62..e7f66add 100755 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -679,8 +679,8 @@ private function displayInAdminOrderPage(array $params) ); } else { $action = $this->context->link->getAdminLink( - self::ADMIN_ORDER_CONTROLLER - ) . '&id_order=' . (int) $orderId; + self::ADMIN_ORDER_CONTROLLER + ) . '&id_order=' . (int) $orderId; } $assertId = $orderRepo->getAssertIdBySaferPayOrderId($saferPayOrderId); diff --git a/src/Adapter/Tools.php b/src/Adapter/Tools.php index 0e36a4cd..0c2911b7 100644 --- a/src/Adapter/Tools.php +++ b/src/Adapter/Tools.php @@ -168,4 +168,4 @@ public function convertPriceFull($amount, \Currency $currency_from = null, \Curr { return PrestashopTools::convertPriceFull($amount, $currency_from, $currency_to); } -} \ No newline at end of file +} diff --git a/src/Api/Request/AssertService.php b/src/Api/Request/AssertService.php index d1297a41..fc0d2871 100755 --- a/src/Api/Request/AssertService.php +++ b/src/Api/Request/AssertService.php @@ -29,7 +29,6 @@ use Invertus\SaferPay\DTO\Response\Assert\AssertBody; use Invertus\SaferPay\EntityBuilder\SaferPayAssertBuilder; use Invertus\SaferPay\Exception\Api\SaferPayApiException; -use Invertus\SaferPay\Exception\Api\TransactionDeclinedException; use Invertus\SaferPay\Service\Response\AssertResponseObjectCreator; use SaferPayOrder; @@ -84,7 +83,7 @@ public function assert(AssertRequest $assertRequest, $saferPayOrderId) // also we call authorize method in some of the success controllers, so if we leave the logic here, // we get an error with TRANSACTION_IN_WRONG_STATE if ($saferPayOrder->is_transaction) { - $assertApi = self::ASSERT_API_TRANSACTION; + $assertApi = self::ASSERT_API_TRANSACTION; } try { diff --git a/src/Context/GlobalShopContext.php b/src/Context/GlobalShopContext.php index 4de1cc4d..8372078f 100644 --- a/src/Context/GlobalShopContext.php +++ b/src/Context/GlobalShopContext.php @@ -80,4 +80,4 @@ public function isShopSingleShopContext() { return \Shop::getContext() === \Shop::CONTEXT_SHOP; } -} \ No newline at end of file +} diff --git a/src/Controller/AbstractAdminSaferPayController.php b/src/Controller/AbstractAdminSaferPayController.php index fa329160..3c62d4d1 100644 --- a/src/Controller/AbstractAdminSaferPayController.php +++ b/src/Controller/AbstractAdminSaferPayController.php @@ -90,4 +90,4 @@ public function ensureHasPermissions($permissions, $ajax = false) return true; } -} \ No newline at end of file +} diff --git a/src/Controller/AbstractSaferPayController.php b/src/Controller/AbstractSaferPayController.php index cac8b4a2..f6bfc003 100755 --- a/src/Controller/AbstractSaferPayController.php +++ b/src/Controller/AbstractSaferPayController.php @@ -82,7 +82,6 @@ protected function applyLock($resource) $this->lock->create($resource); if (!$this->lock->acquire()) { - if (!SaferPayConfig::isVersion17()) { return http_response_code(409); } diff --git a/src/Controller/Front/index.php b/src/Controller/Front/index.php index 7487f261..6b778722 100644 --- a/src/Controller/Front/index.php +++ b/src/Controller/Front/index.php @@ -21,7 +21,7 @@ *@license SIX Payment Services */ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); +header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); diff --git a/src/Core/Order/Action/UpdateOrderStatusAction.php b/src/Core/Order/Action/UpdateOrderStatusAction.php index 000ce93b..983c5fcf 100644 --- a/src/Core/Order/Action/UpdateOrderStatusAction.php +++ b/src/Core/Order/Action/UpdateOrderStatusAction.php @@ -60,6 +60,5 @@ public function run($orderId, $orderStatusId) } catch (\Exception $exception) { throw CouldNotChangeOrderStatus::unknownError(); } - } } diff --git a/src/Core/Payment/DTO/CheckoutData.php b/src/Core/Payment/DTO/CheckoutData.php index 7a48165d..a5cf6336 100644 --- a/src/Core/Payment/DTO/CheckoutData.php +++ b/src/Core/Payment/DTO/CheckoutData.php @@ -44,15 +44,14 @@ class CheckoutData private $status; public function __construct( - $cartId, - $paymentMethod, - $isBusinessLicense, - $selectedCard = -1, - $fieldToken = null, - $successController = null, - $isTransaction = false - ) - { + $cartId, + $paymentMethod, + $isBusinessLicense, + $selectedCard = -1, + $fieldToken = null, + $successController = null, + $isTransaction = false + ) { $this->cartId = $cartId; $this->paymentMethod = $paymentMethod; $this->isBusinessLicense = $isBusinessLicense; @@ -65,15 +64,14 @@ public function __construct( } public static function create( - $cartId, - $paymentMethod, - $isBusinessLicense, - $selectedCard = -1, - $fieldToken = null, - $successController = null, - $isTransaction = false - ) - { + $cartId, + $paymentMethod, + $isBusinessLicense, + $selectedCard = -1, + $fieldToken = null, + $successController = null, + $isTransaction = false + ) { return new self( $cartId, $paymentMethod, diff --git a/src/Enum/PermissionType.php b/src/Enum/PermissionType.php index 20a958e0..afcf34c3 100644 --- a/src/Enum/PermissionType.php +++ b/src/Enum/PermissionType.php @@ -31,4 +31,4 @@ class PermissionType { const VIEW = 'view'; const EDIT = 'edit'; -} \ No newline at end of file +} diff --git a/src/Exception/CouldNotProcessCheckout.php b/src/Exception/CouldNotProcessCheckout.php index b8b19281..e495daa4 100644 --- a/src/Exception/CouldNotProcessCheckout.php +++ b/src/Exception/CouldNotProcessCheckout.php @@ -75,4 +75,4 @@ public static function failedToCreateSaferPayOrder($cartId) ] ); } -} \ No newline at end of file +} diff --git a/src/Exception/SaferPayException.php b/src/Exception/SaferPayException.php index 41906751..851bd257 100644 --- a/src/Exception/SaferPayException.php +++ b/src/Exception/SaferPayException.php @@ -35,8 +35,7 @@ final public function __construct( $internalMessage, $code, array $context = [] - ) - { + ) { parent::__construct($internalMessage, $code); $this->context = $context; } @@ -53,4 +52,4 @@ public static function unknownError() ExceptionCode::UNKNOWN_ERROR ); } -} \ No newline at end of file +} diff --git a/src/Logger/Formatter/LogFormatter.php b/src/Logger/Formatter/LogFormatter.php index ea19716f..cfb3a915 100644 --- a/src/Logger/Formatter/LogFormatter.php +++ b/src/Logger/Formatter/LogFormatter.php @@ -35,4 +35,4 @@ public function getMessage($message) { return self::SAFERPAY_LOG_PREFIX . ' ' . $message; } -} \ No newline at end of file +} diff --git a/src/Logger/Formatter/LogFormatterInterface.php b/src/Logger/Formatter/LogFormatterInterface.php index f3926d67..f31c872b 100644 --- a/src/Logger/Formatter/LogFormatterInterface.php +++ b/src/Logger/Formatter/LogFormatterInterface.php @@ -35,4 +35,4 @@ interface LogFormatterInterface * @return string */ public function getMessage($message); -} \ No newline at end of file +} diff --git a/src/Logger/Logger.php b/src/Logger/Logger.php index f6201dd7..ab849a15 100644 --- a/src/Logger/Logger.php +++ b/src/Logger/Logger.php @@ -26,4 +26,4 @@ class Logger { const LOG_OBJECT_TYPE = 'saferpayLog'; -} \ No newline at end of file +} diff --git a/src/Processor/CheckoutProcessor.php b/src/Processor/CheckoutProcessor.php index 41826f57..62405046 100644 --- a/src/Processor/CheckoutProcessor.php +++ b/src/Processor/CheckoutProcessor.php @@ -40,7 +40,6 @@ use Order; use PrestaShopException; use SaferPayOrder; -use Validate; class CheckoutProcessor { @@ -68,7 +67,8 @@ public function __construct( $this->saferPayOrderRepository = $saferPayOrderRepository; } - public function run(CheckoutData $data) { + public function run(CheckoutData $data) + { $cart = new Cart($data->getCartId()); if (!$cart) { @@ -217,9 +217,8 @@ private function getOrder($cartId) { if (method_exists('Order', 'getIdByCartId')) { return new Order(Order::getIdByCartId($cartId)); - } else { - // For PrestaShop 1.6 use the alternative method - return new Order(Order::getOrderByCartId($cartId)); } + // For PrestaShop 1.6 use the alternative method + return new Order(Order::getOrderByCartId($cartId)); } } diff --git a/src/Processor/index.php b/src/Processor/index.php index 7487f261..6b778722 100644 --- a/src/Processor/index.php +++ b/src/Processor/index.php @@ -21,7 +21,7 @@ *@license SIX Payment Services */ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); +header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); diff --git a/src/Repository/CollectionRepository.php b/src/Repository/CollectionRepository.php index 7ea712d8..0f18bad2 100644 --- a/src/Repository/CollectionRepository.php +++ b/src/Repository/CollectionRepository.php @@ -64,4 +64,4 @@ public function findOneBy(array $keyValueCriteria, $langId = null) return false === $first ? null : $first; } -} \ No newline at end of file +} diff --git a/src/Repository/ReadOnlyCollectionRepositoryInterface.php b/src/Repository/ReadOnlyCollectionRepositoryInterface.php index 357a1704..ad4c44ea 100644 --- a/src/Repository/ReadOnlyCollectionRepositoryInterface.php +++ b/src/Repository/ReadOnlyCollectionRepositoryInterface.php @@ -47,4 +47,4 @@ public function findAllInCollection($langId = null); * @return \ObjectModel|null */ public function findOneBy(array $keyValueCriteria, $langId = null); -} \ No newline at end of file +} diff --git a/src/Repository/SaferPayLogRepository.php b/src/Repository/SaferPayLogRepository.php index 6036db5c..af17438e 100644 --- a/src/Repository/SaferPayLogRepository.php +++ b/src/Repository/SaferPayLogRepository.php @@ -47,4 +47,4 @@ public function prune($daysToKeep) }) ->realize(); } -} \ No newline at end of file +} diff --git a/src/Repository/SaferPayLogRepositoryInterface.php b/src/Repository/SaferPayLogRepositoryInterface.php index 38052f3f..240907e3 100644 --- a/src/Repository/SaferPayLogRepositoryInterface.php +++ b/src/Repository/SaferPayLogRepositoryInterface.php @@ -23,8 +23,6 @@ namespace Invertus\SaferPay\Repository; -use Invertus\SaferPay\Repository\ReadOnlyCollectionRepositoryInterface; - if (!defined('_PS_VERSION_')) { exit; } @@ -32,4 +30,4 @@ interface SaferPayLogRepositoryInterface extends ReadOnlyCollectionRepositoryInterface { public function prune($daysToKeep); -} \ No newline at end of file +} diff --git a/src/Service/Request/InitializeRequestObjectCreator.php b/src/Service/Request/InitializeRequestObjectCreator.php index 0ca1e5e4..906cd5aa 100755 --- a/src/Service/Request/InitializeRequestObjectCreator.php +++ b/src/Service/Request/InitializeRequestObjectCreator.php @@ -27,10 +27,8 @@ use Configuration; use Customer; use Invertus\SaferPay\Config\SaferPayConfig; -use Invertus\SaferPay\DTO\Request\RequestHeader; use Invertus\SaferPay\DTO\Request\Initialize\InitializeRequest; use Invertus\SaferPay\DTO\Request\Payer; -use PrestaShop\PrestaShop\Adapter\Shop\Context; if (!defined('_PS_VERSION_')) { exit; diff --git a/src/Service/SaferPayInitialize.php b/src/Service/SaferPayInitialize.php index e1cb6300..e4822f7e 100755 --- a/src/Service/SaferPayInitialize.php +++ b/src/Service/SaferPayInitialize.php @@ -34,8 +34,6 @@ use Invertus\SaferPay\Repository\SaferPayCardAliasRepository; use Invertus\SaferPay\Factory\ModuleFactory; use Invertus\SaferPay\Service\Request\InitializeRequestObjectCreator; -use Invertus\SaferPay\Config\SaferPayConfig; -use Order; use SaferPayOfficial; if (!defined('_PS_VERSION_')) { diff --git a/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php b/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php index 92c1b2fa..b79bc354 100755 --- a/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php +++ b/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php @@ -30,7 +30,6 @@ use Invertus\SaferPay\Repository\SaferPayOrderRepository; use Invertus\SaferPay\Service\Request\AuthorizationRequestObjectCreator; use Invertus\SaferPay\Service\SaferPayOrderStatusService; -use Order; use SaferPayOrder; if (!defined('_PS_VERSION_')) { diff --git a/upgrade/install-1.1.8.php b/upgrade/install-1.1.8.php index d52c8914..636a4cb3 100644 --- a/upgrade/install-1.1.8.php +++ b/upgrade/install-1.1.8.php @@ -41,4 +41,4 @@ function upgrade_module_1_1_8(SaferPayOfficial $module) $module->registerHook('actionObjectOrderPaymentAddAfter'); return true; -} \ No newline at end of file +} diff --git a/upgrade/install-1.2.2.php b/upgrade/install-1.2.2.php index b0b04cc5..5e3f08fc 100644 --- a/upgrade/install-1.2.2.php +++ b/upgrade/install-1.2.2.php @@ -35,4 +35,3 @@ function upgrade_module_1_2_2($module) && $module->unregisterHook('actionOrderStatusUpdate') && Configuration::deleteByName('SAFERPAY_SEND_ORDER_CONFIRMATION'); } - From 7678e2c00396da0baa4dc74644bf0a880ff9581b Mon Sep 17 00:00:00 2001 From: MarijusCoding Date: Thu, 3 Oct 2024 15:49:28 +0300 Subject: [PATCH 51/90] [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 52/90] [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 53/90] [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 54/90] [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 55/90] 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 56/90] [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 57/90] [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 58/90] [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 59/90] [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 60/90] [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 61/90] [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 62/90] 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 63/90] [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 64/90] [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 65/90] [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 66/90] [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 67/90] [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 68/90] [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 69/90] [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 70/90] [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 71/90] [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 72/90] [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 73/90] [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 74/90] [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 75/90] 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 76/90] 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 77/90] 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 78/90] [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 79/90] 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 80/90] 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 81/90] 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 82/90] 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 83/90] 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 84/90] 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 85/90] 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 86/90] 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 87/90] 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 88/90] 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 89/90] 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 90/90] 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,