diff --git a/.docker/.htaccess1764 b/.docker/.htaccess1764 old mode 100755 new mode 100644 diff --git a/.docker/.htaccess1770 b/.docker/.htaccess1770 old mode 100755 new mode 100644 diff --git a/.docker/.htaccess1784 b/.docker/.htaccess1784 old mode 100755 new mode 100644 diff --git a/.docker/.htaccess1786 b/.docker/.htaccess1786 old mode 100755 new mode 100644 diff --git a/.docker/Dockerfile.1764 b/.docker/Dockerfile.1764 old mode 100755 new mode 100644 diff --git a/.docker/Dockerfile.1770 b/.docker/Dockerfile.1770 old mode 100755 new mode 100644 diff --git a/.docker/Dockerfile.1784 b/.docker/Dockerfile.1784 old mode 100755 new mode 100644 diff --git a/.docker/Dockerfile.1786 b/.docker/Dockerfile.1786 old mode 100755 new mode 100644 diff --git a/.docker/wait-for-container.sh b/.docker/wait-for-container.sh old mode 100755 new mode 100644 diff --git a/.github/.htaccess b/.github/.htaccess old mode 100755 new mode 100644 diff --git a/.github/workflows/PS1764_Cypress_Browserstack.yml b/.github/workflows/PS1764_Cypress_Browserstack.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/PS1770_Cypress_Browserstack.yml b/.github/workflows/PS1770_Cypress_Browserstack.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/PS1784_Cypress_Browserstack.yml b/.github/workflows/PS1784_Cypress_Browserstack.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/PS1786_Cypress_Browserstack.yml b/.github/workflows/PS1786_Cypress_Browserstack.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml old mode 100755 new mode 100644 diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/.php_cs.dist b/.php_cs.dist old mode 100755 new mode 100644 diff --git a/Makefile b/Makefile old mode 100755 new mode 100644 diff --git a/README.md b/README.md old mode 100755 new mode 100644 diff --git a/User-guide-saferpay-module-for-prestashop-int-en.pdf b/User-guide-saferpay-module-for-prestashop-int-en.pdf old mode 100755 new mode 100644 diff --git a/browserstack.json b/browserstack.json old mode 100755 new mode 100644 diff --git a/changelog.md b/changelog.md old mode 100755 new mode 100644 index 4dc83f73a..b1d1a4fe8 --- a/changelog.md +++ b/changelog.md @@ -196,4 +196,10 @@ ## [2.0.2] - Remove WL Crypto payment method - Added setting to toggle order confirmation email sending -- Added feature to group card payment methods into unified "Card" payment method \ No newline at end of file +- Added feature to group card payment methods into unified "Card" payment method + +## [2.0.3] +- Optimized database performance +- Dynamic termimal selection +- Removed uneccesary inputs from admin settings +- Checked overall module stability \ No newline at end of file diff --git a/composer.json b/composer.json old mode 100755 new mode 100644 index 67743e8c1..fef5eb7ff --- a/composer.json +++ b/composer.json @@ -18,7 +18,10 @@ "config": { "prepend-autoloader": false, "platform": { - "php": "5.6" + "php": "7.1" + }, + "audit": { + "ignore": ["PKSA-wws7-mr54-jsny"] } }, "repositories": { @@ -33,22 +36,23 @@ } }, "require": { + "php": ">=7.1", "vlucas/phpdotenv": "^3.6", - "symfony/config": "^3.4", "symfony/dependency-injection": "^3.4", "symfony/filesystem": "^3.4", "apimatic/unirest-php": "^2.3", "symfony/yaml": "^3.4", - "league/container": "2.5.0", + "league/container": "^3.0", "invertus/lock": "^1.0.0", "invertus/knapsack": "^10.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "*", - "phpunit/phpunit": "*", - "behat/behat": "*", - "symfony/translation": "*", + "friendsofphp/php-cs-fixer": "^2.16.7", + "phpunit/phpunit": "^7.5", + "behat/behat": "^3.7", + "symfony/translation": "^3.4", + "symfony/process": "^3.4", "prestashop/php-dev-tools": "^3.16" }, "scripts": { diff --git a/controllers/admin/AdminSaferPayOfficialFieldsController.php b/controllers/admin/AdminSaferPayOfficialFieldsController.php old mode 100755 new mode 100644 diff --git a/controllers/admin/AdminSaferPayOfficialLogsController.php b/controllers/admin/AdminSaferPayOfficialLogsController.php old mode 100755 new mode 100644 diff --git a/controllers/admin/AdminSaferPayOfficialModuleController.php b/controllers/admin/AdminSaferPayOfficialModuleController.php old mode 100755 new mode 100644 diff --git a/controllers/admin/AdminSaferPayOfficialOrderController.php b/controllers/admin/AdminSaferPayOfficialOrderController.php old mode 100755 new mode 100644 diff --git a/controllers/admin/AdminSaferPayOfficialPaymentController.php b/controllers/admin/AdminSaferPayOfficialPaymentController.php old mode 100755 new mode 100644 index a574e0756..6d2102d2a --- a/controllers/admin/AdminSaferPayOfficialPaymentController.php +++ b/controllers/admin/AdminSaferPayOfficialPaymentController.php @@ -160,8 +160,10 @@ protected function renderShoppingPointOptions() $restrictionRepository = $this->module->getService(SaferPayRestrictionRepository::class); $paymentMethods = $this->getPaymentMethods(); - if (is_null($paymentMethods)) { - return; + if (is_null($paymentMethods) || empty($paymentMethods)) { + $this->errors[] = $this->module->l('No payment methods available. Please check your SaferPay account configuration.'); + + return ''; } $this->initForm(); @@ -204,6 +206,12 @@ protected function renderShoppingPointOptions() $this->module->getLocalPath() . 'views/templates/admin/payment_method.tpl' ); } + $this->context->smarty->assign([ + 'countryOptions' => $this->getActiveCountriesList(), + 'countrySelect' => [], + 'currencyOptions' => [0 => $this->module->l('All')], + 'currencySelect' => [], + ]); $referralOptionsForm->fields_value['all'] = $this->context->smarty->fetch( $this->module->getLocalPath() . 'views/templates/admin/payment_method_all.tpl' diff --git a/controllers/admin/AdminSaferPayOfficialSettingsController.php b/controllers/admin/AdminSaferPayOfficialSettingsController.php old mode 100755 new mode 100644 index 7adfd5731..701ffa418 --- a/controllers/admin/AdminSaferPayOfficialSettingsController.php +++ b/controllers/admin/AdminSaferPayOfficialSettingsController.php @@ -24,6 +24,8 @@ use Invertus\SaferPay\Config\SaferPayConfig; use Invertus\SaferPay\Repository\SaferPaySavedCreditCardRepository; use Invertus\SaferPay\Adapter\Configuration; +use Invertus\SaferPay\Service\SaferPayTerminalService; +use Invertus\SaferPay\Logger\LoggerInterface; require_once dirname(__FILE__) . '/../../vendor/autoload.php'; @@ -75,9 +77,71 @@ public function postProcess() $this->errors[] = $this->module->l('Field Access Token is required to use business license'); } + $this->validateTerminalId(); + return true; } + private function validateTerminalId() + { + try { + /** @var Configuration $configuration */ + $configuration = $this->module->getService(Configuration::class); + + $suffix = SaferPayConfig::getConfigSuffix(); + + $terminalId = Tools::getValue(SaferPayConfig::TERMINAL_ID . $suffix); + $customerId = Tools::getValue(SaferPayConfig::CUSTOMER_ID . $suffix) + ?: $configuration->get(SaferPayConfig::CUSTOMER_ID . $suffix); + $username = Tools::getValue(SaferPayConfig::USERNAME . $suffix) + ?: $configuration->get(SaferPayConfig::USERNAME . $suffix); + $password = Tools::getValue(SaferPayConfig::PASSWORD . $suffix) + ?: $configuration->get(SaferPayConfig::PASSWORD . $suffix); + + if (empty($terminalId) || empty($customerId) || empty($username) || empty($password)) { + return; + } + + $originalCustomerId = \Configuration::get(SaferPayConfig::CUSTOMER_ID . $suffix); + $originalUsername = \Configuration::get(SaferPayConfig::USERNAME . $suffix); + $originalPassword = \Configuration::get(SaferPayConfig::PASSWORD . $suffix); + + try { + \Configuration::updateValue(SaferPayConfig::CUSTOMER_ID . $suffix, $customerId); + \Configuration::updateValue(SaferPayConfig::USERNAME . $suffix, $username); + \Configuration::updateValue(SaferPayConfig::PASSWORD . $suffix, $password); + + /** @var SaferPayTerminalService $terminalService */ + $terminalService = $this->module->getService(SaferPayTerminalService::class); + + $terminals = $terminalService->getAvailableTerminals(); + + $isValid = false; + foreach ($terminals as $terminal) { + if ($terminal['TerminalId'] === $terminalId) { + $isValid = true; + break; + } + } + + if (!$isValid && !empty($terminals)) { + $this->warnings[] = $this->module->l('Warning: The Terminal ID you entered was not found in the list of available terminals. Please verify the Terminal ID is correct.'); + } + } finally { + \Configuration::updateValue(SaferPayConfig::CUSTOMER_ID . $suffix, $originalCustomerId); + \Configuration::updateValue(SaferPayConfig::USERNAME . $suffix, $originalUsername); + \Configuration::updateValue(SaferPayConfig::PASSWORD . $suffix, $originalPassword); + } + } catch (Exception $e) { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + $logger->error(sprintf('%s - Failed to validate terminal ID: %s', self::FILE_NAME, $e->getMessage()), [ + 'context' => [], + 'exception' => $e, + ]); + } + } + public function initOptions() { $this->context->smarty->assign(SaferPayConfig::PASSWORD, SaferPayConfig::WEB_SERVICE_PASSWORD_PLACEHOLDER); @@ -104,6 +168,57 @@ public function setMedia($isNewTheme = false) $this->addJS('modules/' . $this->module->name . '/views/js/admin/saferpay_settings.js'); } + /** + * @param string $environment 'test' or 'live' + * @return array + */ + private function getTerminalsForEnvironment($environment = 'live') + { + $suffix = ($environment === 'test') ? SaferPayConfig::TEST_SUFFIX : ''; + + $customerId = Tools::getValue(SaferPayConfig::CUSTOMER_ID . $suffix) + ?: \Configuration::get(SaferPayConfig::CUSTOMER_ID . $suffix); + $username = Tools::getValue(SaferPayConfig::USERNAME . $suffix) + ?: \Configuration::get(SaferPayConfig::USERNAME . $suffix); + $password = Tools::getValue(SaferPayConfig::PASSWORD . $suffix) + ?: \Configuration::get(SaferPayConfig::PASSWORD . $suffix); + + if (empty($customerId) || empty($username) || empty($password)) { + return []; + } + + $originalCustomerId = \Configuration::get(SaferPayConfig::CUSTOMER_ID . $suffix); + $originalUsername = \Configuration::get(SaferPayConfig::USERNAME . $suffix); + $originalPassword = \Configuration::get(SaferPayConfig::PASSWORD . $suffix); + $originalTestMode = \Configuration::get(SaferPayConfig::TEST_MODE); + + try { + \Configuration::updateValue(SaferPayConfig::CUSTOMER_ID . $suffix, $customerId); + \Configuration::updateValue(SaferPayConfig::USERNAME . $suffix, $username); + \Configuration::updateValue(SaferPayConfig::PASSWORD . $suffix, $password); + \Configuration::updateValue(SaferPayConfig::TEST_MODE, $environment === 'test' ? 1 : 0); + + /** @var SaferPayTerminalService $terminalService */ + $terminalService = $this->module->getService(SaferPayTerminalService::class); + $terminals = $terminalService->getAvailableTerminals($customerId); + + return $terminals; + } catch (Exception $e) { + /** @var LoggerInterface $logger */ + $logger = $this->module->getService(LoggerInterface::class); + $logger->error(sprintf('%s - Failed to get terminals: %s', self::FILE_NAME, $e->getMessage()), [ + 'context' => [], + 'exception' => $e, + ]); + return []; + } finally { + \Configuration::updateValue(SaferPayConfig::CUSTOMER_ID . $suffix, $originalCustomerId); + \Configuration::updateValue(SaferPayConfig::USERNAME . $suffix, $originalUsername); + \Configuration::updateValue(SaferPayConfig::PASSWORD . $suffix, $originalPassword); + \Configuration::updateValue(SaferPayConfig::TEST_MODE, $originalTestMode); + } + } + /** * @return array */ @@ -384,8 +499,11 @@ private function displayTestEnvironmentConfiguration() ], SaferPayConfig::TERMINAL_ID . SaferPayConfig::TEST_SUFFIX => [ 'title' => $this->module->l('Terminal ID'), - 'type' => 'text', + 'type' => 'terminal_selector', 'class' => 'fixed-width-xl', + 'value' => \Configuration::get(SaferPayConfig::TERMINAL_ID . SaferPayConfig::TEST_SUFFIX), + 'environment' => 'test', + 'terminals' => $this->getTerminalsForEnvironment('test'), ], SaferPayConfig::MERCHANT_EMAILS . SaferPayConfig::TEST_SUFFIX => [ 'title' => $this->module->l('Merchant emails'), @@ -402,16 +520,6 @@ private function displayTestEnvironmentConfiguration() 'type' => 'text', 'class' => 'fixed-width-xxl', ], - SaferPayConfig::FIELDS_LIBRARY . SaferPayConfig::TEST_SUFFIX . '_description' => [ - 'type' => 'desc', - 'class' => 'col-lg-12', - 'template' => 'field-javascript-library-desc.tpl', - ], - SaferPayConfig::FIELDS_LIBRARY . SaferPayConfig::TEST_SUFFIX => [ - 'title' => $this->module->l('Field Javascript library url'), - 'type' => 'text', - 'class' => 'fixed-width-xxl', - ], SaferPayConfig::BUSINESS_LICENSE . SaferPayConfig::TEST_SUFFIX => [ 'title' => $this->module->l('I have Business license'), 'validation' => 'isBool', @@ -459,8 +567,11 @@ private function displayLiveEnvironmentConfiguration() ], SaferPayConfig::TERMINAL_ID => [ 'title' => $this->module->l('Terminal ID'), - 'type' => 'text', + 'type' => 'terminal_selector', 'class' => 'fixed-width-xl', + 'value' => \Configuration::get(SaferPayConfig::TERMINAL_ID), + 'environment' => 'live', + 'terminals' => $this->getTerminalsForEnvironment('live'), ], SaferPayConfig::MERCHANT_EMAILS => [ 'title' => $this->module->l('Merchant emails'), @@ -477,16 +588,6 @@ private function displayLiveEnvironmentConfiguration() 'type' => 'text', 'class' => 'fixed-width-xxl', ], - SaferPayConfig::FIELDS_LIBRARY . '_description' => [ - 'type' => 'desc', - 'class' => 'col-lg-12', - 'template' => 'field-javascript-library-desc.tpl', - ], - SaferPayConfig::FIELDS_LIBRARY => [ - 'title' => $this->module->l('Field Javascript library url'), - 'type' => 'text', - 'class' => 'fixed-width-xxl', - ], SaferPayConfig::BUSINESS_LICENSE => [ 'title' => $this->module->l('I have Business license'), 'validation' => 'isBool', diff --git a/controllers/admin/index.php b/controllers/admin/index.php old mode 100755 new mode 100644 diff --git a/controllers/front/ajax.php b/controllers/front/ajax.php old mode 100755 new mode 100644 diff --git a/controllers/front/creditCards.php b/controllers/front/creditCards.php old mode 100755 new mode 100644 diff --git a/controllers/front/fail.php b/controllers/front/fail.php old mode 100755 new mode 100644 diff --git a/controllers/front/failIFrame.php b/controllers/front/failIFrame.php old mode 100755 new mode 100644 diff --git a/controllers/front/failValidation.php b/controllers/front/failValidation.php old mode 100755 new mode 100644 diff --git a/controllers/front/hostedIframe.php b/controllers/front/hostedIframe.php old mode 100755 new mode 100644 index e44b8c41e..91daa8f05 --- a/controllers/front/hostedIframe.php +++ b/controllers/front/hostedIframe.php @@ -80,7 +80,7 @@ public function setMedia() $this->context->controller->registerJavascript( 'remote-saferpay-fields-js-lib', - Configuration::get(SaferPayConfig::FIELDS_LIBRARY . SaferPayConfig::getConfigSuffix()), + SaferPayConfig::FIELDS_LIBRARY_DEFAULT_VALUE, ['server' => 'remote', 'position' => 'bottom', 'priority' => 20] ); diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php old mode 100755 new mode 100644 diff --git a/controllers/front/index.php b/controllers/front/index.php old mode 100755 new mode 100644 diff --git a/controllers/front/notify.php b/controllers/front/notify.php old mode 100755 new mode 100644 index 870464e7c..85938721c --- a/controllers/front/notify.php +++ b/controllers/front/notify.php @@ -136,8 +136,8 @@ public function postProcess() $orderId = Order::getIdByCartId($cartId); - //TODO look into pipeline design pattern to use when object is modified in multiple places to avoid this issue. - //NOTE must be left below assert action to get newest information. + // @NOTE: Pipeline design pattern could improve readability when order is modified in multiple places. + // Must be left below assert action to get newest information. $order = new Order($orderId); if (!$assertResponseBody->getLiability()->getLiabilityShift() && diff --git a/controllers/front/pendingNotify.php b/controllers/front/pendingNotify.php old mode 100755 new mode 100644 diff --git a/controllers/front/return.php b/controllers/front/return.php old mode 100755 new mode 100644 diff --git a/controllers/front/success.php b/controllers/front/success.php old mode 100755 new mode 100644 diff --git a/controllers/front/successHosted.php b/controllers/front/successHosted.php old mode 100755 new mode 100644 diff --git a/controllers/front/successIFrame.php b/controllers/front/successIFrame.php old mode 100755 new mode 100644 diff --git a/controllers/front/validation.php b/controllers/front/validation.php old mode 100755 new mode 100644 diff --git a/controllers/index.php b/controllers/index.php old mode 100755 new mode 100644 diff --git a/cypress.json b/cypress.json old mode 100755 new mode 100644 diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json old mode 100755 new mode 100644 diff --git a/cypress/integration/01_ps1764.Module.Configure.cy.js b/cypress/integration/01_ps1764.Module.Configure.cy.js old mode 100755 new mode 100644 diff --git a/cypress/integration/01_ps1770.Module.Configure.cy.js b/cypress/integration/01_ps1770.Module.Configure.cy.js old mode 100755 new mode 100644 diff --git a/cypress/integration/01_ps1784.Module.Configure.cy.js b/cypress/integration/01_ps1784.Module.Configure.cy.js old mode 100755 new mode 100644 diff --git a/cypress/integration/01_ps1786.Module.Configure.cy.js b/cypress/integration/01_ps1786.Module.Configure.cy.js old mode 100755 new mode 100644 diff --git a/cypress/integration/02_ps1764.cy.js b/cypress/integration/02_ps1764.cy.js old mode 100755 new mode 100644 diff --git a/cypress/integration/02_ps1770.cy.js b/cypress/integration/02_ps1770.cy.js old mode 100755 new mode 100644 diff --git a/cypress/integration/02_ps1784.cy.js b/cypress/integration/02_ps1784.cy.js old mode 100755 new mode 100644 diff --git a/cypress/integration/02_ps1786.cy.js b/cypress/integration/02_ps1786.cy.js old mode 100755 new mode 100644 diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js old mode 100755 new mode 100644 diff --git a/cypress/support/commands.js b/cypress/support/commands.js old mode 100755 new mode 100644 diff --git a/cypress/support/index.js b/cypress/support/index.js old mode 100755 new mode 100644 diff --git a/docker-compose.1764.yml b/docker-compose.1764.yml old mode 100755 new mode 100644 diff --git a/docker-compose.1770.yml b/docker-compose.1770.yml old mode 100755 new mode 100644 diff --git a/docker-compose.1784.yml b/docker-compose.1784.yml old mode 100755 new mode 100644 diff --git a/docker-compose.1786.yml b/docker-compose.1786.yml old mode 100755 new mode 100644 diff --git a/docker-compose.e2e.1764.yml b/docker-compose.e2e.1764.yml old mode 100755 new mode 100644 diff --git a/docker-compose.e2e.1784.yml b/docker-compose.e2e.1784.yml old mode 100755 new mode 100644 diff --git a/docker-compose.e2e.1786.yml b/docker-compose.e2e.1786.yml old mode 100755 new mode 100644 diff --git a/index.php b/index.php old mode 100755 new mode 100644 diff --git a/logo.png b/logo.png old mode 100755 new mode 100644 diff --git a/package-lock.json b/package-lock.json old mode 100755 new mode 100644 diff --git a/package.json b/package.json old mode 100755 new mode 100644 diff --git a/saferpay.config.php b/saferpay.config.php old mode 100755 new mode 100644 diff --git a/saferpayofficial.php b/saferpayofficial.php old mode 100755 new mode 100644 index b0acd4630..da83d0cf4 --- a/saferpayofficial.php +++ b/saferpayofficial.php @@ -59,13 +59,16 @@ class SaferPayOfficial extends PaymentModule const ADMIN_ORDER_CONTROLLER = 'AdminSaferPayOfficialOrder'; const ADMIN_LOGS_CONTROLLER = 'AdminSaferPayOfficialLogs'; - const DISABLE_CACHE = true; + /** + * @var LeagueServiceContainerProvider|null + */ + private $containerProvider; public function __construct($name = null) { $this->name = 'saferpayofficial'; $this->author = 'Invertus'; - $this->version = '2.0.2'; + $this->version = '2.0.3'; $this->module_key = '3d3506c3e184a1fe63b936b82bda1bdf'; $this->displayName = 'SaferpayOfficial'; $this->description = 'Saferpay Payment module'; @@ -87,17 +90,13 @@ public function getContent() public function install() { - $installer = new \Invertus\SaferPay\Install\Installer($this); - if (!parent::install()) { return false; } - if (!$installer->install()) { - return false; - } + $installer = new Installer($this); - return true; + return $installer->install(); } public function uninstall() @@ -129,11 +128,20 @@ private function loadConfig() { require $this->getLocalPath() . 'saferpay.config.php'; } + + /** + * Get a service from the container. + * + * @param string $service + * @return mixed + */ public function getService($service) { - $containerProvider = new LeagueServiceContainerProvider(); + if (null === $this->containerProvider) { + $this->containerProvider = new LeagueServiceContainerProvider(); + } - return $containerProvider->getService($service); + return $this->containerProvider->getService($service); } public function hookDisplayOrderConfirmation($params) @@ -179,7 +187,7 @@ public function hookActionObjectOrderPaymentAddAfter($params) /** @var Order|bool $order */ $order = $orders->getFirst(); - if (!Validate::isLoadedObject($order) || !$order) { + if (!Validate::isLoadedObject($order)) { return; } @@ -235,9 +243,6 @@ public function hookPaymentOptions($params) $logosEnabled[] = SaferPayConfig::PAYMENT_CARDS; } - $activePaymentMethods = $paymentRepository->getActivePaymentMethodsNames(); - $activePaymentMethods = array_column($activePaymentMethods, 'name'); - /** @var CurrencyProvider $currencyProvider */ $currencyProvider = $this->getService(CurrencyProvider::class); @@ -250,6 +255,17 @@ public function hookPaymentOptions($params) $paymentMethods = $cardGroupingService->group($paymentMethods, $allCurrencies); } + // Services used in the loop - initialized once for performance + /** @var SaferPayCardAliasRepository $cardAliasRepository */ + $cardAliasRepository = $this->getService(SaferPayCardAliasRepository::class); + /** @var PaymentRedirectionProvider $paymentRedirectionProvider */ + $paymentRedirectionProvider = $this->getService(PaymentRedirectionProvider::class); + /** @var LegacyTranslator $translator */ + $translator = $this->getService(LegacyTranslator::class); + + $isBusinessLicenseEnabled = Configuration::get(SaferPayConfig::BUSINESS_LICENSE . SaferPayConfig::getConfigSuffix()); + $isCreditCardSavingEnabled = Configuration::get(SaferPayConfig::CREDIT_CARD_SAVE); + foreach ($paymentMethods as $paymentMethod) { $paymentMethod['paymentMethod'] = str_replace(' ', '', $paymentMethod['paymentMethod']); @@ -257,8 +273,10 @@ public function hookPaymentOptions($params) $paymentMethod['currencies'] = $currencyProvider->getAllCurrenciesInArray(); } - if (!in_array($this->context->currency->iso_code, $paymentMethod['currencies']) - && !in_array($paymentMethod['paymentMethod'], \Invertus\SaferPay\Config\SaferPayConfig::WALLET_PAYMENT_METHODS)) { + if ( + !in_array($this->context->currency->iso_code, $paymentMethod['currencies']) + && !in_array($paymentMethod['paymentMethod'], \Invertus\SaferPay\Config\SaferPayConfig::WALLET_PAYMENT_METHODS) + ) { continue; } @@ -273,27 +291,17 @@ public function hookPaymentOptions($params) $paymentMethod['paymentMethod'], SaferPayConfig::TRANSACTION_METHODS ); - $isBusinessLicenseEnabled = Configuration::get(SaferPayConfig::BUSINESS_LICENSE . SaferPayConfig::getConfigSuffix()); - /** @var SaferPayCardAliasRepository $cardAliasRep */ - $cardAliasRep = $this->getService(SaferPayCardAliasRepository::class); - - $isCreditCardSavingEnabled = Configuration::get(SaferPayConfig::CREDIT_CARD_SAVE); $selectedCard = 0; + $isCreditCardSavingEnabledForUser = $isCreditCardSavingEnabled; + if ($this->context->customer->is_guest) { - $isCreditCardSavingEnabled = false; + $isCreditCardSavingEnabledForUser = false; $selectedCard = -1; } - /** @var PaymentRedirectionProvider $paymentRedirectionProvider */ - $paymentRedirectionProvider = $this->getService(PaymentRedirectionProvider::class); - $newOption = new PaymentOption(); - $translator = $this->getService( - LegacyTranslator::class - ); - $paymentMethodName = $translator->translate($paymentMethod['paymentMethod']); $inputs = [ @@ -309,10 +317,10 @@ public function hookPaymentOptions($params) ], ]; - if ($isCreditCardSavingEnabled && $isCreditCard && $isBusinessLicenseEnabled) { + if ($isCreditCardSavingEnabledForUser && $isCreditCard && $isBusinessLicenseEnabled) { $currentDate = date('Y-m-d h:i:s'); - $savedCards = $cardAliasRep->getSavedValidCardsByUserIdAndPaymentMethod( + $savedCards = $cardAliasRepository->getSavedValidCardsByUserIdAndPaymentMethod( $this->context->customer->id, $paymentMethod['paymentMethod'], $currentDate @@ -418,13 +426,12 @@ public function hookActionEmailSendBefore($params) return true; } - - return true; } public function hookActionAdminControllerSetMedia() { - if ('AdminOrders' === Tools::getValue('controller') + if ( + 'AdminOrders' === Tools::getValue('controller') && (Tools::isSubmit('vieworder') || Tools::getValue('action') === 'vieworder') ) { $this->context->controller->addCSS( @@ -518,8 +525,10 @@ private function displayInAdminOrderPage(array $params) // Note: This condition check or Payment method supports 3DS. // If payment method does not supports 3DS , when we change 'liability_shift' // to true , to hide 'failed security check ' message. - if ($assertData['liability_shift'] === "0" - && !in_array($assertData['paymentMethod'], $supported3DsPaymentMethods)) { + if ( + $assertData['liability_shift'] === "0" + && !in_array($assertData['paymentMethod'], $supported3DsPaymentMethods) + ) { $assertData['liability_shift'] = true; } @@ -543,7 +552,8 @@ private function displayInAdminOrderPage(array $params) public function addFlash($msg, $type) { - if (VersionUtility::isPsVersionGreaterOrEqualTo('1.7.7.0') + if ( + VersionUtility::isPsVersionGreaterOrEqualTo('1.7.7.0') && VersionUtility::isPsVersionLessThan('9.0.0') ) { return $this->get('session')->getFlashBag()->add($type, $msg); diff --git a/src/.gitkeep b/src/.gitkeep old mode 100755 new mode 100644 diff --git a/src/Adapter/LegacyContext.php b/src/Adapter/LegacyContext.php old mode 100755 new mode 100644 index 91434eecb..852e4a585 --- a/src/Adapter/LegacyContext.php +++ b/src/Adapter/LegacyContext.php @@ -31,52 +31,82 @@ class LegacyContext { - public function getContext() + /** + * @return Context + */ + public function getContext(): Context { return Context::getContext(); } - public function getShopId() + /** + * @return int + */ + public function getShopId(): int { return (int) $this->getContext()->shop->id; } - public function getLanguageId() + /** + * @return int + */ + public function getLanguageId(): int { return (int) $this->getContext()->language->id; } - public function getLanguageIso() + /** + * @return string + */ + public function getLanguageIso(): string { return (string) $this->getContext()->language->iso_code ?: 'en'; } - public function getCurrencyIsoCode() + /** + * @return string + */ + public function getCurrencyIsoCode(): string { return $this->getContext()->currency->iso_code; } - public function getCountryIsoCode() + /** + * @return string + */ + public function getCountryIsoCode(): string { return $this->getContext()->country->iso_code; } - public function getCountryId() + /** + * @return int + */ + public function getCountryId(): int { return $this->getContext()->country->id; } - public function getCurrencyId() + /** + * @return int + */ + public function getCurrencyId(): int { return $this->getContext()->currency->id; } - public function getMobileDetect() + /** + * @return \Mobile_Detect + */ + public function getMobileDetect(): \Mobile_Detect { return $this->getContext()->getMobileDetect(); } - public function getLink() + /** + * @return \Link + */ + public function getLink(): \Link { return $this->getContext()->link; } @@ -84,23 +114,34 @@ public function getLink() /** * @return int */ - public function getDeviceDetect() + public function getDeviceDetect(): int { return (int) $this->getContext()->getDevice(); } - public function getAdminLink($controllerName, array $params = []) + /** + * @param string $controllerName + * @param array $params + * @return string + */ + public function getAdminLink(string $controllerName, array $params = []): string { /* @noinspection PhpMethodParametersCountMismatchInspection - its valid for PS1.7 */ return (string) Context::getContext()->link->getAdminLink($controllerName, true, [], $params); } - public function getLanguageCode() + /** + * @return string + */ + public function getLanguageCode(): string { return (string) $this->getContext()->language->language_code ?: 'en-us'; } - public function getCurrencyIso() + /** + * @return string + */ + public function getCurrencyIso(): string { if (!$this->getContext()->currency) { return ''; @@ -109,7 +150,10 @@ public function getCurrencyIso() return (string) $this->getContext()->currency->iso_code; } - public function getCountryIso() + /** + * @return string + */ + public function getCountryIso(): string { if (!$this->getContext()->country) { return ''; @@ -118,12 +162,18 @@ public function getCountryIso() return (string) $this->getContext()->country->iso_code; } - public function getCurrency() + /** + * @return ?\Currency + */ + public function getCurrency(): ?\Currency { return $this->getContext()->currency; } - public function getCustomerId() + /** + * @return int + */ + public function getCustomerId(): int { if (!$this->getContext()->customer) { return 0; @@ -132,7 +182,10 @@ public function getCustomerId() return (int) $this->getContext()->customer->id; } - public function isCustomerLoggedIn() + /** + * @return bool + */ + public function isCustomerLoggedIn(): bool { if (!$this->getContext()->customer) { return false; @@ -141,7 +194,10 @@ public function isCustomerLoggedIn() return (bool) $this->getContext()->customer->isLogged(); } - public function getCustomerEmail() + /** + * @return string + */ + public function getCustomerEmail(): string { if (!$this->getContext()->customer) { return ''; @@ -150,25 +206,36 @@ public function getCustomerEmail() return $this->getContext()->customer->email; } - public function getShopDomain() + /** + * @return string + */ + public function getShopDomain(): string { return (string) $this->getContext()->shop->domain; } - public function getShopName() + /** + * @return string + */ + public function getShopName(): string { return (string) $this->getContext()->shop->name; } - public function getController() + /** + * @return \Controller|\AdminController|\FrontController|null + */ + public function getController(): ?\Controller { return $this->getContext()->controller; } /** + * @param \Cart $cart + * @return void * @throws \Throwable */ - public function setCurrentCart(\Cart $cart) + public function setCurrentCart(\Cart $cart): void { $this->getContext()->cart = $cart; $this->getContext()->cart->update(); @@ -177,22 +244,38 @@ public function setCurrentCart(\Cart $cart) $this->getContext()->cookie->write(); } - public function setCountry(\Country $country) + /** + * @param \Country $country + * @return void + */ + public function setCountry(\Country $country): void { $this->getContext()->country = $country; } - public function setCurrency(\Currency $currency) + /** + * @param \Currency $currency + * @return void + */ + public function setCurrency(\Currency $currency): void { $this->getContext()->currency = $currency; } - public function getBaseLink($shopId = null, $ssl = null) + /** + * @param int|null $shopId + * @param bool|null $ssl + * @return string + */ + public function getBaseLink(?int $shopId = null, ?bool $ssl = null): string { return (string) $this->getContext()->link->getBaseLink($shopId, $ssl); } - public function getCartProducts() + /** + * @return array + */ + public function getCartProducts(): array { $cart = $this->getContext()->cart; @@ -203,17 +286,27 @@ public function getCartProducts() return $cart->getProducts(); } - public function getCart() + /** + * @return \Cart|null + */ + public function getCart(): ?\Cart { return isset($this->getContext()->cart) ? $this->getContext()->cart : null; } - public function getShopThemeName() + /** + * @return string + */ + public function getShopThemeName(): string { return $this->getContext()->shop->theme_name; } - public function updateCustomer(\Customer $customer) + /** + * @param \Customer $customer + * @return void + */ + public function updateCustomer(\Customer $customer): void { $this->getContext()->updateCustomer($customer); } diff --git a/src/Adapter/index.php b/src/Adapter/index.php old mode 100755 new mode 100644 diff --git a/src/Api/ApiRequest.php b/src/Api/ApiRequest.php old mode 100755 new mode 100644 index 512e75427..5f02cba3d --- a/src/Api/ApiRequest.php +++ b/src/Api/ApiRequest.php @@ -53,10 +53,10 @@ public function __construct(LoggerInterface $logger) * * @param string $url * @param array $params - * @return object|null + * @return \stdClass|null * @throws Exception */ - public function post($url, $params = []) + public function post(string $url, array $params = []): ?\stdClass { try { $response = Request::post( @@ -87,13 +87,13 @@ public function post($url, $params = []) * * @param string $url * @param array $params - * @return array |null + * @return \stdClass|null * @throws Exception */ - public function get($url, $params = []) + public function get(string $url, array $params = []): ?\stdClass { $response = null; - + try { $response = Request::get( $this->getBaseUrl() . $url, @@ -127,7 +127,10 @@ public function get($url, $params = []) } } - private function getHeaders() + /** + * @return array + */ + private function getHeaders(): array { $username = Configuration::get(SaferPayConfig::USERNAME . SaferPayConfig::getConfigSuffix()); $password = Configuration::get(SaferPayConfig::PASSWORD . SaferPayConfig::getConfigSuffix()); @@ -143,12 +146,20 @@ private function getHeaders() ]; } - private function getBaseUrl() + /** + * @return string + */ + private function getBaseUrl(): string { return SaferPayConfig::getBaseApiUrl(); } - private function isValidResponse(Response $response) + /** + * @param Response $response + * @return void + * @throws SaferPayApiException + */ + private function isValidResponse(Response $response): void { if (isset($response->body->ErrorName) && $response->body->ErrorName === SaferPayConfig::TRANSACTION_ALREADY_CAPTURED) { $this->logger->debug('Tried to apply state CAPTURED to already captured order', [ diff --git a/src/Api/Request/AssertRefundService.php b/src/Api/Request/AssertRefundService.php old mode 100755 new mode 100644 diff --git a/src/Api/Request/AssertService.php b/src/Api/Request/AssertService.php old mode 100755 new mode 100644 diff --git a/src/Api/Request/AuthorizationService.php b/src/Api/Request/AuthorizationService.php old mode 100755 new mode 100644 index 4fa0af743..c4dc416ff --- a/src/Api/Request/AuthorizationService.php +++ b/src/Api/Request/AuthorizationService.php @@ -73,7 +73,12 @@ public function __construct( $this->aliasBuilder = $aliasBuilder; } - public function authorize(AuthorizationRequest $authorizationRequest) + /** + * @param AuthorizationRequest $authorizationRequest + * @return \stdClass|null + * @throws SaferPayApiException + */ + public function authorize(AuthorizationRequest $authorizationRequest): ?\stdClass { try { return $this->apiRequest->post( @@ -95,11 +100,11 @@ public function authorize(AuthorizationRequest $authorizationRequest) * @throws Exception */ public function createObjectsFromAuthorizationResponse( - $responseBody, - $saferPayOrderId, - $customerId, - $selectedCardOption - ) { + array $responseBody, + int $saferPayOrderId, + int $customerId, + int $selectedCardOption + ): AssertBody { $assertBody = $this->assertResponseObjectCreator->createAssertObject($responseBody); $this->assertBuilder->createAssert($assertBody, $saferPayOrderId); $isPaymentSafe = $assertBody->getLiability()->getLiabilityShift(); diff --git a/src/Api/Request/CancelService.php b/src/Api/Request/CancelService.php old mode 100755 new mode 100644 index f6f791ba5..40633bc0b --- a/src/Api/Request/CancelService.php +++ b/src/Api/Request/CancelService.php @@ -46,9 +46,11 @@ public function __construct(ApiRequest $apiRequest) } /** + * @param CancelRequest $cancelRequest + * @return \stdClass|null * @throws Exception */ - public function cancel(CancelRequest $cancelRequest) + public function cancel(CancelRequest $cancelRequest): ?\stdClass { return $this->apiRequest->post( self::CANCEL_API, diff --git a/src/Api/Request/CaptureService.php b/src/Api/Request/CaptureService.php old mode 100755 new mode 100644 index fb59545cd..a26192028 --- a/src/Api/Request/CaptureService.php +++ b/src/Api/Request/CaptureService.php @@ -46,9 +46,11 @@ public function __construct(ApiRequest $apiRequest) } /** + * @param CaptureRequest $captureRequest + * @return \stdClass|null * @throws Exception */ - public function capture(CaptureRequest $captureRequest) + public function capture(CaptureRequest $captureRequest): ?\stdClass { return $this->apiRequest->post( self::CAPTURE_API, diff --git a/src/Api/Request/InitializeService.php b/src/Api/Request/InitializeService.php old mode 100755 new mode 100644 index 3cee4204c..8c3e9759c --- a/src/Api/Request/InitializeService.php +++ b/src/Api/Request/InitializeService.php @@ -48,9 +48,12 @@ public function __construct(ApiRequest $apiRequest) } /** + * @param InitializeRequest $initializeRequest + * @param bool $isBusinessLicence + * @return \stdClass|null * @throws Exception */ - public function initialize(InitializeRequest $initializeRequest, $isBusinessLicence) + public function initialize(InitializeRequest $initializeRequest, bool $isBusinessLicence): ?\stdClass { $initializeApi = self::INITIALIZE_API_PAYMENT; if ($isBusinessLicence) { diff --git a/src/Api/Request/ObtainPaymentMethodsService.php b/src/Api/Request/ObtainPaymentMethodsService.php old mode 100755 new mode 100644 diff --git a/src/Api/Request/RefundService.php b/src/Api/Request/RefundService.php old mode 100755 new mode 100644 index 3cfb17960..acdb0c3d7 --- a/src/Api/Request/RefundService.php +++ b/src/Api/Request/RefundService.php @@ -46,9 +46,11 @@ public function __construct(ApiRequest $apiRequest) } /** + * @param RefundRequest $refundRequest + * @return \stdClass|null * @throws Exception */ - public function refund(RefundRequest $refundRequest) + public function refund(RefundRequest $refundRequest): ?\stdClass { return $this->apiRequest->post( self::REFUND_API, diff --git a/src/Api/Request/index.php b/src/Api/Request/index.php old mode 100755 new mode 100644 diff --git a/src/Api/index.php b/src/Api/index.php old mode 100755 new mode 100644 diff --git a/src/Builder/OrderConfirmationMessageTemplate.php b/src/Builder/OrderConfirmationMessageTemplate.php old mode 100755 new mode 100644 index 9e2cba576..e577e3364 --- a/src/Builder/OrderConfirmationMessageTemplate.php +++ b/src/Builder/OrderConfirmationMessageTemplate.php @@ -72,8 +72,9 @@ public function __construct(ModuleFactory $module) * Sets Smarty From Given Param. * * @param \Smarty $smarty + * @return void */ - public function setSmarty(\Smarty $smarty) + public function setSmarty(\Smarty $smarty): void { $this->smarty = $smarty; } @@ -82,8 +83,9 @@ public function setSmarty(\Smarty $smarty) * Sets Order Message Template Class. * * @param string $orderMessageTemplateClass + * @return void */ - public function setOrderMessageTemplateClass($orderMessageTemplateClass) + public function setOrderMessageTemplateClass(string $orderMessageTemplateClass): void { $this->orderMessageTemplateClass = $orderMessageTemplateClass; } @@ -92,8 +94,9 @@ public function setOrderMessageTemplateClass($orderMessageTemplateClass) * Sets Order Message Text. * * @param string $orderMessageText + * @return void */ - public function setOrderMessageText($orderMessageText) + public function setOrderMessageText(string $orderMessageText): void { $this->orderMessageText = $orderMessageText; } @@ -103,7 +106,7 @@ public function setOrderMessageText($orderMessageText) * * @return array */ - public function getSmartyParams() + public function getSmartyParams(): array { return [ 'orderMessageText' => $this->orderMessageText, @@ -118,7 +121,7 @@ public function getSmartyParams() * * @throws \SmartyException */ - public function getHtml() + public function getHtml(): string { $this->smarty->assign($this->getSmartyParams()); return $this->smarty->fetch( diff --git a/src/Builder/index.php b/src/Builder/index.php old mode 100755 new mode 100644 diff --git a/src/Config/SaferPayConfig.php b/src/Config/SaferPayConfig.php old mode 100755 new mode 100644 index ae7879997..e17917fb9 --- a/src/Config/SaferPayConfig.php +++ b/src/Config/SaferPayConfig.php @@ -49,7 +49,7 @@ class SaferPayConfig const RESTRICT_REFUND_AMOUNT_TO_CAPTURED_AMOUNT = 'SAFERPAY_RESTRICT_REFUND_AMOUNT_TO_CAPTURED_AMOUNT'; const CONFIGURATION_NAME = 'SAFERPAY_CONFIGURATION_NAME'; const TEST_SUFFIX = '_TEST'; - const API_VERSION = '1.45'; + const API_VERSION = '1.50'; const HOOKS = [ 'paymentOptions', @@ -71,7 +71,6 @@ class SaferPayConfig self::PAYMENT_DIRECTDEBIT, self::PAYMENT_EPRZELEWY, self::PAYMENT_EPS, - self::PAYMENT_GIROPAY, self::PAYMENT_IDEAL, self::PAYMENT_INVOICE, self::PAYMENT_JCB, @@ -79,10 +78,8 @@ class SaferPayConfig self::PAYMENT_MASTERCARD, self::PAYMENT_MYONE, self::PAYMENT_PAYPAL, - self::PAYMENT_PAYDIREKT, self::PAYMENT_POSTCARD, self::PAYMENT_POSTFINANCE, - self::PAYMENT_SOFORT, self::PAYMENT_TWINT, self::PAYMENT_VISA, self::PAYMENT_VPAY, @@ -93,6 +90,8 @@ class SaferPayConfig self::PAYMENT_CLICKTOPAY, self::PAYMENT_REKA, self::PAYMENT_CARDS, + self::PAYMENT_WERO, + self::PAYMENT_GIFTCARD, ]; const PAYMENT_ALIPAY = 'ALIPAY'; @@ -130,6 +129,8 @@ class SaferPayConfig const PAYMENT_CLICKTOPAY = 'CLICKTOPAY'; const PAYMENT_BLIK = 'BLIK'; const PAYMENT_REKA = 'REKA'; + const PAYMENT_WERO = 'WERO'; + const PAYMENT_GIFTCARD = 'GIFTCARD'; const WALLET_PAYMENT_METHODS = [ self::PAYMENT_APPLEPAY, @@ -148,14 +149,12 @@ class SaferPayConfig 'MaestroInternational' => self::PAYMENT_MAESTRO, 'Mastercard' => self::PAYMENT_MASTERCARD, 'myOne' => self::PAYMENT_MYONE, - 'paydirekt' => self::PAYMENT_PAYDIREKT, 'PayPal' => self::PAYMENT_PAYPAL, 'Twint' => self::PAYMENT_TWINT, 'Visa' => self::PAYMENT_VISA, 'Postcard' => self::PAYMENT_POSTCARD, 'BonusCard' => self::PAYMENT_BONUS, 'Lastschrift' => self::PAYMENT_LASTSCHRIFT, - 'SOFORTUEBERWEISUNG' => self::PAYMENT_SOFORT, 'AccountToAccount' => self::PAYMENT_ACCOUNTTOACCOUNT, 'Payconiq' => self::PAYMENT_PAYCONIQ, 'Cards' => self::PAYMENT_CARDS, @@ -163,6 +162,8 @@ class SaferPayConfig 'WeChatPay' => self::PAYMENT_WECHATPAY, 'Blik' => self::PAYMENT_BLIK, 'Reka' => self::PAYMENT_REKA, + 'Wero' => self::PAYMENT_WERO, + 'Giftcard' => self::PAYMENT_GIFTCARD, ]; const FIELD_SUPPORTED_PAYMENT_METHODS = [ @@ -265,7 +266,6 @@ class SaferPayConfig const FIELDS_ACCESS_TOKEN = 'SAFERPAY_FIELDS_ACCESS_TOKEN'; const FIELDS_LIBRARY = 'SAFERPAY_FIELDS_JAVASCRIPT_LIBRARY'; const FIELDS_LIBRARY_DEFAULT_VALUE = 'https://www.saferpay.com/Fields/lib/1/saferpay-fields.js'; - const FIELDS_LIBRARY_TEST_DEFAULT_VALUE = 'https://www.saferpay.com/Fields/lib/1/saferpay-fields.js'; const HOSTED_FIELDS_TEMPLATE_DEFAULT = 1; const HOSTED_FIELDS_TEMPLATE = 'SAFERPAY_HOSTED_FIELDS_TEMPLATE'; @@ -321,6 +321,7 @@ public static function supportsOrderCapture($paymentMethod) $unsupportedCapturePayments = [ self::PAYMENT_WECHATPAY, self::PAYMENT_ACCOUNTTOACCOUNT, + self::PAYMENT_GIFTCARD, ]; return !in_array($paymentMethod, $unsupportedCapturePayments); @@ -332,6 +333,7 @@ public static function supportsOrderCancel($paymentMethod) $unsupportedCancelPayments = [ self::PAYMENT_WECHATPAY, self::PAYMENT_ACCOUNTTOACCOUNT, + self::PAYMENT_GIFTCARD, ]; return !in_array($paymentMethod, $unsupportedCancelPayments); @@ -347,11 +349,12 @@ public static function isRedirectPayment($paymentMethod) self::PAYMENT_TWINT, self::PAYMENT_POSTFINANCE_PAY, self::PAYMENT_DIRECTDEBIT, - self::PAYMENT_SOFORT, self::PAYMENT_PAYPAL, self::PAYMENT_CLICKTOPAY, self::PAYMENT_BLIK, self::PAYMENT_REKA, + self::PAYMENT_WERO, + self::PAYMENT_GIFTCARD, ]; return in_array($paymentMethod, $paymentsAlwaysRedirect); @@ -376,7 +379,7 @@ public static function getFieldAccessToken() { return Configuration::get( \Invertus\SaferPay\Config\SaferPayConfig::FIELDS_ACCESS_TOKEN . - \Invertus\SaferPay\Config\SaferPayConfig::getConfigSuffix() + \Invertus\SaferPay\Config\SaferPayConfig::getConfigSuffix() ); } @@ -393,7 +396,7 @@ public static function getFieldUrl() \Invertus\SaferPay\Config\SaferPayConfig::getBaseUrl(), Configuration::get( \Invertus\SaferPay\Config\SaferPayConfig::CUSTOMER_ID . - \Invertus\SaferPay\Config\SaferPayConfig::getConfigSuffix() + \Invertus\SaferPay\Config\SaferPayConfig::getConfigSuffix() ) ); } @@ -436,8 +439,6 @@ public static function getDefaultConfiguration() SaferPayConfig::PAYMENT_BEHAVIOR_WITHOUT_3D => 1, SaferPayConfig::SAFERPAY_ALLOW_SAFERPAY_SEND_CUSTOMER_MAIL => 1, SaferPayConfig::SAFERPAY_PAYMENT_DESCRIPTION => self::SAFERPAY_PAYMENT_DESCRIPTION_DEFAULT_VALUE, - SaferPayConfig::FIELDS_LIBRARY => self::FIELDS_LIBRARY_DEFAULT_VALUE, - SaferPayConfig::FIELDS_LIBRARY . SaferPayConfig::TEST_SUFFIX => self::FIELDS_LIBRARY_TEST_DEFAULT_VALUE, self::SAFERPAY_ORDER_CREATION_AFTER_AUTHORIZATION => 0, self::TEST_MODE => 1, self::HOSTED_FIELDS_TEMPLATE => self::HOSTED_FIELDS_TEMPLATE_DEFAULT, @@ -476,8 +477,6 @@ public static function getUninstallConfiguration() self::CREDIT_CARD_SAVE, self::FIELDS_ACCESS_TOKEN, self::FIELDS_ACCESS_TOKEN . self::TEST_SUFFIX, - self::FIELDS_LIBRARY, - self::FIELDS_LIBRARY . self::TEST_SUFFIX, self::SAFERPAY_ORDER_CREATION_AFTER_AUTHORIZATION, self::SAFERPAY_SEND_ORDER_CONF_MAIL, self::SAFERPAY_GROUP_CARDS, diff --git a/src/Config/index.php b/src/Config/index.php old mode 100755 new mode 100644 diff --git a/src/Controller/AbstractSaferPayController.php b/src/Controller/AbstractSaferPayController.php old mode 100755 new mode 100644 diff --git a/src/Controller/index.php b/src/Controller/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/Address.php b/src/DTO/Request/Address.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/Assert/AssertRequest.php b/src/DTO/Request/Assert/AssertRequest.php old mode 100755 new mode 100644 index 3caa6884d..860d4f654 --- a/src/DTO/Request/Assert/AssertRequest.php +++ b/src/DTO/Request/Assert/AssertRequest.php @@ -24,14 +24,13 @@ namespace Invertus\SaferPay\DTO\Request\Assert; use Invertus\SaferPay\DTO\Request\RequestHeader; +use Invertus\SaferPay\DTO\Request\SaferPayRequestInterface; if (!defined('_PS_VERSION_')) { exit; } -// TODO: A lot of these request are the same, we can at least put them under an interface - -class AssertRequest +class AssertRequest implements SaferPayRequestInterface { /** diff --git a/src/DTO/Request/Assert/index.php b/src/DTO/Request/Assert/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/AssertRefund/AssertRefundRequest.php b/src/DTO/Request/AssertRefund/AssertRefundRequest.php old mode 100755 new mode 100644 index 80a2b8e96..ac12f85e9 --- a/src/DTO/Request/AssertRefund/AssertRefundRequest.php +++ b/src/DTO/Request/AssertRefund/AssertRefundRequest.php @@ -24,12 +24,13 @@ namespace Invertus\SaferPay\DTO\Request\AssertRefund; use Invertus\SaferPay\DTO\Request\RequestHeader; +use Invertus\SaferPay\DTO\Request\SaferPayRequestInterface; if (!defined('_PS_VERSION_')) { exit; } -class AssertRefundRequest +class AssertRefundRequest implements SaferPayRequestInterface { /** diff --git a/src/DTO/Request/AssertRefund/index.php b/src/DTO/Request/AssertRefund/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/Authorization/AuthorizationRequest.php b/src/DTO/Request/Authorization/AuthorizationRequest.php old mode 100755 new mode 100644 index aaf4d5b52..42ce3eb20 --- a/src/DTO/Request/Authorization/AuthorizationRequest.php +++ b/src/DTO/Request/Authorization/AuthorizationRequest.php @@ -24,12 +24,13 @@ namespace Invertus\SaferPay\DTO\Request\Authorization; use Invertus\SaferPay\DTO\Request\RequestHeader; +use Invertus\SaferPay\DTO\Request\SaferPayRequestInterface; if (!defined('_PS_VERSION_')) { exit; } -class AuthorizationRequest +class AuthorizationRequest implements SaferPayRequestInterface { /** diff --git a/src/DTO/Request/Authorization/index.php b/src/DTO/Request/Authorization/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/Cancel/CancelRequest.php b/src/DTO/Request/Cancel/CancelRequest.php old mode 100755 new mode 100644 index e6543d15d..bae87bd25 --- a/src/DTO/Request/Cancel/CancelRequest.php +++ b/src/DTO/Request/Cancel/CancelRequest.php @@ -24,12 +24,13 @@ namespace Invertus\SaferPay\DTO\Request\Cancel; use Invertus\SaferPay\DTO\Request\RequestHeader; +use Invertus\SaferPay\DTO\Request\SaferPayRequestInterface; if (!defined('_PS_VERSION_')) { exit; } -class CancelRequest +class CancelRequest implements SaferPayRequestInterface { /** diff --git a/src/DTO/Request/Cancel/index.php b/src/DTO/Request/Cancel/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/Capture/CaptureRequest.php b/src/DTO/Request/Capture/CaptureRequest.php old mode 100755 new mode 100644 index 6d3c6da86..baddaaedf --- a/src/DTO/Request/Capture/CaptureRequest.php +++ b/src/DTO/Request/Capture/CaptureRequest.php @@ -25,12 +25,13 @@ use Invertus\SaferPay\DTO\Request\Payment; use Invertus\SaferPay\DTO\Request\RequestHeader; +use Invertus\SaferPay\DTO\Request\SaferPayRequestInterface; if (!defined('_PS_VERSION_')) { exit; } -class CaptureRequest +class CaptureRequest implements SaferPayRequestInterface { /** * @var RequestHeader diff --git a/src/DTO/Request/Capture/index.php b/src/DTO/Request/Capture/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/DeliveryAddressForm.php b/src/DTO/Request/DeliveryAddressForm.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/Initialize/InitializeRequest.php b/src/DTO/Request/Initialize/InitializeRequest.php old mode 100755 new mode 100644 index 4b96a984f..17cae436f --- a/src/DTO/Request/Initialize/InitializeRequest.php +++ b/src/DTO/Request/Initialize/InitializeRequest.php @@ -33,12 +33,13 @@ use Invertus\SaferPay\DTO\Request\RequestHeader; use Invertus\SaferPay\DTO\Request\ReturnUrl; use Invertus\SaferPay\DTO\Request\SaferPayNotification; +use Invertus\SaferPay\DTO\Request\SaferPayRequestInterface; if (!defined('_PS_VERSION_')) { exit; } -class InitializeRequest +class InitializeRequest implements SaferPayRequestInterface { /** diff --git a/src/DTO/Request/Initialize/index.php b/src/DTO/Request/Initialize/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/ObtainPaymentMethods/ObtainPaymentMethodsRequest.php b/src/DTO/Request/ObtainPaymentMethods/ObtainPaymentMethodsRequest.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/Order.php b/src/DTO/Request/Order.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/OrderItem.php b/src/DTO/Request/OrderItem.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/Payer.php b/src/DTO/Request/Payer.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/PayerProfile.php b/src/DTO/Request/PayerProfile.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/Payment.php b/src/DTO/Request/Payment.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/PendingNotification.php b/src/DTO/Request/PendingNotification.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/Refund/RefundRequest.php b/src/DTO/Request/Refund/RefundRequest.php old mode 100755 new mode 100644 index 864c5e1f8..72daf3c57 --- a/src/DTO/Request/Refund/RefundRequest.php +++ b/src/DTO/Request/Refund/RefundRequest.php @@ -27,13 +27,14 @@ use Invertus\SaferPay\DTO\Request\Payment; use Invertus\SaferPay\DTO\Request\PendingNotification; use Invertus\SaferPay\DTO\Request\RequestHeader; +use Invertus\SaferPay\DTO\Request\SaferPayRequestInterface; use Configuration; if (!defined('_PS_VERSION_')) { exit; } -class RefundRequest +class RefundRequest implements SaferPayRequestInterface { /** diff --git a/src/DTO/Request/Refund/index.php b/src/DTO/Request/Refund/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/RequestHeader.php b/src/DTO/Request/RequestHeader.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/ReturnUrl.php b/src/DTO/Request/ReturnUrl.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/SaferPayNotification.php b/src/DTO/Request/SaferPayNotification.php old mode 100755 new mode 100644 diff --git a/src/DTO/Request/SaferPayRequestInterface.php b/src/DTO/Request/SaferPayRequestInterface.php new file mode 100644 index 000000000..5df3abe91 --- /dev/null +++ b/src/DTO/Request/SaferPayRequestInterface.php @@ -0,0 +1,36 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +namespace Invertus\SaferPay\DTO\Request; + +if (!defined('_PS_VERSION_')) { + exit; +} + +interface SaferPayRequestInterface +{ + /** + * @return array + */ + public function getAsArray(); +} diff --git a/src/DTO/Request/index.php b/src/DTO/Request/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Amount.php b/src/DTO/Response/Amount.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Assert/AssertBody.php b/src/DTO/Response/Assert/AssertBody.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Assert/index.php b/src/DTO/Response/Assert/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/AssertRefund/AssertRefundBody.php b/src/DTO/Response/AssertRefund/AssertRefundBody.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/AssertRefund/index.php b/src/DTO/Response/AssertRefund/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Authorization/AuthorizationBody.php b/src/DTO/Response/Authorization/AuthorizationBody.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Authorization/index.php b/src/DTO/Response/Authorization/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Brand.php b/src/DTO/Response/Brand.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Card.php b/src/DTO/Response/Card.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Dcc.php b/src/DTO/Response/Dcc.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/DeliveryAddress.php b/src/DTO/Response/DeliveryAddress.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/FraudFree.php b/src/DTO/Response/FraudFree.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Initialize/InitializeBody.php b/src/DTO/Response/Initialize/InitializeBody.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Initialize/index.php b/src/DTO/Response/Initialize/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Liability.php b/src/DTO/Response/Liability.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Payer.php b/src/DTO/Response/Payer.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/PaymentMeans.php b/src/DTO/Response/PaymentMeans.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/RegistrationResult.php b/src/DTO/Response/RegistrationResult.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/ResponseHeader.php b/src/DTO/Response/ResponseHeader.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/ThreeDs.php b/src/DTO/Response/ThreeDs.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/Transaction.php b/src/DTO/Response/Transaction.php old mode 100755 new mode 100644 diff --git a/src/DTO/Response/index.php b/src/DTO/Response/index.php old mode 100755 new mode 100644 diff --git a/src/DTO/index.php b/src/DTO/index.php old mode 100755 new mode 100644 diff --git a/src/Entity/SaferPayAssert.php b/src/Entity/SaferPayAssert.php old mode 100755 new mode 100644 diff --git a/src/Entity/SaferPayAssertRefund.php b/src/Entity/SaferPayAssertRefund.php old mode 100755 new mode 100644 diff --git a/src/Entity/SaferPayCardAlias.php b/src/Entity/SaferPayCardAlias.php old mode 100755 new mode 100644 diff --git a/src/Entity/SaferPayCountry.php b/src/Entity/SaferPayCountry.php old mode 100755 new mode 100644 diff --git a/src/Entity/SaferPayCurrency.php b/src/Entity/SaferPayCurrency.php old mode 100755 new mode 100644 diff --git a/src/Entity/SaferPayField.php b/src/Entity/SaferPayField.php old mode 100755 new mode 100644 diff --git a/src/Entity/SaferPayLog.php b/src/Entity/SaferPayLog.php old mode 100755 new mode 100644 diff --git a/src/Entity/SaferPayLogo.php b/src/Entity/SaferPayLogo.php old mode 100755 new mode 100644 diff --git a/src/Entity/SaferPayOrder.php b/src/Entity/SaferPayOrder.php old mode 100755 new mode 100644 diff --git a/src/Entity/SaferPayOrderRefund.php b/src/Entity/SaferPayOrderRefund.php old mode 100755 new mode 100644 diff --git a/src/Entity/SaferPayPayment.php b/src/Entity/SaferPayPayment.php old mode 100755 new mode 100644 diff --git a/src/Entity/index.php b/src/Entity/index.php old mode 100755 new mode 100644 diff --git a/src/EntityBuilder/SaferPayAssertBuilder.php b/src/EntityBuilder/SaferPayAssertBuilder.php old mode 100755 new mode 100644 index cc6c62180..c9ce9eb0b --- a/src/EntityBuilder/SaferPayAssertBuilder.php +++ b/src/EntityBuilder/SaferPayAssertBuilder.php @@ -34,12 +34,12 @@ class SaferPayAssertBuilder { /** * @param AssertBody $assertBody - * @param $saferPayOrderId + * @param int $saferPayOrderId * * @return SaferPayAssert * @throws \Exception */ - public function createAssert(AssertBody $assertBody, $saferPayOrderId) + public function createAssert(AssertBody $assertBody, int $saferPayOrderId): SaferPayAssert { $assert = new SaferPayAssert(); diff --git a/src/EntityBuilder/SaferPayCardAliasBuilder.php b/src/EntityBuilder/SaferPayCardAliasBuilder.php old mode 100755 new mode 100644 diff --git a/src/EntityBuilder/SaferPayOrderBuilder.php b/src/EntityBuilder/SaferPayOrderBuilder.php old mode 100755 new mode 100644 index cca57f36b..ba6749354 --- a/src/EntityBuilder/SaferPayOrderBuilder.php +++ b/src/EntityBuilder/SaferPayOrderBuilder.php @@ -34,7 +34,14 @@ class SaferPayOrderBuilder { - public function create($body, $cartId, $customerId, $isTransaction) + /** + * @param object $body + * @param int $cartId + * @param int $customerId + * @param bool $isTransaction + * @return SaferPayOrder + */ + public function create($body, int $cartId, int $customerId, bool $isTransaction): SaferPayOrder { if (method_exists('Order', 'getIdByCartId')) { $orderId = Order::getIdByCartId($cartId); @@ -56,7 +63,14 @@ public function create($body, $cartId, $customerId, $isTransaction) return $saferPayOrder; } - public function createDirectOrder($body, Cart $cart, Customer $customer, $isTransaction) + /** + * @param object $body + * @param Cart $cart + * @param Customer $customer + * @param bool $isTransaction + * @return SaferPayOrder + */ + public function createDirectOrder($body, Cart $cart, Customer $customer, bool $isTransaction): SaferPayOrder { $orderId = Order::getOrderByCartId($cart->id); $saferPayOrder = new SaferPayOrder(); @@ -75,7 +89,7 @@ public function createDirectOrder($body, Cart $cart, Customer $customer, $isTran * * @return string */ - private function getRedirectionUrl($initializeBody) + private function getRedirectionUrl($initializeBody): string { if (isset($initializeBody->RedirectUrl)) { return $initializeBody->RedirectUrl; diff --git a/src/EntityBuilder/index.php b/src/EntityBuilder/index.php old mode 100755 new mode 100644 diff --git a/src/Enum/ControllerName.php b/src/Enum/ControllerName.php old mode 100755 new mode 100644 diff --git a/src/Enum/GenderEnum.php b/src/Enum/GenderEnum.php old mode 100755 new mode 100644 diff --git a/src/Enum/PaymentType.php b/src/Enum/PaymentType.php old mode 100755 new mode 100644 diff --git a/src/Enum/index.php b/src/Enum/index.php old mode 100755 new mode 100644 diff --git a/src/Exception/Api/SaferPayApiException.php b/src/Exception/Api/SaferPayApiException.php old mode 100755 new mode 100644 diff --git a/src/Exception/Api/index.php b/src/Exception/Api/index.php old mode 100755 new mode 100644 diff --git a/src/Exception/Restriction/RestrictionException.php b/src/Exception/Restriction/RestrictionException.php old mode 100755 new mode 100644 diff --git a/src/Exception/Restriction/WrongRestrictionTypeException.php b/src/Exception/Restriction/WrongRestrictionTypeException.php old mode 100755 new mode 100644 diff --git a/src/Exception/Restriction/index.php b/src/Exception/Restriction/index.php old mode 100755 new mode 100644 diff --git a/src/Exception/index.php b/src/Exception/index.php old mode 100755 new mode 100644 diff --git a/src/Factory/ModuleFactory.php b/src/Factory/ModuleFactory.php old mode 100755 new mode 100644 diff --git a/src/Install/AbstractInstaller.php b/src/Install/AbstractInstaller.php old mode 100755 new mode 100644 diff --git a/src/Install/Installer.php b/src/Install/Installer.php old mode 100755 new mode 100644 index 5523a22b3..1cdfce80d --- a/src/Install/Installer.php +++ b/src/Install/Installer.php @@ -223,7 +223,9 @@ private function installSaferPayOrderTable() `refunded` tinyint(1) DEFAULT 0, `canceled` tinyint(1) DEFAULT 0, `authorized` tinyint(1) DEFAULT 0, - `pending` tinyint(1) DEFAULT 0 + `pending` tinyint(1) DEFAULT 0, + INDEX `idx_token` (`token`), + INDEX `idx_status` (`captured`, `refunded`, `canceled`, `authorized`, `pending`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' ); } @@ -254,7 +256,13 @@ private function installSaferPayAssertTable() `card_number` VARCHAR(64) NOT NULL, `dcc_value` INTEGER(32) DEFAULT NULL, `dcc_currency_code` VARCHAR(64) DEFAULT NULL, - `authorized` tinyint(1) DEFAULT 0 + `authorized` tinyint(1) DEFAULT 0, + INDEX `idx_status` (`status`), + INDEX `idx_payment_id` (`payment_id`), + INDEX `idx_merchant_reference` (`merchant_reference`), + INDEX `idx_authorized` (`authorized`), + INDEX `idx_currency_code` (`currency_code`), + INDEX `idx_order_status` (`id_saferpay_order`, `status`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' ); } @@ -272,7 +280,10 @@ private function installSaferPayCardAlias() `payment_method` VARCHAR(64) NOT NULL, `valid_till` datetime NOT NULL, `date_add` datetime NOT NULL, - `date_upd` datetime NOT NULL + `date_upd` datetime NOT NULL, + INDEX `idx_success` (`success`), + INDEX `idx_customer_success` (`id_customer`, `success`), + INDEX `idx_customer_valid_till` (`id_customer`, `valid_till`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' ); } @@ -304,7 +315,11 @@ private function installOrderRefundTable() `transaction_id` VARCHAR(64) NOT NULL, `amount` INTEGER(20) NOT NULL, `currency` VARCHAR(64) NOT NULL, - `status` VARCHAR(64) NOT NULL + `status` VARCHAR(64) NOT NULL, + INDEX `idx_status` (`status`), + INDEX `idx_currency` (`currency`), + INDEX `idx_order_status` (`id_order`, `status`), + INDEX `idx_saferpay_order_status` (`id_saferpay_order`, `status`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci' ); } diff --git a/src/Install/Uninstaller.php b/src/Install/Uninstaller.php old mode 100755 new mode 100644 diff --git a/src/Install/index.php b/src/Install/index.php old mode 100755 new mode 100644 diff --git a/src/Presentation/Loader/PaymentFormAssetLoader.php b/src/Presentation/Loader/PaymentFormAssetLoader.php old mode 100755 new mode 100644 diff --git a/src/Presenter/AdminOrderPagePresenter.php b/src/Presenter/AdminOrderPagePresenter.php old mode 100755 new mode 100644 diff --git a/src/Presenter/AssertPresenter.php b/src/Presenter/AssertPresenter.php old mode 100755 new mode 100644 index 2e46e42ad..f2cc84e60 --- a/src/Presenter/AssertPresenter.php +++ b/src/Presenter/AssertPresenter.php @@ -45,7 +45,11 @@ public function __construct(SaferPayOfficial $saferPay) $this->saferPay = $saferPay; } - public function present(SaferPayAssert $assert) + /** + * @param SaferPayAssert $assert + * @return array + */ + public function present(SaferPayAssert $assert): array { $paymentMethod = $assert->payment_method; diff --git a/src/Presenter/index.php b/src/Presenter/index.php old mode 100755 new mode 100644 diff --git a/src/Provider/CurrencyProvider.php b/src/Provider/CurrencyProvider.php index 0c5be18ba..6954508c1 100644 --- a/src/Provider/CurrencyProvider.php +++ b/src/Provider/CurrencyProvider.php @@ -30,7 +30,10 @@ } class CurrencyProvider { - public function getAllCurrenciesInArray() + /** + * @return array + */ + public function getAllCurrenciesInArray(): array { $currencies = []; diff --git a/src/Provider/PaymentRedirectionProvider.php b/src/Provider/PaymentRedirectionProvider.php old mode 100755 new mode 100644 diff --git a/src/Provider/PaymentRestrictionProvider.php b/src/Provider/PaymentRestrictionProvider.php old mode 100755 new mode 100644 diff --git a/src/Provider/PaymentRestrictionProviderInterface.php b/src/Provider/PaymentRestrictionProviderInterface.php old mode 100755 new mode 100644 diff --git a/src/Provider/PaymentTypeProvider.php b/src/Provider/PaymentTypeProvider.php old mode 100755 new mode 100644 index 1625c0578..88eb1ac39 --- a/src/Provider/PaymentTypeProvider.php +++ b/src/Provider/PaymentTypeProvider.php @@ -44,10 +44,9 @@ public function __construct( /** * @param string $paymentMethod - * * @return string */ - public function get($paymentMethod) + public function get(string $paymentMethod): string { if ($this->isHostedIframeRedirect($paymentMethod)) { return PaymentType::HOSTED_IFRAME; @@ -62,10 +61,9 @@ public function get($paymentMethod) /** * @param string $paymentMethod - * * @return bool */ - private function isIframeRedirect($paymentMethod) + private function isIframeRedirect(string $paymentMethod): bool { if (!in_array($paymentMethod, SaferPayConfig::TRANSACTION_METHODS)) { return false; @@ -80,10 +78,9 @@ private function isIframeRedirect($paymentMethod) /** * @param string $paymentMethod - * * @return bool */ - private function isHostedIframeRedirect($paymentMethod) + private function isHostedIframeRedirect(string $paymentMethod): bool { if (!$this->saferPayFieldRepository->isActiveByName($paymentMethod)) { return false; diff --git a/src/Provider/index.php b/src/Provider/index.php old mode 100755 new mode 100644 diff --git a/src/Repository/AbstractRepository.php b/src/Repository/AbstractRepository.php old mode 100755 new mode 100644 diff --git a/src/Repository/OrderRepository.php b/src/Repository/OrderRepository.php old mode 100755 new mode 100644 diff --git a/src/Repository/OrderRepositoryInterface.php b/src/Repository/OrderRepositoryInterface.php old mode 100755 new mode 100644 diff --git a/src/Repository/ReadOnlyRepositoryInterface.php b/src/Repository/ReadOnlyRepositoryInterface.php old mode 100755 new mode 100644 diff --git a/src/Repository/SaferPayCardAliasRepository.php b/src/Repository/SaferPayCardAliasRepository.php old mode 100755 new mode 100644 index d1664313e..70fb0da73 --- a/src/Repository/SaferPayCardAliasRepository.php +++ b/src/Repository/SaferPayCardAliasRepository.php @@ -37,7 +37,7 @@ public function getSavedValidCardsByUserIdAndPaymentMethod($userId, $paymentMeth $query = new DbQuery(); $query->select('`id_saferpay_card_alias`, `card_number`'); $query->from('saferpay_card_alias'); - $query->where('id_customer = "' . (int) $userId . '"'); + $query->where('id_customer = ' . (int) $userId); $query->where('payment_method = "' . pSQL($paymentMethod) . '"'); $query->where('valid_till > "' . pSQL($currentDate) . '"'); @@ -49,7 +49,7 @@ public function getSavedCardAliasFromId($id) $query = new DbQuery(); $query->select('`alias_id`'); $query->from('saferpay_card_alias'); - $query->where('id_saferpay_card_alias = "' . (int) $id . '"'); + $query->where('id_saferpay_card_alias = ' . (int) $id); return Db::getInstance()->getValue($query); } @@ -59,7 +59,7 @@ public function getSavedCardIdByCustomerIdAndAliasId($customerId, $aliasId) $query = new DbQuery(); $query->select('`id_saferpay_card_alias`'); $query->from('saferpay_card_alias'); - $query->where('id_customer = "' . (int) $customerId . '"'); + $query->where('id_customer = ' . (int) $customerId); $query->where('alias_id = "' . pSQL($aliasId) . '"'); return Db::getInstance()->getValue($query); @@ -70,7 +70,7 @@ public function getSavedCardsByCustomerId($customerId) $query = new DbQuery(); $query->select('*'); $query->from('saferpay_card_alias'); - $query->where('id_customer = "' . (int) $customerId . '"'); + $query->where('id_customer = ' . (int) $customerId); return Db::getInstance()->executeS($query); } diff --git a/src/Repository/SaferPayFieldRepository.php b/src/Repository/SaferPayFieldRepository.php old mode 100755 new mode 100644 diff --git a/src/Repository/SaferPayLogoRepository.php b/src/Repository/SaferPayLogoRepository.php old mode 100755 new mode 100644 diff --git a/src/Repository/SaferPayOrderRepository.php b/src/Repository/SaferPayOrderRepository.php old mode 100755 new mode 100644 index 921a401f4..095d31791 --- a/src/Repository/SaferPayOrderRepository.php +++ b/src/Repository/SaferPayOrderRepository.php @@ -36,67 +36,84 @@ class SaferPayOrderRepository /** * @param int $orderId - * * @return SaferPayOrder */ - public function getByOrderId($orderId) + public function getByOrderId(int $orderId): SaferPayOrder { return new SaferPayOrder($this->getIdByOrderId($orderId)); } - public function getIdByOrderId($orderId) + /** + * @param int $orderId + * @return false|string|null + */ + public function getIdByOrderId(int $orderId) { $query = new DbQuery(); $query->select('`id_saferpay_order`'); $query->from('saferpay_order'); - $query->where('id_order = "' . (int) $orderId . '"'); + $query->where('id_order = ' . (int) $orderId); $query->orderBy('`id_saferpay_order` DESC'); return Db::getInstance()->getValue($query); } - public function getIdByCartId($cartId) + /** + * @param int $cartId + * @return false|string|null + */ + public function getIdByCartId(int $cartId) { $query = new DbQuery(); $query->select('`id_saferpay_order`'); $query->from('saferpay_order'); - $query->where('id_cart = "' . (int) $cartId . '"'); + $query->where('id_cart = ' . (int) $cartId); $query->orderBy('`id_saferpay_order` DESC'); return Db::getInstance()->getValue($query); } - public function getAssertIdBySaferPayOrderId($saferPayOrderId) + + /** + * @param int $saferPayOrderId + * @return false|string|null + */ + public function getAssertIdBySaferPayOrderId(int $saferPayOrderId) { $query = new DbQuery(); $query->select('`id_saferpay_assert`'); $query->from('saferpay_assert'); - $query->where('id_saferPay_order = "' . (int) $saferPayOrderId . '"'); + $query->where('id_saferPay_order = ' . (int) $saferPayOrderId); $query->orderBy('id_saferpay_assert DESC'); return Db::getInstance()->getValue($query); } - /*** - * @param $saferPayOrderId + /** + * @param int $saferPayOrderId * @return array * @throws \PrestaShopDatabaseException */ - public function getOrderRefunds($saferPayOrderId) + public function getOrderRefunds(int $saferPayOrderId): array { $query = new DbQuery(); $query->select('*'); $query->from('saferpay_order_refund'); - $query->where('id_saferPay_order = "' . (int) $saferPayOrderId . '"'); + $query->where('id_saferPay_order = ' . (int) $saferPayOrderId); + $query->orderBy('id_saferpay_order_refund DESC'); return Db::getInstance()->executeS($query); } - public function getPaymentBrandBySaferpayOrderId($saferpayOrderId) + /** + * @param int $saferpayOrderId + * @return false|string|null + */ + public function getPaymentBrandBySaferpayOrderId(int $saferpayOrderId) { $query = new DbQuery(); $query->select('`brand`'); $query->from('saferpay_assert'); - $query->where('id_saferpay_order = "' . (int) $saferpayOrderId . '"'); + $query->where('id_saferpay_order = ' . (int) $saferpayOrderId); return Db::getInstance()->getValue($query); } diff --git a/src/Repository/SaferPayPaymentRepository.php b/src/Repository/SaferPayPaymentRepository.php old mode 100755 new mode 100644 diff --git a/src/Repository/SaferPayRestrictionRepository.php b/src/Repository/SaferPayRestrictionRepository.php old mode 100755 new mode 100644 diff --git a/src/Repository/SaferPaySavedCreditCardRepository.php b/src/Repository/SaferPaySavedCreditCardRepository.php old mode 100755 new mode 100644 diff --git a/src/Repository/index.php b/src/Repository/index.php old mode 100755 new mode 100644 diff --git a/src/Service/CartDuplicationService.php b/src/Service/CartDuplicationService.php old mode 100755 new mode 100644 diff --git a/src/Service/LegacyTranslator.php b/src/Service/LegacyTranslator.php old mode 100755 new mode 100644 index 82bc605a2..3bd472465 --- a/src/Service/LegacyTranslator.php +++ b/src/Service/LegacyTranslator.php @@ -45,12 +45,19 @@ public function __construct(ModuleFactory $module) $this->module = $module->getModule(); } - public function translate($key) + /** + * @param string $key + * @return string + */ + public function translate(string $key): string { return isset($this->getTranslations()[$key]) ? $this->getTranslations()[$key] : $key; } - private function getTranslations() + /** + * @return array + */ + private function getTranslations(): array { return [ SaferPayConfig::PAYMENT_ALIPAY => $this->module->l('Alipay', self::FILE_NAME), @@ -60,17 +67,14 @@ private function getTranslations() SaferPayConfig::PAYMENT_DIRECTDEBIT => $this->module->l('Directdebit', self::FILE_NAME), SaferPayConfig::PAYMENT_EPRZELEWY => $this->module->l('Eprzelewy', self::FILE_NAME), SaferPayConfig::PAYMENT_EPS => $this->module->l('Eps', self::FILE_NAME), - SaferPayConfig::PAYMENT_GIROPAY => $this->module->l('Giropay', self::FILE_NAME), SaferPayConfig::PAYMENT_IDEAL => $this->module->l('Ideal', self::FILE_NAME), SaferPayConfig::PAYMENT_INVOICE => $this->module->l('Invoice', self::FILE_NAME), SaferPayConfig::PAYMENT_JCB => $this->module->l('Jcb', self::FILE_NAME), SaferPayConfig::PAYMENT_MAESTRO => $this->module->l('Maestro', self::FILE_NAME), SaferPayConfig::PAYMENT_MASTERCARD => $this->module->l('Mastercard', self::FILE_NAME), SaferPayConfig::PAYMENT_MYONE => $this->module->l('Myone', self::FILE_NAME), - SaferPayConfig::PAYMENT_PAYDIREKT => $this->module->l('Paydirect', self::FILE_NAME), SaferPayConfig::PAYMENT_POSTCARD => $this->module->l('Postcard', self::FILE_NAME), SaferPayConfig::PAYMENT_POSTFINANCE => $this->module->l('Postfinance', self::FILE_NAME), - SaferPayConfig::PAYMENT_SOFORT => $this->module->l('Sofort', self::FILE_NAME), SaferPayConfig::PAYMENT_TWINT => $this->module->l('Twint', self::FILE_NAME), SaferPayConfig::PAYMENT_VISA => $this->module->l('Visa', self::FILE_NAME), SaferPayConfig::PAYMENT_VPAY => $this->module->l('Vpay', self::FILE_NAME), @@ -85,6 +89,8 @@ private function getTranslations() SaferPayConfig::PAYMENT_GOOGLEPAY => $this->module->l('Googlepay'), SaferPayConfig::PAYMENT_CLICKTOPAY => $this->module->l('Clicktopay', self::FILE_NAME), SaferPayConfig::PAYMENT_REKA => $this->module->l('Reka', self::FILE_NAME), + SaferPayConfig::PAYMENT_WERO => $this->module->l('Wero', self::FILE_NAME), + SaferPayConfig::PAYMENT_GIFTCARD => $this->module->l('Giftcard', self::FILE_NAME), ]; } } diff --git a/src/Service/PaymentRestrictionValidation.php b/src/Service/PaymentRestrictionValidation.php old mode 100755 new mode 100644 diff --git a/src/Service/PaymentRestrictionValidation/ApplePayPaymentRestrictionValidation.php b/src/Service/PaymentRestrictionValidation/ApplePayPaymentRestrictionValidation.php old mode 100755 new mode 100644 index 6dc84419c..d24428ef9 --- a/src/Service/PaymentRestrictionValidation/ApplePayPaymentRestrictionValidation.php +++ b/src/Service/PaymentRestrictionValidation/ApplePayPaymentRestrictionValidation.php @@ -43,17 +43,20 @@ public function __construct(LegacyContext $context) } /** - * @inheritDoc + * @inheritdoc + * @param string $paymentName + * @return bool */ - public function isValid($paymentName) + public function isValid(string $paymentName): bool { return $this->isIosDevice() || $this->isMacDesktop(); } /** - * @inheritdoc + * @param string $paymentName + * @return bool */ - public function supports($paymentName) + public function supports(string $paymentName): bool { return \Tools::strtoupper($paymentName) == SaferPayConfig::PAYMENT_APPLEPAY; } @@ -63,7 +66,7 @@ public function supports($paymentName) * * @return bool */ - private function isIosDevice() + private function isIosDevice(): bool { if (SaferPayConfig::isTestMode()) { return true; @@ -72,7 +75,10 @@ private function isIosDevice() return (bool) $this->context->getMobileDetect()->is('ios'); } - private function isMacDesktop() + /** + * @return bool + */ + private function isMacDesktop(): bool { if (SaferPayConfig::isTestMode()) { return true; diff --git a/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php b/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php old mode 100755 new mode 100644 index 0a3985d19..f664ae2ba --- a/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php +++ b/src/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidation.php @@ -70,8 +70,10 @@ public function __construct( /** * @inheritDoc + * @param string $paymentName + * @return bool */ - public function isValid($paymentName) + public function isValid(string $paymentName): bool { if ($paymentName === SaferPayConfig::PAYMENT_CARDS) { return true; @@ -94,8 +96,10 @@ public function isValid($paymentName) /** * @inheritDoc + * @param string $paymentName + * @return bool */ - public function supports($paymentName) + public function supports(string $paymentName): bool { return true; } diff --git a/src/Service/PaymentRestrictionValidation/KlarnaPaymentRestrictionValidation.php b/src/Service/PaymentRestrictionValidation/KlarnaPaymentRestrictionValidation.php old mode 100755 new mode 100644 index 89e2be015..1431b3606 --- a/src/Service/PaymentRestrictionValidation/KlarnaPaymentRestrictionValidation.php +++ b/src/Service/PaymentRestrictionValidation/KlarnaPaymentRestrictionValidation.php @@ -41,8 +41,10 @@ public function __construct(LegacyContext $context) /** * @inheritdoc + * @param string $paymentName + * @return bool */ - public function isValid($paymentName) + public function isValid(string $paymentName): bool { if (!$this->isContextCountryCodeSupported()) { return false; @@ -55,7 +57,11 @@ public function isValid($paymentName) return true; } - public function supports($paymentName) + /** + * @param string $paymentName + * @return bool + */ + public function supports(string $paymentName): bool { return \Tools::strtoupper($paymentName) == SaferPayConfig::PAYMENT_KLARNA; } diff --git a/src/Service/PaymentRestrictionValidation/PaymentRestrictionValidationInterface.php b/src/Service/PaymentRestrictionValidation/PaymentRestrictionValidationInterface.php old mode 100755 new mode 100644 index 313439f95..5883a698c --- a/src/Service/PaymentRestrictionValidation/PaymentRestrictionValidationInterface.php +++ b/src/Service/PaymentRestrictionValidation/PaymentRestrictionValidationInterface.php @@ -33,17 +33,15 @@ interface PaymentRestrictionValidationInterface * Returns if payment is valid * * @param string $paymentName - * * @return bool */ - public function isValid($paymentName); + public function isValid(string $paymentName): bool; /** * Returns if payment restriction validator is supported by payment name * * @param string $paymentName - * * @return bool */ - public function supports($paymentName); + public function supports(string $paymentName): bool; } diff --git a/src/Service/PaymentRestrictionValidation/index.php b/src/Service/PaymentRestrictionValidation/index.php old mode 100755 new mode 100644 diff --git a/src/Service/Request/AssertRefundRequestObjectCreator.php b/src/Service/Request/AssertRefundRequestObjectCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/Request/AssertRequestObjectCreator.php b/src/Service/Request/AssertRequestObjectCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/Request/AuthorizationRequestObjectCreator.php b/src/Service/Request/AuthorizationRequestObjectCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/Request/CancelRequestObjectCreator.php b/src/Service/Request/CancelRequestObjectCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/Request/CaptureRequestObjectCreator.php b/src/Service/Request/CaptureRequestObjectCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/Request/InitializeRequestObjectCreator.php b/src/Service/Request/InitializeRequestObjectCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/Request/ObtainPaymentMethodsObjectCreator.php b/src/Service/Request/ObtainPaymentMethodsObjectCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/Request/RefundRequestObjectCreator.php b/src/Service/Request/RefundRequestObjectCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/Request/RequestObjectCreator.php b/src/Service/Request/RequestObjectCreator.php old mode 100755 new mode 100644 index 6e961489f..d1f2e65d1 --- a/src/Service/Request/RequestObjectCreator.php +++ b/src/Service/Request/RequestObjectCreator.php @@ -70,8 +70,10 @@ class RequestObjectCreator */ private $orderRepository; - //TODO extract logic to appropriate services. - /** @var IdempotencyProviderInterface */ + /** + * @NOTE: Consider splitting this class into focused services (AddressBuilder, PaymentBuilder, etc.) + * @var IdempotencyProviderInterface + */ private $idempotencyProvider; public function __construct( @@ -86,7 +88,7 @@ public function __construct( $this->idempotencyProvider = $idempotencyProvider; } - public function createRequestHeader() + public function createRequestHeader(): RequestHeader { $specVersion = Configuration::get(RequestHeader::SPEC_VERSION); $customerId = Configuration::get(RequestHeader::CUSTOMER_ID . SaferPayConfig::getConfigSuffix()); @@ -105,7 +107,7 @@ public function createRequestHeader() * @return Payment|null * @throws \PrestaShopException */ - public function createPayment(Cart $cart, $totalPrice) + public function createPayment(Cart $cart, string $totalPrice): ?Payment { $currency = \Currency::getCurrency($cart->id_currency); /** @var \Order|null $order */ @@ -130,29 +132,29 @@ public function createPayment(Cart $cart, $totalPrice) return $payment; } - public function createReturnUrl($returnUrl) + public function createReturnUrl(string $returnUrl): ReturnUrl { return new ReturnUrl($returnUrl); } - public function createNotification($customerEmail, $notifyUrl) + public function createNotification(string $customerEmail, string $notifyUrl): SaferPayNotification { $payerEmail = $customerEmail; $merchantEmail = Configuration::get(SaferPayConfig::MERCHANT_EMAILS . SaferPayConfig::getConfigSuffix()); return new SaferPayNotification($payerEmail, $merchantEmail, $notifyUrl); } - public function createDeliveryAddressForm() + public function createDeliveryAddressForm(): DeliveryAddressForm { return new DeliveryAddressForm(DeliveryAddressForm::MANDATORY_FIELDS, DeliveryAddressForm::ADDRESS_SOURCE); } - public function createAmount($value, $currencyCode) + public function createAmount(string $value, string $currencyCode): Amount { return new Amount($value, $currencyCode); } - public function createAddressObject(\Address $address, Customer $customer) + public function createAddressObject(\Address $address, Customer $customer): Address { $saferpayAddress = new Address(); $saferpayAddress->setFirstName($address->firstname); @@ -185,7 +187,7 @@ public function createAddressObject(\Address $address, Customer $customer) * * @return OrderItem */ - public function buildOrderItem(array $product) + public function buildOrderItem(array $product): OrderItem { $orderItem = new OrderItem(); $orderItem->setVariantId($product['id_product_attribute']); @@ -199,7 +201,7 @@ public function buildOrderItem(array $product) return $orderItem; } - public function buildOrderItemShippingFee(Cart $cart) + public function buildOrderItemShippingFee(Cart $cart): OrderItem { $carrier = new Carrier($cart->id_carrier); $cartRules = $cart->getCartRules(CartRule::FILTER_ACTION_SHIPPING, false); @@ -239,7 +241,7 @@ public function buildOrderItemShippingFee(Cart $cart) * * @return Order */ - public function buildOrder(Cart $cart) + public function buildOrder(Cart $cart): Order { $order = new Order(); $products = $cart->getProducts(); @@ -260,7 +262,7 @@ public function buildOrder(Cart $cart) * * @return PayerProfile */ - public function createPayerProfile(Customer $customer) + public function createPayerProfile(Customer $customer): PayerProfile { $payerProfile = new PayerProfile(); $payerProfile->setCreationDate((new \DateTime($customer->date_add))->format(\DateTime::ISO8601)); diff --git a/src/Service/Request/index.php b/src/Service/Request/index.php old mode 100755 new mode 100644 diff --git a/src/Service/Response/AssertRefundResponseObjectCreator.php b/src/Service/Response/AssertRefundResponseObjectCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/Response/AssertResponseObjectCreator.php b/src/Service/Response/AssertResponseObjectCreator.php old mode 100755 new mode 100644 index f4ec1e21d..6fa40c3f5 --- a/src/Service/Response/AssertResponseObjectCreator.php +++ b/src/Service/Response/AssertResponseObjectCreator.php @@ -32,11 +32,11 @@ class AssertResponseObjectCreator extends ResponseObjectCreator { /** - * @param $responseBody + * @param object|array $responseBody * * @return AssertBody */ - public function createAssertObject($responseBody) + public function createAssertObject($responseBody): AssertBody { $assertBody = new AssertBody(); diff --git a/src/Service/Response/AuthorizationResponseObjectCreator.php b/src/Service/Response/AuthorizationResponseObjectCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/Response/InitializeResponseObjectCreator.php b/src/Service/Response/InitializeResponseObjectCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/Response/ResponseObjectCreator.php b/src/Service/Response/ResponseObjectCreator.php old mode 100755 new mode 100644 index 38c4b8824..e552888dd --- a/src/Service/Response/ResponseObjectCreator.php +++ b/src/Service/Response/ResponseObjectCreator.php @@ -77,8 +77,12 @@ protected function createPaymentMeans($paymentMeans) $card = $paymentMeans->Card; $cardObj = new Card(); $cardObj->setMaskedNumber($card->MaskedNumber); - $cardObj->setExpYear($card->ExpYear); - $cardObj->setExpMonth($card->ExpMonth); + if (isset($card->ExpYear)) { + $cardObj->setExpYear($card->ExpYear); + } + if (isset($card->ExpMonth)) { + $cardObj->setExpMonth($card->ExpMonth); + } if (isset($card->HolderName)) { $cardObj->setHolderName($card->HolderName); } diff --git a/src/Service/Response/index.php b/src/Service/Response/index.php old mode 100755 new mode 100644 diff --git a/src/Service/SaferPayCartService.php b/src/Service/SaferPayCartService.php old mode 100755 new mode 100644 index 9ab61ee0a..112a90848 --- a/src/Service/SaferPayCartService.php +++ b/src/Service/SaferPayCartService.php @@ -44,7 +44,11 @@ public function __construct(ModuleFactory $moduleFactory) $this->module = $moduleFactory->getModule(); } - public function isCurrencyAvailable(Cart $cart) + /** + * @param Cart $cart + * @return bool + */ + public function isCurrencyAvailable(Cart $cart): bool { $currency_order = new Currency($cart->id_currency); $currencies_module = $this->module->getCurrency($cart->id_currency); diff --git a/src/Service/SaferPayEmailTemplateControlService.php b/src/Service/SaferPayEmailTemplateControlService.php index 591eb514d..62f0c9b14 100644 --- a/src/Service/SaferPayEmailTemplateControlService.php +++ b/src/Service/SaferPayEmailTemplateControlService.php @@ -1,4 +1,25 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services + */ declare(strict_types=1); diff --git a/src/Service/SaferPayEmailTemplateControlServiceInterface.php b/src/Service/SaferPayEmailTemplateControlServiceInterface.php index aca089692..42e0815c0 100644 --- a/src/Service/SaferPayEmailTemplateControlServiceInterface.php +++ b/src/Service/SaferPayEmailTemplateControlServiceInterface.php @@ -1,4 +1,25 @@ + *@copyright SIX Payment Services + *@license SIX Payment Services + */ declare(strict_types=1); diff --git a/src/Service/SaferPayErrorDisplayService.php b/src/Service/SaferPayErrorDisplayService.php old mode 100755 new mode 100644 diff --git a/src/Service/SaferPayExceptionService.php b/src/Service/SaferPayExceptionService.php old mode 100755 new mode 100644 index 89a5ffb52..da8d2e47e --- a/src/Service/SaferPayExceptionService.php +++ b/src/Service/SaferPayExceptionService.php @@ -46,7 +46,10 @@ public function __construct(ModuleFactory $module) $this->module = $module->getModule(); } - public function getErrorMessages() + /** + * @return array + */ + public function getErrorMessages(): array { //todo: test translations return [ @@ -68,7 +71,12 @@ public function getErrorMessages() ]; } - public function getErrorMessageForException(Exception $exception, array $messages) + /** + * @param Exception $exception + * @param array $messages + * @return string + */ + public function getErrorMessageForException(Exception $exception, array $messages): string { $exceptionType = get_class($exception); $exceptionCode = $exception->getCode(); diff --git a/src/Service/SaferPayFieldCreator.php b/src/Service/SaferPayFieldCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/SaferPayInitialize.php b/src/Service/SaferPayInitialize.php old mode 100755 new mode 100644 diff --git a/src/Service/SaferPayLogoCreator.php b/src/Service/SaferPayLogoCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/SaferPayMailService.php b/src/Service/SaferPayMailService.php old mode 100755 new mode 100644 diff --git a/src/Service/SaferPayObtainPaymentMethods.php b/src/Service/SaferPayObtainPaymentMethods.php old mode 100755 new mode 100644 index e9ddb6e53..75c617f35 --- a/src/Service/SaferPayObtainPaymentMethods.php +++ b/src/Service/SaferPayObtainPaymentMethods.php @@ -36,9 +36,17 @@ class SaferPayObtainPaymentMethods { const FILE_NAME = 'SaferPayObtainPaymentMethods'; + + /** @var ObtainPaymentMethodsService */ private $obtainPaymentMethodsService; + + /** @var ObtainPaymentMethodsObjectCreator */ private $obtainPaymentMethodsObjectCreator; + + /** @var SaferPayPaymentNotation */ private $saferPayPaymentNotation; + + /** @var LoggerInterface */ private $logger; public function __construct( @@ -58,7 +66,7 @@ public function obtainPaymentMethods(): array $paymentMethods = []; try { - // TODO: Fix this to return an object + /** @var \stdClass $paymentMethodsObject */ $paymentMethodsObject = $this->obtainPaymentMethodsService->getPaymentMethods( $this->obtainPaymentMethodsObjectCreator->create() ); @@ -83,7 +91,7 @@ public function obtainPaymentMethods(): array } if (!empty($paymentMethodsObject->Wallets)) { - // TODO: Fix this to return an object (now error in IDE) + /** @var \stdClass $wallet */ foreach ($paymentMethodsObject->Wallets as $wallet) { $paymentMethods[$wallet->WalletName] = [ 'paymentMethod' => $wallet->WalletName, diff --git a/src/Service/SaferPayOrderStatusService.php b/src/Service/SaferPayOrderStatusService.php old mode 100755 new mode 100644 index 2bf3e2ae8..d6ec4f3ad --- a/src/Service/SaferPayOrderStatusService.php +++ b/src/Service/SaferPayOrderStatusService.php @@ -121,7 +121,7 @@ public function __construct( $this->logger = $logger; } - public function setPending(Order $order) + public function setPending(Order $order): void { $saferPayOrder = $this->orderRepository->getByOrderId($order->id); $saferPayOrder->pending = 1; @@ -130,7 +130,7 @@ public function setPending(Order $order) $order->setCurrentState(_SAFERPAY_PAYMENT_PENDING_); } - public function setComplete(Order $order) + public function setComplete(Order $order): void { $saferPayOrder = $this->orderRepository->getByOrderId($order->id); $saferPayOrder->captured = 1; @@ -147,8 +147,11 @@ public function setComplete(Order $order) $order->setCurrentState(_SAFERPAY_PAYMENT_COMPLETED_); } - /** TODO extract capture api code to different service like Assert for readability */ - public function capture(Order $order, $refundedAmount = 0, $isRefund = false) + /** + * @NOTE: Consider extracting capture API logic to a dedicated service for improved readability. + * @see SaferPayTransactionAssertion for similar service pattern + */ + public function capture(Order $order, int $refundedAmount = 0, bool $isRefund = false): void { $saferPayOrderId = $this->orderRepository->getIdByOrderId($order->id); $saferPayOrder = new SaferPayOrder($saferPayOrderId); @@ -220,7 +223,7 @@ public function capture(Order $order, $refundedAmount = 0, $isRefund = false) $saferPayAssert->update(); } - public function cancel(Order $order) + public function cancel(Order $order): void { $saferPayOrderId = $this->orderRepository->getIdByOrderId($order->id); $saferPayOrder = new SaferPayOrder($saferPayOrderId); @@ -248,7 +251,7 @@ public function cancel(Order $order) $saferPayAssert->update(); } - public function refund(Order $order, $refundedAmount) + public function refund(Order $order, float $refundedAmount): void { $saferPayOrderId = $this->orderRepository->getIdByOrderId($order->id); $saferPayOrder = new SaferPayOrder($saferPayOrderId); @@ -266,21 +269,6 @@ public function refund(Order $order, $refundedAmount) $cart = new Cart($order->id_cart); $pendingNotification = null; - if ($saferPayAssert->payment_method === SaferPayConfig::PAYMENT_PAYDIREKT) { - $pendingNotify = $this->context->getLink()->getModuleLink( - $this->module->name, - ControllerName::PENDING_NOTIFY, - [ - 'success' => 1, - 'cartId' => $cart->id, - 'orderId' => Order::getOrderByCartId($cart->id), - 'secureKey' => $cart->secure_key, - ], - true - ); - $customer = new Customer($order->id_customer); - $pendingNotification = new PendingNotification($pendingNotify, [$customer->email]); - } $refundRequest = $this->refundRequestObjectCreator->create( $cart, $saferPayOrder->transaction_id, diff --git a/src/Service/SaferPayPaymentCreator.php b/src/Service/SaferPayPaymentCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/SaferPayPaymentNotation.php b/src/Service/SaferPayPaymentNotation.php old mode 100755 new mode 100644 index e9b12d33c..11aad6016 --- a/src/Service/SaferPayPaymentNotation.php +++ b/src/Service/SaferPayPaymentNotation.php @@ -38,7 +38,11 @@ class SaferPayPaymentNotation 'MAESTRO' => 'Maestro-Intl.', ]; - public function getForDisplay($payment) + /** + * @param string $payment + * @return string + */ + public function getForDisplay($payment): string { if (array_key_exists($payment, self::PAYMENTS)) { return self::PAYMENTS[$payment]; @@ -50,7 +54,11 @@ public function getForDisplay($payment) return $notation; } - public function getShortName($payment) + /** + * @param string $payment + * @return string + */ + public function getShortName($payment): string { $paymentNotation = str_replace(' ', '', $payment); diff --git a/src/Service/SaferPayRefreshPaymentsService.php b/src/Service/SaferPayRefreshPaymentsService.php old mode 100755 new mode 100644 diff --git a/src/Service/SaferPayRestrictionCreator.php b/src/Service/SaferPayRestrictionCreator.php old mode 100755 new mode 100644 diff --git a/src/Service/SaferPayTerminalService.php b/src/Service/SaferPayTerminalService.php new file mode 100644 index 000000000..c7f9b9c4a --- /dev/null +++ b/src/Service/SaferPayTerminalService.php @@ -0,0 +1,191 @@ + + *@copyright SIX Payment Services + *@license SIX Payment Services + */ + +namespace Invertus\SaferPay\Service; + +use Configuration; +use Exception; +use Invertus\SaferPay\Config\SaferPayConfig; +use Invertus\SaferPay\Logger\LoggerInterface; +use Unirest\Request; + +if (!defined('_PS_VERSION_')) { + exit; +} + +class SaferPayTerminalService +{ + const FILE_NAME = 'SaferPayTerminalService'; + + /** @var LoggerInterface */ + private $logger; + + public function __construct(LoggerInterface $logger) + { + $this->logger = $logger; + } + + /** + * Fetch available terminals from SaferPay REST API + * + * @param string|null $customerId Optional customer ID, if not provided uses config + * @return array Array of terminals with TerminalId and Description + */ + public function getAvailableTerminals($customerId = null) + { + try { + $customerId = $customerId ?: Configuration::get( + SaferPayConfig::CUSTOMER_ID . SaferPayConfig::getConfigSuffix() + ); + + if (empty($customerId)) { + $this->logger->debug(sprintf('%s - Customer ID not configured', self::FILE_NAME)); + return []; + } + + $url = $this->getBaseRestUrl() . '/api/rest/customers/' . $customerId . '/terminals'; + $headers = $this->getHeaders(); + + $this->logger->debug(sprintf('%s - Fetching terminals from: %s', self::FILE_NAME, $url)); + + $request = new Request(); + $response = $request->get($url, $headers); + + $this->logger->debug(sprintf('%s - Terminal API response: %d', self::FILE_NAME, $response->code), [ + 'context' => [ + 'uri' => $url, + ], + 'response' => $response->body, + ]); + + if ($response->code >= 300) { + $this->logger->error(sprintf('%s - Failed to fetch terminals: %d', self::FILE_NAME, $response->code), [ + 'context' => [], + 'response' => $response->body, + ]); + return []; + } + + return $this->parseTerminalsResponse($response->body); + } catch (Exception $exception) { + $this->logger->error(sprintf('%s - Exception: %s', self::FILE_NAME, $exception->getMessage()), [ + 'context' => [], + 'exception' => $exception, + ]); + return []; + } + } + + /** + * Validate if a terminal ID exists in available terminals + * + * @param string $terminalId + * @return bool + */ + public function isValidTerminal($terminalId) + { + if (empty($terminalId)) { + return false; + } + + $terminals = $this->getAvailableTerminals(); + + foreach ($terminals as $terminal) { + if ($terminal['TerminalId'] === $terminalId) { + return true; + } + } + + return false; + } + + /** + * Parse terminals response from API + * + * @param mixed $responseBody + * @return array + */ + private function parseTerminalsResponse($responseBody) + { + $terminals = []; + + if (empty($responseBody)) { + return $terminals; + } + + if (is_object($responseBody)) { + $responseBody = json_decode(json_encode($responseBody), true); + } + + $terminalsList = $responseBody['Terminals'] ?? $responseBody; + + if (is_array($terminalsList)) { + foreach ($terminalsList as $terminal) { + $terminalId = $terminal['TerminalId'] ?? null; + $description = $terminal['Description'] ?? null; + + if ($terminalId) { + $terminals[] = [ + 'TerminalId' => $terminalId, + 'Description' => $description ?: $terminalId, + ]; + } + } + } + + $this->logger->debug(sprintf('%s - Parsed %d terminals', self::FILE_NAME, count($terminals))); + + return $terminals; + } + + /** + * Get REST API base URL + * + * @return string + */ + private function getBaseRestUrl() + { + return SaferPayConfig::getBaseUrl(); + } + + /** + * Get headers for REST API request + * + * @return array + */ + private function getHeaders() + { + $username = Configuration::get(SaferPayConfig::USERNAME . SaferPayConfig::getConfigSuffix()); + $password = Configuration::get(SaferPayConfig::PASSWORD . SaferPayConfig::getConfigSuffix()); + + $credentials = base64_encode("$username:$password"); + + return [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + 'Saferpay-ApiVersion' => SaferPayConfig::API_VERSION, + 'Saferpay-RequestId' => 'false', + 'Authorization' => "Basic $credentials", + ]; + } +} diff --git a/src/Service/TransactionFlow/SaferPayTransactionAssertion.php b/src/Service/TransactionFlow/SaferPayTransactionAssertion.php old mode 100755 new mode 100644 diff --git a/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php b/src/Service/TransactionFlow/SaferPayTransactionAuthorization.php old mode 100755 new mode 100644 diff --git a/src/Service/TransactionFlow/SaferPayTransactionRefundAssertion.php b/src/Service/TransactionFlow/SaferPayTransactionRefundAssertion.php old mode 100755 new mode 100644 diff --git a/src/Service/TransactionFlow/index.php b/src/Service/TransactionFlow/index.php old mode 100755 new mode 100644 diff --git a/src/Service/TranslatorInterface.php b/src/Service/TranslatorInterface.php old mode 100755 new mode 100644 index fb186c91d..14cc50df9 --- a/src/Service/TranslatorInterface.php +++ b/src/Service/TranslatorInterface.php @@ -40,5 +40,5 @@ interface TranslatorInterface * * @return string The translated string */ - public function translate($key); + public function translate(string $key): string; } diff --git a/src/Service/index.php b/src/Service/index.php old mode 100755 new mode 100644 diff --git a/src/ServiceProvider/BaseServiceProvider.php b/src/ServiceProvider/BaseServiceProvider.php old mode 100755 new mode 100644 diff --git a/src/ServiceProvider/LeagueServiceContainerProvider.php b/src/ServiceProvider/LeagueServiceContainerProvider.php old mode 100755 new mode 100644 diff --git a/src/ServiceProvider/ServiceContainerProviderInterface.php b/src/ServiceProvider/ServiceContainerProviderInterface.php old mode 100755 new mode 100644 diff --git a/src/Utility/PriceUtility.php b/src/Utility/PriceUtility.php old mode 100755 new mode 100644 index 216c1a938..f700fe8c8 --- a/src/Utility/PriceUtility.php +++ b/src/Utility/PriceUtility.php @@ -31,10 +31,9 @@ class PriceUtility { /** * @param float $price - * * @return int */ - public function convertToCents($price) + public function convertToCents($price): int { if (!is_numeric($price)) { throw new \InvalidArgumentException('Price must be numeric'); diff --git a/src/Utility/VersionUtility.php b/src/Utility/VersionUtility.php index d19b7ac7d..417d9d883 100644 --- a/src/Utility/VersionUtility.php +++ b/src/Utility/VersionUtility.php @@ -29,32 +29,55 @@ class VersionUtility { - public static function isPsVersionLessThan($version) + /** + * @param string $version + * @return bool + */ + public static function isPsVersionLessThan($version): bool { return version_compare(_PS_VERSION_, $version, '<'); } - public static function isPsVersionGreaterThan($version) + /** + * @param string $version + * @return bool + */ + public static function isPsVersionGreaterThan($version): bool { return version_compare(_PS_VERSION_, $version, '>'); } - public static function isPsVersionGreaterOrEqualTo($version) + /** + * @param string $version + * @return bool + */ + public static function isPsVersionGreaterOrEqualTo($version): bool { return version_compare(_PS_VERSION_, $version, '>='); } - public static function isPsVersionLessThanOrEqualTo($version) + /** + * @param string $version + * @return bool + */ + public static function isPsVersionLessThanOrEqualTo($version): bool { return version_compare(_PS_VERSION_, $version, '<='); } - public static function isPsVersionEqualTo($version) + /** + * @param string $version + * @return bool + */ + public static function isPsVersionEqualTo($version): bool { return version_compare(_PS_VERSION_, $version, '='); } - public static function current() + /** + * @return string + */ + public static function current(): string { return _PS_VERSION_; } diff --git a/src/Utility/index.php b/src/Utility/index.php old mode 100755 new mode 100644 diff --git a/src/index.php b/src/index.php old mode 100755 new mode 100644 diff --git a/tests/.env.dist b/tests/.env.dist old mode 100755 new mode 100644 diff --git a/tests/Integration/Payment/SaferPayPaymentTest.php b/tests/Integration/Payment/SaferPayPaymentTest.php old mode 100755 new mode 100644 diff --git a/tests/Integration/Payment/index.php b/tests/Integration/Payment/index.php old mode 100755 new mode 100644 diff --git a/tests/Integration/Tools/index.php b/tests/Integration/Tools/index.php old mode 100755 new mode 100644 diff --git a/tests/Integration/bootstrap.php b/tests/Integration/bootstrap.php old mode 100755 new mode 100644 diff --git a/tests/Integration/index.php b/tests/Integration/index.php old mode 100755 new mode 100644 diff --git a/tests/Integration/phpunit.xml b/tests/Integration/phpunit.xml old mode 100755 new mode 100644 diff --git a/tests/Unit/Service/PaymentRestrictionValidation/ApplePayPaymentRestrictionValidationTest.php b/tests/Unit/Service/PaymentRestrictionValidation/ApplePayPaymentRestrictionValidationTest.php old mode 100755 new mode 100644 diff --git a/tests/Unit/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidationTest.php b/tests/Unit/Service/PaymentRestrictionValidation/BasePaymentRestrictionValidationTest.php old mode 100755 new mode 100644 diff --git a/tests/Unit/Service/PaymentRestrictionValidation/KlarnaPaymentRestrictionValidationTest.php b/tests/Unit/Service/PaymentRestrictionValidation/KlarnaPaymentRestrictionValidationTest.php old mode 100755 new mode 100644 diff --git a/tests/Unit/Service/PaymentRestrictionValidation/index.php b/tests/Unit/Service/PaymentRestrictionValidation/index.php old mode 100755 new mode 100644 diff --git a/tests/Unit/Service/SaferPayPaymentNotationTest.php b/tests/Unit/Service/SaferPayPaymentNotationTest.php old mode 100755 new mode 100644 diff --git a/tests/Unit/Service/index.php b/tests/Unit/Service/index.php old mode 100755 new mode 100644 diff --git a/tests/Unit/Tools/UnitTestCase.php b/tests/Unit/Tools/UnitTestCase.php old mode 100755 new mode 100644 diff --git a/tests/Unit/Tools/index.php b/tests/Unit/Tools/index.php old mode 100755 new mode 100644 diff --git a/tests/Unit/Utility/PriceUtilityTest.php b/tests/Unit/Utility/PriceUtilityTest.php old mode 100755 new mode 100644 diff --git a/tests/Unit/Utility/index.php b/tests/Unit/Utility/index.php old mode 100755 new mode 100644 diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php old mode 100755 new mode 100644 diff --git a/tests/Unit/index.php b/tests/Unit/index.php old mode 100755 new mode 100644 diff --git a/tests/Unit/phpunit.xml b/tests/Unit/phpunit.xml old mode 100755 new mode 100644 diff --git a/tests/index.php b/tests/index.php old mode 100755 new mode 100644 diff --git a/tests/seed/database/index.php b/tests/seed/database/index.php old mode 100755 new mode 100644 diff --git a/tests/seed/database/prestashop_1764.sql b/tests/seed/database/prestashop_1764.sql old mode 100755 new mode 100644 diff --git a/tests/seed/database/prestashop_1770.sql b/tests/seed/database/prestashop_1770.sql old mode 100755 new mode 100644 diff --git a/tests/seed/database/prestashop_1784_2.sql b/tests/seed/database/prestashop_1784_2.sql old mode 100755 new mode 100644 diff --git a/tests/seed/database/prestashop_1786.sql b/tests/seed/database/prestashop_1786.sql old mode 100755 new mode 100644 diff --git a/tests/seed/index.php b/tests/seed/index.php old mode 100755 new mode 100644 diff --git a/tests/seed/settings1764/defines.inc.php b/tests/seed/settings1764/defines.inc.php old mode 100755 new mode 100644 diff --git a/tests/seed/settings1764/index.php b/tests/seed/settings1764/index.php old mode 100755 new mode 100644 diff --git a/tests/seed/settings1764/parameters.php b/tests/seed/settings1764/parameters.php old mode 100755 new mode 100644 diff --git a/tests/seed/settings1770/defines.inc.php b/tests/seed/settings1770/defines.inc.php old mode 100755 new mode 100644 diff --git a/tests/seed/settings1770/index.php b/tests/seed/settings1770/index.php old mode 100755 new mode 100644 diff --git a/tests/seed/settings1770/parameters.php b/tests/seed/settings1770/parameters.php old mode 100755 new mode 100644 diff --git a/tests/seed/settings1784/defines.inc.php b/tests/seed/settings1784/defines.inc.php old mode 100755 new mode 100644 diff --git a/tests/seed/settings1784/index.php b/tests/seed/settings1784/index.php old mode 100755 new mode 100644 diff --git a/tests/seed/settings1784/parameters.php b/tests/seed/settings1784/parameters.php old mode 100755 new mode 100644 diff --git a/tests/seed/settings1786/defines.inc.php b/tests/seed/settings1786/defines.inc.php old mode 100755 new mode 100644 diff --git a/tests/seed/settings1786/index.php b/tests/seed/settings1786/index.php old mode 100755 new mode 100644 diff --git a/tests/seed/settings1786/parameters.php b/tests/seed/settings1786/parameters.php old mode 100755 new mode 100644 diff --git a/translations/lt.php b/translations/lt.php old mode 100755 new mode 100644 diff --git a/upgrade/index.php b/upgrade/index.php old mode 100755 new mode 100644 diff --git a/upgrade/install-1.0.13.php b/upgrade/install-1.0.13.php old mode 100755 new mode 100644 diff --git a/upgrade/install-1.0.18.php b/upgrade/install-1.0.18.php old mode 100755 new mode 100644 diff --git a/upgrade/install-1.0.2.php b/upgrade/install-1.0.2.php old mode 100755 new mode 100644 diff --git a/upgrade/install-1.0.3.php b/upgrade/install-1.0.3.php old mode 100755 new mode 100644 index 2574c76e5..a55c92bc2 --- a/upgrade/install-1.0.3.php +++ b/upgrade/install-1.0.3.php @@ -39,7 +39,7 @@ function upgrade_module_1_0_3($module) Configuration::updateValue( \Invertus\SaferPay\Config\SaferPayConfig::FIELDS_LIBRARY . \Invertus\SaferPay\Config\SaferPayConfig::TEST_SUFFIX, - \Invertus\SaferPay\Config\SaferPayConfig::FIELDS_LIBRARY_TEST_DEFAULT_VALUE + \Invertus\SaferPay\Config\SaferPayConfig::FIELDS_LIBRARY_DEFAULT_VALUE ); Configuration::updateValue( \Invertus\SaferPay\Config\SaferPayConfig::HOSTED_FIELDS_TEMPLATE, diff --git a/upgrade/install-1.0.4.php b/upgrade/install-1.0.4.php old mode 100755 new mode 100644 diff --git a/upgrade/install-1.0.6.php b/upgrade/install-1.0.6.php old mode 100755 new mode 100644 diff --git a/upgrade/install-2.0.2.php b/upgrade/install-2.0.2.php index e66a64d06..24e3b5e40 100644 --- a/upgrade/install-2.0.2.php +++ b/upgrade/install-2.0.2.php @@ -25,10 +25,106 @@ exit; } -function upgrade_module_2_0_2() +function upgrade_module_2_0_2(SaferPayOfficial $module) { - Configuration::updateValue('SAFERPAY_SEND_ORDER_CONF_MAIL', 0); - Configuration::updateValue('SAFERPAY_GROUP_CARDS', 0); + $db = Db::getInstance(); + $success = true; - return true; + // Add indexes for saferpay_order table + $orderIndexes = [ + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_order` ADD INDEX `idx_id_order` (`id_order`)", + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_order` ADD INDEX `idx_id_cart` (`id_cart`)", + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_order` ADD INDEX `idx_id_customer` (`id_customer`)", + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_order` ADD INDEX `idx_transaction_id` (`transaction_id`)", + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_order` ADD INDEX `idx_status_flags` (`authorized`, `captured`, `pending`)", + ]; + + foreach ($orderIndexes as $indexSql) { + try { + $result = $db->execute($indexSql); + if (!$result) { + $error = $db->getMsgError(); + if (strpos($error, 'Duplicate key name') === false) { + $success = false; + PrestaShopLogger::addLog('SaferPay: Failed to add order index - ' . $error, 3, null, 'SaferPayOrder'); + } + } + } catch (Exception $e) { + PrestaShopLogger::addLog('SaferPay: Order index creation skipped - ' . $e->getMessage(), 1, null, 'SaferPayOrder'); + } + } + + // Add indexes for saferpay_card_alias table + $cardAliasIndexes = [ + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_card_alias` ADD INDEX `idx_id_customer` (`id_customer`)", + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_card_alias` ADD INDEX `idx_payment_method` (`payment_method`)", + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_card_alias` ADD INDEX `idx_customer_payment` (`id_customer`, `payment_method`)", + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_card_alias` ADD INDEX `idx_valid_till` (`valid_till`)", + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_card_alias` ADD INDEX `idx_alias_id` (`alias_id`)", + ]; + + foreach ($cardAliasIndexes as $indexSql) { + try { + $result = $db->execute($indexSql); + if (!$result) { + $error = $db->getMsgError(); + if (strpos($error, 'Duplicate key name') === false) { + $success = false; + PrestaShopLogger::addLog('SaferPay: Failed to add card alias index - ' . $error, 3, null, 'SaferPayCardAlias'); + } + } + } catch (Exception $e) { + PrestaShopLogger::addLog('SaferPay: Card alias index creation skipped - ' . $e->getMessage(), 1, null, 'SaferPayCardAlias'); + } + } + + // Add indexes for saferpay_assert table + $assertIndexes = [ + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_assert` ADD INDEX `idx_id_saferpay_order` (`id_saferpay_order`)", + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_assert` ADD INDEX `idx_payment_method` (`payment_method`)", + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_assert` ADD INDEX `idx_brand` (`brand`)", + ]; + + foreach ($assertIndexes as $indexSql) { + try { + $result = $db->execute($indexSql); + if (!$result) { + $error = $db->getMsgError(); + if (strpos($error, 'Duplicate key name') === false) { + $success = false; + PrestaShopLogger::addLog('SaferPay: Failed to add assert index - ' . $error, 3, null, 'SaferPayAssert'); + } + } + } catch (Exception $e) { + PrestaShopLogger::addLog('SaferPay: Assert index creation skipped - ' . $e->getMessage(), 1, null, 'SaferPayAssert'); + } + } + + // Add indexes for saferpay_order_refund table + $refundIndexes = [ + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_order_refund` ADD INDEX `idx_id_saferpay_order` (`id_saferpay_order`)", + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_order_refund` ADD INDEX `idx_id_order` (`id_order`)", + "ALTER TABLE `" . _DB_PREFIX_ . "saferpay_order_refund` ADD INDEX `idx_transaction_id` (`transaction_id`)", + ]; + + foreach ($refundIndexes as $indexSql) { + try { + $result = $db->execute($indexSql); + if (!$result) { + $error = $db->getMsgError(); + if (strpos($error, 'Duplicate key name') === false) { + $success = false; + PrestaShopLogger::addLog('SaferPay: Failed to add refund index - ' . $error, 3, null, 'SaferPayOrderRefund'); + } + } + } catch (Exception $e) { + PrestaShopLogger::addLog('SaferPay: Refund index creation skipped - ' . $e->getMessage(), 1, null, 'SaferPayOrderRefund'); + } + } + + if ($success) { + PrestaShopLogger::addLog('SaferPay: Database indexes added successfully', 1, null, 'SaferPayOptimization'); + } + + return $success; } diff --git a/var/index.php b/var/index.php old mode 100755 new mode 100644 diff --git a/views/css/admin/index.php b/views/css/admin/index.php old mode 100755 new mode 100644 diff --git a/views/css/admin/logs_tab.css b/views/css/admin/logs_tab.css old mode 100755 new mode 100644 diff --git a/views/css/admin/payment_method.css b/views/css/admin/payment_method.css old mode 100755 new mode 100644 diff --git a/views/css/admin/saferpay_admin_order.css b/views/css/admin/saferpay_admin_order.css old mode 100755 new mode 100644 diff --git a/views/css/admin/saferpay_fields.css b/views/css/admin/saferpay_fields.css old mode 100755 new mode 100644 diff --git a/views/css/front/hosted-templates/index.php b/views/css/front/hosted-templates/index.php old mode 100755 new mode 100644 diff --git a/views/css/front/hosted-templates/template1.css b/views/css/front/hosted-templates/template1.css old mode 100755 new mode 100644 diff --git a/views/css/front/hosted-templates/template2.css b/views/css/front/hosted-templates/template2.css old mode 100755 new mode 100644 diff --git a/views/css/front/hosted-templates/template3.css b/views/css/front/hosted-templates/template3.css old mode 100755 new mode 100644 diff --git a/views/css/front/index.php b/views/css/front/index.php old mode 100755 new mode 100644 diff --git a/views/css/front/loading.css b/views/css/front/loading.css old mode 100755 new mode 100644 diff --git a/views/css/front/saferpay_checkout.css b/views/css/front/saferpay_checkout.css old mode 100755 new mode 100644 diff --git a/views/css/front/saferpay_iframe.css b/views/css/front/saferpay_iframe.css old mode 100755 new mode 100644 diff --git a/views/css/index.php b/views/css/index.php old mode 100755 new mode 100644 diff --git a/views/img/ALIPAY.png b/views/img/ALIPAY.png old mode 100755 new mode 100644 diff --git a/views/img/AMEX.png b/views/img/AMEX.png old mode 100755 new mode 100644 diff --git a/views/img/APPLEPAY.png b/views/img/APPLEPAY.png old mode 100755 new mode 100644 diff --git a/views/img/BANCONTACT.png b/views/img/BANCONTACT.png old mode 100755 new mode 100644 diff --git a/views/img/BONUS.png b/views/img/BONUS.png old mode 100755 new mode 100644 diff --git a/views/img/DINERS.png b/views/img/DINERS.png old mode 100755 new mode 100644 diff --git a/views/img/DIRECTDEBIT.png b/views/img/DIRECTDEBIT.png old mode 100755 new mode 100644 diff --git a/views/img/EPRZELEWY.png b/views/img/EPRZELEWY.png old mode 100755 new mode 100644 diff --git a/views/img/EPS.png b/views/img/EPS.png old mode 100755 new mode 100644 diff --git a/views/img/GIROPAY.png b/views/img/GIROPAY.png old mode 100755 new mode 100644 diff --git a/views/img/IDEAL.png b/views/img/IDEAL.png old mode 100755 new mode 100644 diff --git a/views/img/INVOICE.png b/views/img/INVOICE.png old mode 100755 new mode 100644 diff --git a/views/img/JCB.png b/views/img/JCB.png old mode 100755 new mode 100644 diff --git a/views/img/KLARNA.png b/views/img/KLARNA.png old mode 100755 new mode 100644 diff --git a/views/img/MAESTRO.png b/views/img/MAESTRO.png old mode 100755 new mode 100644 diff --git a/views/img/MASTERCARD.png b/views/img/MASTERCARD.png old mode 100755 new mode 100644 diff --git a/views/img/MYONE.png b/views/img/MYONE.png old mode 100755 new mode 100644 diff --git a/views/img/PAYDIREKT.png b/views/img/PAYDIREKT.png old mode 100755 new mode 100644 diff --git a/views/img/PAYPAL.png b/views/img/PAYPAL.png old mode 100755 new mode 100644 diff --git a/views/img/POSTCARD.png b/views/img/POSTCARD.png old mode 100755 new mode 100644 diff --git a/views/img/POSTFINANCE.png b/views/img/POSTFINANCE.png old mode 100755 new mode 100644 diff --git a/views/img/SAFERPAY.png b/views/img/SAFERPAY.png old mode 100755 new mode 100644 diff --git a/views/img/SOFORT.png b/views/img/SOFORT.png old mode 100755 new mode 100644 diff --git a/views/img/TWINT.png b/views/img/TWINT.png old mode 100755 new mode 100644 diff --git a/views/img/UNIONPAY.png b/views/img/UNIONPAY.png old mode 100755 new mode 100644 diff --git a/views/img/VISA.png b/views/img/VISA.png old mode 100755 new mode 100644 diff --git a/views/img/VPAY.png b/views/img/VPAY.png old mode 100755 new mode 100644 diff --git a/views/img/WLCRYPTOPAYMENTS.png b/views/img/WLCRYPTOPAYMENTS.png old mode 100755 new mode 100644 diff --git a/views/img/example-card/credit-card-back-cvc.png b/views/img/example-card/credit-card-back-cvc.png old mode 100755 new mode 100644 diff --git a/views/img/example-card/credit-card-back.png b/views/img/example-card/credit-card-back.png old mode 100755 new mode 100644 diff --git a/views/img/example-card/credit-card-front-card-number.png b/views/img/example-card/credit-card-front-card-number.png old mode 100755 new mode 100644 diff --git a/views/img/example-card/credit-card-front-expiration.png b/views/img/example-card/credit-card-front-expiration.png old mode 100755 new mode 100644 diff --git a/views/img/example-card/credit-card-front.png b/views/img/example-card/credit-card-front.png old mode 100755 new mode 100644 diff --git a/views/img/example-card/index.php b/views/img/example-card/index.php old mode 100755 new mode 100644 diff --git a/views/img/hosted-templates/index.php b/views/img/hosted-templates/index.php old mode 100755 new mode 100644 diff --git a/views/img/hosted-templates/template1.jpg b/views/img/hosted-templates/template1.jpg old mode 100755 new mode 100644 diff --git a/views/img/hosted-templates/template2.jpg b/views/img/hosted-templates/template2.jpg old mode 100755 new mode 100644 diff --git a/views/img/hosted-templates/template3.jpg b/views/img/hosted-templates/template3.jpg old mode 100755 new mode 100644 diff --git a/views/img/index.php b/views/img/index.php old mode 100755 new mode 100644 diff --git a/views/img/readme/01.png b/views/img/readme/01.png old mode 100755 new mode 100644 diff --git a/views/img/readme/02.png b/views/img/readme/02.png old mode 100755 new mode 100644 diff --git a/views/img/readme/Step1.png b/views/img/readme/Step1.png old mode 100755 new mode 100644 diff --git a/views/img/readme/Step2.png b/views/img/readme/Step2.png old mode 100755 new mode 100644 diff --git a/views/img/readme/Step3.png b/views/img/readme/Step3.png old mode 100755 new mode 100644 diff --git a/views/img/readme/Step4.png b/views/img/readme/Step4.png old mode 100755 new mode 100644 diff --git a/views/img/readme/Step5.png b/views/img/readme/Step5.png old mode 100755 new mode 100644 diff --git a/views/img/readme/Step6.png b/views/img/readme/Step6.png old mode 100755 new mode 100644 diff --git a/views/img/readme/Step7.png b/views/img/readme/Step7.png old mode 100755 new mode 100644 diff --git a/views/img/readme/img.png b/views/img/readme/img.png old mode 100755 new mode 100644 diff --git a/views/img/readme/index.php b/views/img/readme/index.php old mode 100755 new mode 100644 diff --git a/views/img/readme/pic1.png b/views/img/readme/pic1.png old mode 100755 new mode 100644 diff --git a/views/img/readme/pic2.png b/views/img/readme/pic2.png old mode 100755 new mode 100644 diff --git a/views/img/readme/ss1.png b/views/img/readme/ss1.png old mode 100755 new mode 100644 diff --git a/views/img/readme/ss2.png b/views/img/readme/ss2.png old mode 100755 new mode 100644 diff --git a/views/img/readme/ss3.png b/views/img/readme/ss3.png old mode 100755 new mode 100644 diff --git a/views/img/readme/ss4.png b/views/img/readme/ss4.png old mode 100755 new mode 100644 diff --git a/views/img/readme/ss5.png b/views/img/readme/ss5.png old mode 100755 new mode 100644 diff --git a/views/img/readme/ss6.png b/views/img/readme/ss6.png old mode 100755 new mode 100644 diff --git a/views/img/readme/ss7.png b/views/img/readme/ss7.png old mode 100755 new mode 100644 diff --git a/views/img/state/SAFERPAY_PAYMENT_AUTHORIZATION_FAILED.gif b/views/img/state/SAFERPAY_PAYMENT_AUTHORIZATION_FAILED.gif old mode 100755 new mode 100644 diff --git a/views/img/state/SAFERPAY_PAYMENT_AUTHORIZED.gif b/views/img/state/SAFERPAY_PAYMENT_AUTHORIZED.gif old mode 100755 new mode 100644 diff --git a/views/img/state/SAFERPAY_PAYMENT_AWAITING.gif b/views/img/state/SAFERPAY_PAYMENT_AWAITING.gif old mode 100755 new mode 100644 diff --git a/views/img/state/SAFERPAY_PAYMENT_CANCELED.gif b/views/img/state/SAFERPAY_PAYMENT_CANCELED.gif old mode 100755 new mode 100644 diff --git a/views/img/state/SAFERPAY_PAYMENT_COMPLETED.gif b/views/img/state/SAFERPAY_PAYMENT_COMPLETED.gif old mode 100755 new mode 100644 diff --git a/views/img/state/SAFERPAY_PAYMENT_PARTLY_REFUNDED.gif b/views/img/state/SAFERPAY_PAYMENT_PARTLY_REFUNDED.gif old mode 100755 new mode 100644 diff --git a/views/img/state/SAFERPAY_PAYMENT_PENDING_REFUND.gif b/views/img/state/SAFERPAY_PAYMENT_PENDING_REFUND.gif old mode 100755 new mode 100644 diff --git a/views/img/state/SAFERPAY_PAYMENT_REFUNDED.gif b/views/img/state/SAFERPAY_PAYMENT_REFUNDED.gif old mode 100755 new mode 100644 diff --git a/views/img/state/SAFERPAY_PAYMENT_REJECTED.gif b/views/img/state/SAFERPAY_PAYMENT_REJECTED.gif old mode 100755 new mode 100644 diff --git a/views/img/state/index.php b/views/img/state/index.php old mode 100755 new mode 100644 diff --git a/views/index.php b/views/index.php old mode 100755 new mode 100644 diff --git a/views/js/admin/chosen_countries.js b/views/js/admin/chosen_countries.js old mode 100755 new mode 100644 diff --git a/views/js/admin/index.php b/views/js/admin/index.php old mode 100755 new mode 100644 diff --git a/views/js/admin/payment_method_all.js b/views/js/admin/payment_method_all.js old mode 100755 new mode 100644 diff --git a/views/js/admin/saferpay_settings.js b/views/js/admin/saferpay_settings.js old mode 100755 new mode 100644 diff --git a/views/js/front/hosted-templates/hosted_fields.js b/views/js/front/hosted-templates/hosted_fields.js old mode 100755 new mode 100644 diff --git a/views/js/front/hosted-templates/index.php b/views/js/front/hosted-templates/index.php old mode 100755 new mode 100644 diff --git a/views/js/front/hosted-templates/template1.js b/views/js/front/hosted-templates/template1.js old mode 100755 new mode 100644 diff --git a/views/js/front/hosted-templates/template2.js b/views/js/front/hosted-templates/template2.js old mode 100755 new mode 100644 diff --git a/views/js/front/hosted-templates/template3.js b/views/js/front/hosted-templates/template3.js old mode 100755 new mode 100644 diff --git a/views/js/front/hosted-templates/template_submit.js b/views/js/front/hosted-templates/template_submit.js old mode 100755 new mode 100644 diff --git a/views/js/front/index.php b/views/js/front/index.php old mode 100755 new mode 100644 diff --git a/views/js/front/opc/index.php b/views/js/front/opc/index.php old mode 100755 new mode 100644 diff --git a/views/js/front/saferpay_iframe.js b/views/js/front/saferpay_iframe.js old mode 100755 new mode 100644 diff --git a/views/js/front/saferpay_saved_card.js b/views/js/front/saferpay_saved_card.js old mode 100755 new mode 100644 diff --git a/views/js/index.php b/views/js/index.php old mode 100755 new mode 100644 diff --git a/views/templates/admin/field-option-settings/helpers/index.php b/views/templates/admin/field-option-settings/helpers/index.php old mode 100755 new mode 100644 diff --git a/views/templates/admin/field-option-settings/helpers/options/index.php b/views/templates/admin/field-option-settings/helpers/options/index.php old mode 100755 new mode 100644 diff --git a/views/templates/admin/field-option-settings/helpers/options/options.tpl b/views/templates/admin/field-option-settings/helpers/options/options.tpl old mode 100755 new mode 100644 index 4c100589d..a51d8345e --- a/views/templates/admin/field-option-settings/helpers/options/options.tpl +++ b/views/templates/admin/field-option-settings/helpers/options/options.tpl @@ -27,11 +27,11 @@
{/if} @@ -67,4 +67,10 @@ {/if} + + {if $field['type'] == 'terminal_selector'} +
+ {include file="../../../partials/field-terminal-id.tpl"} +
+ {/if} {/block} diff --git a/views/templates/admin/field-option-settings/index.php b/views/templates/admin/field-option-settings/index.php old mode 100755 new mode 100644 diff --git a/views/templates/admin/index.php b/views/templates/admin/index.php old mode 100755 new mode 100644 diff --git a/views/templates/admin/partials/field-access-token-desc.tpl b/views/templates/admin/partials/field-access-token-desc.tpl old mode 100755 new mode 100644 diff --git a/views/templates/admin/partials/field-hosted-field-template-desc.tpl b/views/templates/admin/partials/field-hosted-field-template-desc.tpl old mode 100755 new mode 100644 diff --git a/views/templates/admin/partials/field-javascript-library-desc.tpl b/views/templates/admin/partials/field-javascript-library-desc.tpl old mode 100755 new mode 100644 diff --git a/views/templates/admin/partials/field-new-order-mail-desc.tpl b/views/templates/admin/partials/field-new-order-mail-desc.tpl old mode 100755 new mode 100644 diff --git a/views/templates/admin/partials/field-terminal-id.tpl b/views/templates/admin/partials/field-terminal-id.tpl new file mode 100644 index 000000000..1049d0c47 --- /dev/null +++ b/views/templates/admin/partials/field-terminal-id.tpl @@ -0,0 +1,47 @@ +{** + *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 !isset($field['terminals']) || count($field['terminals']) == 0} +

