From 9f83463568b00ac9da027595e8fb3b21fee7a7c9 Mon Sep 17 00:00:00 2001 From: kGablo Date: Fri, 2 Aug 2024 10:14:29 +0200 Subject: [PATCH 1/9] Add custom order for banks and generic payments --- CHANGELOG.MD | 6 + .../admin/TpayConfigurationController.php | 69 ++++++++-- src/Service/PaymentOptions/Transfer.php | 23 +++- tpay.php | 2 +- translations/pl.php | 4 +- views/templates/_admin/configuration.tpl | 123 +++++++++++++++++- 6 files changed, 206 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 1e242ed..1948ace 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.9.5] + +### Added + +- Added custom order for banks and generic payments + ## [1.9.4] ### Fixed diff --git a/controllers/admin/TpayConfigurationController.php b/controllers/admin/TpayConfigurationController.php index a4add41..2d1c924 100644 --- a/controllers/admin/TpayConfigurationController.php +++ b/controllers/admin/TpayConfigurationController.php @@ -27,6 +27,7 @@ class TpayConfigurationController extends ModuleAdminController public const SEPARATE_PAYMENT_INFO = 'Show the method as a separate payment'; public $errors = []; public $configuration = []; + public $channels = []; /** @var Tpay */ public $module; @@ -58,6 +59,10 @@ public function getValuesFormFields(): array $value = json_decode(Cfg::get('TPAY_GENERIC_PAYMENTS'), true); } + if ($field == 'TPAY_CUSTOM_ORDER[]') { + $value = json_decode(Cfg::get('TPAY_CUSTOM_ORDER'), true); + } + $fields[$field] = $value; } @@ -97,7 +102,6 @@ public function getOrderStates(): array return OrderState::getOrderStates(Context::getContext()->language->id); } - protected function getWarningMultishopHtml() { if (Shop::getContext() == Shop::CONTEXT_GROUP) { @@ -127,6 +131,7 @@ protected function contextIsGroup(): bool public function createForm(): array { + $this->getChannels(); $form[] = $this->formBasicOptions(); $form[] = $this->formPaymentOptions(); $form[] = $this->formCardOptions(); @@ -463,6 +468,21 @@ public function formPaymentOptions(): array ], ], + [ + 'type' => 'select', + 'label' => $this->module->l('Custom order'), + 'name' => 'TPAY_CUSTOM_ORDER[]', + 'multiple' => true, + 'class' => 'child', + 'desc' => $this->module->l('Custom order of displayed banks. Drag to change order'), + 'size' => 20, + 'options' => [ + 'query' => $this->sortPayment('TPAY_CUSTOM_ORDER'), + 'id' => 'id', + 'name' => 'name' + ], + ], + [ 'type' => 'switch', 'label' => $this->module->l('GooglePay'), @@ -706,15 +726,7 @@ public function formStatusesOptions(): array private function formGenericPaymentOptions(): array { - $result = []; - - if ($this->module->api()) { - try { - $result = $this->module->api()->transactions()->getChannels(); - } catch (Exception $exception) { - PrestaShopLogger::addLog($exception->getMessage(), 3); - } - } + $result = $this->sortPayment('TPAY_GENERIC_PAYMENTS'); return [ 'form' => [ @@ -724,10 +736,11 @@ private function formGenericPaymentOptions(): array 'type' => 'select', 'label' => $this->module->l('Select payments to Easy on-site mechanism to'), 'name' => 'TPAY_GENERIC_PAYMENTS[]', + 'desc' => $this->module->l('Custom order of displayed payment methods. Drag to change order'), 'multiple' => true, 'size' => $result ? 20 : 1, 'options' => [ - 'query' => $result['channels'] ?? [], + 'query' => $result, 'id' => 'id', 'name' => 'name' ], @@ -737,4 +750,38 @@ private function formGenericPaymentOptions(): array ] ]; } + + private function getChannels() + { + if ($this->module->api()) { + try { + $this->channels = $this->module->api()->transactions()->getChannels()['channels'] ?? []; + } catch (Exception $exception) { + PrestaShopLogger::addLog($exception->getMessage(), 3); + } + } + } + + private function sortPayment(string $field): array + { + $channels = $this->channels; + $chosenPayments = json_decode(Cfg::get($field), true); + + if (count($chosenPayments) > 0) { + $orderedList = []; + + foreach ($chosenPayments as $chosenPayment) { + foreach ($channels as $key => $channel) { + if ($channel['id'] == $chosenPayment) { + $orderedList[$key] = $channel; + unset($channels[$key]); + } + } + } + + return array_merge($orderedList, $channels); + } + + return $channels; + } } diff --git a/src/Service/PaymentOptions/Transfer.php b/src/Service/PaymentOptions/Transfer.php index 7c13a6b..1078c72 100644 --- a/src/Service/PaymentOptions/Transfer.php +++ b/src/Service/PaymentOptions/Transfer.php @@ -36,7 +36,7 @@ public function getPaymentOption( 'transfer_type' => Helper::getMultistoreConfigurationValue('TPAY_TRANSFER_WIDGET') ? 'widget' : 'redirect', 'transfer_gateway' => $data['id'], 'transfer_moduleLink' => $moduleLink, - 'gateways' => $data['gateways'], + 'gateways' => $this->sortGateways($data['gateways']), 'isDirect' => (bool) Configuration::get('TPAY_REDIRECT_TO_CHANNEL'), ]); @@ -60,4 +60,25 @@ protected function generateForm() return Context::getContext()->smarty->fetch('module:tpay/views/templates/hook/payment.tpl'); } + + private function sortGateways(array $gateways) + { + if ((bool)Configuration::get('TPAY_REDIRECT_TO_CHANNEL') && !empty(Configuration::get('TPAY_CUSTOM_ORDER'))) { + $orderedList = []; + $customOrder = json_decode(Configuration::get('TPAY_CUSTOM_ORDER'), true); + + foreach ($customOrder as $orderNumber) { + foreach ($gateways as $gateway) { + if ($gateway['mainChannel'] == $orderNumber) { + $orderedList[$gateway['mainChannel']] = $gateway; + unset($gateways[$gateway['mainChannel']]); + } + } + } + + return array_merge($orderedList, $gateways); + } + + return $gateways; + } } diff --git a/tpay.php b/tpay.php index c9a0317..4f97648 100644 --- a/tpay.php +++ b/tpay.php @@ -141,7 +141,7 @@ public function __construct() { $this->name = 'tpay'; $this->tab = 'payments_gateways'; - $this->version = '1.9.4'; + $this->version = '1.9.5'; $this->author = 'Krajowy Integrator Płatności S.A.'; $this->need_instance = 0; $this->ps_versions_compliancy = [ diff --git a/translations/pl.php b/translations/pl.php index c12742a..c39d914 100644 --- a/translations/pl.php +++ b/translations/pl.php @@ -146,7 +146,9 @@ $_MODULE['<{tpay}prestashop>tpay_a2436f156896e30797fae5cb4625ff06'] = 'Kod bezpieczeństwa (w powiadomieniach)'; $_MODULE['<{tpay}prestashop>tpay_321d4f2bb69eb9edd173cfd0c02500f2'] = 'Forma pola CRC'; $_MODULE['<{tpay}prestashop>tpay_542b1d933b6142f66e3cfb215ffa2f70'] = 'Widget przelewów'; -$_MODULE['<{tpay}prestashop>tpay_483fd2351d43804a57ac0f4406c2112a'] = 'Widget kart'; +$_MODULE['<{tpay}prestashop>tpay_9291570afa178cc68f9fa711153822bd'] = 'Własna kolejność'; +$_MODULE['<{tpay}prestashop>tpay_550cbbbc14019038a72c2b4aacd23061'] = 'Własna kolejność wyświetlanych banków. Przeciągnij, żeby zmienić kolejność'; +$_MODULE['<{tpay}prestashop>tpay_0e4929b5127c6468265b817bad986f8b'] = 'Własna kolejność wyświetlanych metod płatności. Przeciągnij, żeby zmienić kolejność';$_MODULE['<{tpay}prestashop>tpay_483fd2351d43804a57ac0f4406c2112a'] = 'Widget kart'; $_MODULE['<{tpay}prestashop>tpay_5add32cd1f3d800e55157999a7470db3'] = 'Wyświetl metodę płatności w widgecie'; $_MODULE['<{tpay}prestashop>tpay_30b95da4d0c97cd63150d7115f161d5c'] = 'Wyświetl metodę płatności w widgecie'; $_MODULE['<{tpay}prestashop>tpay_18059342ab22f4ce9dcb766714593cf1'] = 'Używaj konta Sandbox'; diff --git a/views/templates/_admin/configuration.tpl b/views/templates/_admin/configuration.tpl index 1b74220..51ae5bd 100644 --- a/views/templates/_admin/configuration.tpl +++ b/views/templates/_admin/configuration.tpl @@ -11,11 +11,13 @@ * @copyright 2010-2022 tpay.com * @license LICENSE.txt *} + From 9a622b418f4ef9fe07b86c28887e205f1e461b72 Mon Sep 17 00:00:00 2001 From: kGablo Date: Fri, 2 Aug 2024 12:23:58 +0200 Subject: [PATCH 2/9] Add custom order for banks and generic payments --- controllers/admin/TpayConfigurationController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/admin/TpayConfigurationController.php b/controllers/admin/TpayConfigurationController.php index 2d1c924..e168451 100644 --- a/controllers/admin/TpayConfigurationController.php +++ b/controllers/admin/TpayConfigurationController.php @@ -765,7 +765,7 @@ private function getChannels() private function sortPayment(string $field): array { $channels = $this->channels; - $chosenPayments = json_decode(Cfg::get($field), true); + $chosenPayments = json_decode(Cfg::get($field), true) ?? []; if (count($chosenPayments) > 0) { $orderedList = []; From 251a50473513401f15dc9da1af03c642f1175827 Mon Sep 17 00:00:00 2001 From: kGablo Date: Fri, 2 Aug 2024 12:42:51 +0200 Subject: [PATCH 3/9] Add custom order for banks and generic payments --- src/Util/Helper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Util/Helper.php b/src/Util/Helper.php index 98f9c7e..c00bfa3 100644 --- a/src/Util/Helper.php +++ b/src/Util/Helper.php @@ -45,6 +45,8 @@ public static function getFields(): array 'TPAY_BLIK_ACTIVE', 'TPAY_BLIK_WIDGET', 'TPAY_TRANSFER_WIDGET', + 'TPAY_CUSTOM_ORDER[]', + 'TPAY_CUSTOM_ORDER', 'TPAY_CARD_WIDGET', 'TPAY_INSTALLMENTS_ACTIVE', 'TPAY_PEKAO_INSTALLMENTS_ACTIVE', From d294575505a3c578c2c35ee8db222a119ddad2b4 Mon Sep 17 00:00:00 2001 From: kGablo Date: Mon, 5 Aug 2024 08:18:04 +0200 Subject: [PATCH 4/9] Add custom order for banks and generic payments --- controllers/admin/TpayConfigurationController.php | 2 +- translations/pl.php | 5 +++-- views/templates/_admin/configuration.tpl | 12 ++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/controllers/admin/TpayConfigurationController.php b/controllers/admin/TpayConfigurationController.php index e168451..36c8b0e 100644 --- a/controllers/admin/TpayConfigurationController.php +++ b/controllers/admin/TpayConfigurationController.php @@ -474,7 +474,7 @@ public function formPaymentOptions(): array 'name' => 'TPAY_CUSTOM_ORDER[]', 'multiple' => true, 'class' => 'child', - 'desc' => $this->module->l('Custom order of displayed banks. Drag to change order'), + 'desc' => $this->module->l('Custom order of displayed banks. Drag to change order. The ability to change the order of payment methods is possible when the "Direct bank redirect" option is enabled.'), 'size' => 20, 'options' => [ 'query' => $this->sortPayment('TPAY_CUSTOM_ORDER'), diff --git a/translations/pl.php b/translations/pl.php index c39d914..fb39274 100644 --- a/translations/pl.php +++ b/translations/pl.php @@ -147,8 +147,9 @@ $_MODULE['<{tpay}prestashop>tpay_321d4f2bb69eb9edd173cfd0c02500f2'] = 'Forma pola CRC'; $_MODULE['<{tpay}prestashop>tpay_542b1d933b6142f66e3cfb215ffa2f70'] = 'Widget przelewów'; $_MODULE['<{tpay}prestashop>tpay_9291570afa178cc68f9fa711153822bd'] = 'Własna kolejność'; -$_MODULE['<{tpay}prestashop>tpay_550cbbbc14019038a72c2b4aacd23061'] = 'Własna kolejność wyświetlanych banków. Przeciągnij, żeby zmienić kolejność'; -$_MODULE['<{tpay}prestashop>tpay_0e4929b5127c6468265b817bad986f8b'] = 'Własna kolejność wyświetlanych metod płatności. Przeciągnij, żeby zmienić kolejność';$_MODULE['<{tpay}prestashop>tpay_483fd2351d43804a57ac0f4406c2112a'] = 'Widget kart'; +$_MODULE['<{tpay}prestashop>tpay_520132326c61928684fbd55983f0ac64'] = 'Własna kolejność wyświetlanych banków. Przeciągnij, żeby zmienić kolejność. Możliwość zmiany kolejności metod płatności jest możliwa przy uruchomionej opcji "Bezpośrednie przekierowanie do banku".'; +$_MODULE['<{tpay}prestashop>tpay_0e4929b5127c6468265b817bad986f8b'] = 'Własna kolejność wyświetlanych metod płatności. Przeciągnij, żeby zmienić kolejność'; +$_MODULE['<{tpay}prestashop>tpay_483fd2351d43804a57ac0f4406c2112a'] = 'Widget kart'; $_MODULE['<{tpay}prestashop>tpay_5add32cd1f3d800e55157999a7470db3'] = 'Wyświetl metodę płatności w widgecie'; $_MODULE['<{tpay}prestashop>tpay_30b95da4d0c97cd63150d7115f161d5c'] = 'Wyświetl metodę płatności w widgecie'; $_MODULE['<{tpay}prestashop>tpay_18059342ab22f4ce9dcb766714593cf1'] = 'Używaj konta Sandbox'; diff --git a/views/templates/_admin/configuration.tpl b/views/templates/_admin/configuration.tpl index 51ae5bd..99b57fa 100644 --- a/views/templates/_admin/configuration.tpl +++ b/views/templates/_admin/configuration.tpl @@ -15,7 +15,7 @@ - - - - - {include file="module:tpay/views/templates/hook/regulations.tpl"} - diff --git a/views/templates/hook/gpay.tpl b/views/templates/hook/gpay.tpl deleted file mode 100644 index b7621de..0000000 --- a/views/templates/hook/gpay.tpl +++ /dev/null @@ -1,17 +0,0 @@ -{* -* NOTICE OF LICENSE -* -* This file is licenced under the Software License Agreement. -* With the purchase or the installation of the software in your application -* you accept the licence agreement. -* -* You must not modify, adapt or create derivative works of this source code -* -* @author tpay.com -* @copyright 2010-2020 tpay.com -* @license LICENSE.txt -*} -
- {l s='You will be redirected to the payment gateway.' mod='tpay'} - {include file="module:tpay/views/templates/hook/regulations.tpl"} -
diff --git a/views/templates/hook/installments.tpl b/views/templates/hook/installments.tpl deleted file mode 100644 index fca18a5..0000000 --- a/views/templates/hook/installments.tpl +++ /dev/null @@ -1,17 +0,0 @@ -{* -* NOTICE OF LICENSE -* -* This file is licenced under the Software License Agreement. -* With the purchase or the installation of the software in your application -* you accept the licence agreement. -* -* You must not modify, adapt or create derivative works of this source code -* -* @author tpay.com -* @copyright 2010-2020 tpay.com -* @license LICENSE.txt -*} -
- {l s='You will be redirected to the payment gateway.' mod='tpay'} - {include file="module:tpay/views/templates/hook/regulations.tpl"} -
diff --git a/views/templates/hook/pekao_installments.tpl b/views/templates/hook/pekao_installments.tpl deleted file mode 100644 index 4547675..0000000 --- a/views/templates/hook/pekao_installments.tpl +++ /dev/null @@ -1,46 +0,0 @@ -{* -* NOTICE OF LICENSE -* -* This file is licenced under the Software License Agreement. -* With the purchase or the installation of the software in your application -* you accept the licence agreement. -* -* You must not modify, adapt or create derivative works of this source code -* -* @author tpay.com -* @copyright 2010-2020 tpay.com -* @license LICENSE.txt -*} - -
- {if isset($available_channels) && $available_channels} - -
- - -
    - {foreach $available_channels as $id} - - {/foreach} -
-
- - - - {include file="module:tpay/views/templates/hook/regulations.tpl"} - {else} - {l s='No active installment gateways' mod='tpay'} - {/if} -
From 1d52285d2b61c9917e86de6fff51ef72f1faf552 Mon Sep 17 00:00:00 2001 From: kGablo Date: Tue, 6 Aug 2024 09:36:20 +0200 Subject: [PATCH 7/9] Add custom order for banks and generic payments --- controllers/admin/TpayConfigurationController.php | 7 +++++-- src/Service/PaymentOptions/PaymentOptionsService.php | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/controllers/admin/TpayConfigurationController.php b/controllers/admin/TpayConfigurationController.php index 5f99194..4f0101c 100644 --- a/controllers/admin/TpayConfigurationController.php +++ b/controllers/admin/TpayConfigurationController.php @@ -134,9 +134,9 @@ public function createForm(): array $this->getChannels(); $form[] = $this->formBasicOptions(); $form[] = $this->formPaymentOptions(); + $form[] = $this->formGenericPaymentOptions(); $form[] = $this->formCardOptions(); $form[] = $this->formStatusesOptions(); - $form[] = $this->formGenericPaymentOptions(); return $form; } @@ -646,7 +646,10 @@ private function formGenericPaymentOptions(): array return [ 'form' => [ - 'legend' => ['title' => 'Generic payments', 'icon' => 'icon-cogs'], + 'legend' => [ + 'title' => $this->module->l('Generic payments'), + 'icon' => 'icon-cogs' + ], 'input' => [ [ 'type' => 'select', diff --git a/src/Service/PaymentOptions/PaymentOptionsService.php b/src/Service/PaymentOptions/PaymentOptionsService.php index 35cc782..2de27f5 100644 --- a/src/Service/PaymentOptions/PaymentOptionsService.php +++ b/src/Service/PaymentOptions/PaymentOptionsService.php @@ -122,7 +122,9 @@ private function createGateway(array $array = []): void */ private function getSeparatePayments(array $channels): array { - $paymentsMethods = []; + $paymentsMethods = [ + Config::GATEWAY_BLIK => (bool)Helper::getMultistoreConfigurationValue('TPAY_BLIK_ACTIVE'), + ]; if ($this->hasActiveCard()) { $paymentsMethods[Config::GATEWAY_CARD] = (bool)Helper::getMultistoreConfigurationValue( From f0aab40bd4d097ec081df5eb977383f89fda58aa Mon Sep 17 00:00:00 2001 From: kGablo Date: Tue, 6 Aug 2024 13:50:40 +0200 Subject: [PATCH 8/9] Add custom order for banks and generic payments --- controllers/front/confirmation.php | 1 - 1 file changed, 1 deletion(-) diff --git a/controllers/front/confirmation.php b/controllers/front/confirmation.php index 043a9e9..ab6fb55 100644 --- a/controllers/front/confirmation.php +++ b/controllers/front/confirmation.php @@ -23,7 +23,6 @@ public function initContent() $type = Tools::getValue('type'); switch ($type) { - case Config::TPAY_PAYMENT_INSTALLMENTS: case Config::TPAY_PAYMENT_BASIC: case Config::TPAY_PAYMENT_BLIK: case Config::TPAY_PAYMENT_CARDS: From 6f74ffc363ada82e7f520ef1c0996baade0514e0 Mon Sep 17 00:00:00 2001 From: kGablo Date: Wed, 7 Aug 2024 11:18:08 +0200 Subject: [PATCH 9/9] Add custom order for banks and generic payments --- src/Hook/Payment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hook/Payment.php b/src/Hook/Payment.php index e725f34..0426f6f 100644 --- a/src/Hook/Payment.php +++ b/src/Hook/Payment.php @@ -49,7 +49,7 @@ public function paymentOptions($params) 'clause_url' => 'https://tpay.com/user/assets/files_for_download/information-clause-payer.pdf' ]; - if ($this->context->language->getIsoCode() == 'pl') { + if (substr($this->context->currentLocale->getCode(), 0, 2) == 'pl') { $langData = [ 'regulation_url' => 'https://secure.tpay.com/regulamin.pdf', 'clause_url' => 'https://tpay.com/user/assets/files_for_download/klauzula-informacyjna-platnik.pdf'