+ {l s='Please configure Customer ID, Username, and Password to load terminals' mod='saferpayofficial'} +

+ {else} +

+ {l s='Select a terminal from the list' mod='saferpayofficial'} +

+ {/if} +
diff --git a/views/templates/admin/partials/index.php b/views/templates/admin/partials/index.php old mode 100755 new mode 100644 diff --git a/views/templates/admin/payment_method.tpl b/views/templates/admin/payment_method.tpl old mode 100755 new mode 100644 diff --git a/views/templates/admin/payment_method_all.tpl b/views/templates/admin/payment_method_all.tpl old mode 100755 new mode 100644 diff --git a/views/templates/admin/payment_method_label.tpl b/views/templates/admin/payment_method_label.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/credit_card.tpl b/views/templates/front/credit_card.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/credit_cards.tpl b/views/templates/front/credit_cards.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/hosted-templates/index.php b/views/templates/front/hosted-templates/index.php old mode 100755 new mode 100644 diff --git a/views/templates/front/hosted-templates/partials/all_errors.tpl b/views/templates/front/hosted-templates/partials/all_errors.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/hosted-templates/partials/all_errors_16.tpl b/views/templates/front/hosted-templates/partials/all_errors_16.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/hosted-templates/partials/index.php b/views/templates/front/hosted-templates/partials/index.php old mode 100755 new mode 100644 diff --git a/views/templates/front/hosted-templates/partials/initialize_error.tpl b/views/templates/front/hosted-templates/partials/initialize_error.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/hosted-templates/partials/internal_error.tpl b/views/templates/front/hosted-templates/partials/internal_error.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/hosted-templates/partials/submission_error.tpl b/views/templates/front/hosted-templates/partials/submission_error.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/hosted-templates/partials/validation_error.tpl b/views/templates/front/hosted-templates/partials/validation_error.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/hosted-templates/template1.tpl b/views/templates/front/hosted-templates/template1.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/hosted-templates/template2.tpl b/views/templates/front/hosted-templates/template2.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/hosted-templates/template3.tpl b/views/templates/front/hosted-templates/template3.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/index.php b/views/templates/front/index.php old mode 100755 new mode 100644 diff --git a/views/templates/front/loading.tpl b/views/templates/front/loading.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/order_fail.tpl b/views/templates/front/order_fail.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/payment_return.tpl b/views/templates/front/payment_return.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/saferpay_iframe.tpl b/views/templates/front/saferpay_iframe.tpl old mode 100755 new mode 100644 diff --git a/views/templates/front/saferpay_wait.tpl b/views/templates/front/saferpay_wait.tpl index 28d372572..7b998a7f8 100644 --- a/views/templates/front/saferpay_wait.tpl +++ b/views/templates/front/saferpay_wait.tpl @@ -20,6 +20,7 @@ *@license SIX Payment Services *}

{l s='Awaiting payment status' mod='saferpayofficial'}

+
@@ -90,8 +91,8 @@ (function awaitSaferpayPaymentStatus() { var timeout = 3000; var request = new XMLHttpRequest(); - // nofilter is needed for url with variables - request.open('GET', '{$checkStatusEndpoint|escape:'javascript':'UTF-8' nofilter}', true); + var endpoint = document.getElementById('saferpay-await-config').getAttribute('data-status-endpoint'); + request.open('GET', endpoint, true); request.onload = function() { if (request.status >= 200 && request.status < 400) { diff --git a/views/templates/hook/admin/display_nav.tpl b/views/templates/hook/admin/display_nav.tpl old mode 100755 new mode 100644 diff --git a/views/templates/hook/admin/index.php b/views/templates/hook/admin/index.php old mode 100755 new mode 100644 diff --git a/views/templates/hook/admin/saferpay_order.tpl b/views/templates/hook/admin/saferpay_order.tpl old mode 100755 new mode 100644 diff --git a/views/templates/hook/front/MyAccount.tpl b/views/templates/hook/front/MyAccount.tpl old mode 100755 new mode 100644 diff --git a/views/templates/hook/front/index.php b/views/templates/hook/front/index.php old mode 100755 new mode 100644 diff --git a/views/templates/hook/front/payment.tpl b/views/templates/hook/front/payment.tpl old mode 100755 new mode 100644 diff --git a/views/templates/hook/front/payment_with_cards.tpl b/views/templates/hook/front/payment_with_cards.tpl old mode 100755 new mode 100644 diff --git a/views/templates/hook/front/payments.tpl b/views/templates/hook/front/payments.tpl old mode 100755 new mode 100644 diff --git a/views/templates/hook/front/saferpay_additional_info.tpl b/views/templates/hook/front/saferpay_additional_info.tpl old mode 100755 new mode 100644 diff --git a/views/templates/hook/front/saferpay_field_info.tpl b/views/templates/hook/front/saferpay_field_info.tpl old mode 100755 new mode 100644 diff --git a/views/templates/hook/front/saferpay_payment.tpl b/views/templates/hook/front/saferpay_payment.tpl old mode 100755 new mode 100644 diff --git a/views/templates/hook/index.php b/views/templates/hook/index.php old mode 100755 new mode 100644 diff --git a/views/templates/index.php b/views/templates/index.php old mode 100755 new mode 100644