Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/111' into 653
Browse files Browse the repository at this point in the history
# Conflicts:
#	views/templates/_admin/configuration.tpl
  • Loading branch information
krzGablo committed Aug 27, 2024
2 parents 67db651 + 6f74ffc commit 4c22038
Show file tree
Hide file tree
Showing 23 changed files with 222 additions and 652 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
154 changes: 60 additions & 94 deletions controllers/admin/TpayConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -97,7 +102,6 @@ public function getOrderStates(): array
return OrderState::getOrderStates(Context::getContext()->language->id);
}


protected function getWarningMultishopHtml()
{
if (Shop::getContext() == Shop::CONTEXT_GROUP) {
Expand Down Expand Up @@ -127,12 +131,13 @@ protected function contextIsGroup(): bool

public function createForm(): array
{
$this->getChannels();
$form[] = $this->formBasicOptions();
$form[] = $this->formPeKaoInstallments();
$form[] = $this->formPaymentOptions();
$form[] = $this->formGenericPaymentOptions();
$form[] = $this->formCardOptions();
$form[] = $this->formStatusesOptions();
$form[] = $this->formGenericPaymentOptions();

return $form;
}
Expand Down Expand Up @@ -563,86 +568,17 @@ public function formPaymentOptions(): array
],

[
'type' => 'switch',
'label' => $this->module->l('GooglePay'),
'name' => 'TPAY_GPAY_ACTIVE',
'desc' => $this->module->l('Show the method as a separate payment'),
'is_bool' => true,
'class' => 't',
'values' => [
[
'id' => 'tpay_active_on',
'value' => 1,
'label' => $this->module->l('Yes'),
],
[
'id' => 'tpay_active_off',
'value' => 0,
'label' => $this->module->l('No'),
],
],
],

[
'type' => 'switch',
'label' => $this->module->l('Alior Installment (from 300 PLN to 13 888,00 PLN)'),
'name' => 'TPAY_INSTALLMENTS_ACTIVE',
'desc' => $this->module->l('Show the method as a separate payment'),
'is_bool' => true,
'class' => 't',
'values' => [
[
'id' => 'tpay_installments_on',
'value' => 1,
'label' => $this->module->l('Yes'),
],
[
'id' => 'tpay_installments_off',
'value' => 0,
'label' => $this->module->l('No'),
],
],
],

[
'type' => 'switch',
'label' => $this->module->l('Pekao Installment (from 100 PLN to 20 000 PLN)'),
'name' => 'TPAY_PEKAO_INSTALLMENTS_ACTIVE',
'desc' => $this->module->l('Show the method as a separate payment'),
'is_bool' => true,
'class' => 't',
'values' => [
[
'id' => 'tpay_pekao_installments_on',
'value' => 1,
'label' => $this->module->l('Yes'),
],
[
'id' => 'tpay_pekao_installments_off',
'value' => 0,
'label' => $this->module->l('No'),
],
],
],

[
'type' => 'switch',
'label' => sprintf($this->module->l('Twisto - Buy now, pay later (from 1 PLN to 1 500 PLN)')),
'name' => 'TPAY_TWISTO_ACTIVE',
'desc' => $this->module->l('Show the method as a separate payment'),
'is_bool' => true,
'class' => 't',
'values' => [
[
'id' => 'tpay_installments_on',
'value' => 1,
'label' => $this->module->l('Yes'),
],
[
'id' => 'tpay_installments_off',
'value' => 0,
'label' => $this->module->l('No'),
],
'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. 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'),
'id' => 'id',
'name' => 'fullName'
],
],
],
Expand Down Expand Up @@ -805,35 +741,65 @@ 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' => [
'legend' => ['title' => 'Generic payments', 'icon' => 'icon-cogs'],
'legend' => [
'title' => $this->module->l('Generic payments'),
'icon' => 'icon-cogs'
],
'input' => [
[
'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'
'name' => 'fullName'
],
]
],
'submit' => ['title' => $this->module->l('Save')],
]
];
}

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;
}
}
1 change: 0 additions & 1 deletion controllers/front/confirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 0 additions & 32 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,18 @@ class Config
public const TPAY_PAYMENT_CARDS = 'cards';
public const TPAY_PAYMENT_BLIK = 'blik';
public const TPAY_PAYMENT_GPAY = 'gpay';
public const TPAY_PAYMENT_INSTALLMENTS = 'installments';
public const TPAY_PAYMENT_GENERIC = 'generic';

public const TPAY_GATEWAY_ALIOR_RATY = 109;
public const TPAY_GATEWAY_PEKAO_RATY = 169;
public const TPAY_GATEWAY_TWISTO = 167;
public const TPAY_GATEWAY_PAYPO = 172;
public const TPAY_GATEWAY_GOOGLE_PAY = 166;

/// IDS to get bank channels
public const GATEWAY_TWISTO = 71; //71

public const GATEWAY_PAYPO = 83;
public const GATEWAY_ALIOR_RATY = 49; // 49
public const GATEWAY_CARD = 53;
public const GATEWAY_BLIK = 64;
public const GATEWAY_BLIK_0 = 150;
public const GATEWAY_GOOGLE_PAY = 68;

public const GATEWAY_TRANSFER = 999;

public const GATEWAY_APPLE_PAY = 9999;
public const GATEWAYS_PEKAO_RATY_3x0 = 78;
public const GATEWAYS_PEKAO_RATY_10x0 = 80;

public const GATEWAYS_PEKAO_RATY_50 = 81;
public const GATEWAYS_PEKAO_RATY = 77;

public const CARD_GROUP_ID = 103;

public const TPAY_VIEW_REDIRECT = 0;
public const TPAY_SURCHARGE_AMOUNT = 0;
public const TPAY_SURCHARGE_PERCENT = 1;
public const TPAY_PATH = 'module:tpay/views/templates/front';

public const TWISTO_MIN = 1.00;
public const TWISTO_MAX = 1500;
public const ALIOR_RATY_MIN = 300;
public const ALIOR_RATY_MAX = 13888.00;

public const PEKAO_RATY_MIN = 100;
public const PEKAO_RATY_MAX = 20000;

public const PAYPO_MIN = 40;

public const PAYPO_MAX = 3000;
}
1 change: 0 additions & 1 deletion src/Factory/PaymentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static function getPaymentMethod(string $type)
{
switch ($type) {
case Config::TPAY_PAYMENT_BASIC:
case Config::TPAY_PAYMENT_INSTALLMENTS:
case Config::TPAY_PAYMENT_GPAY:
case Config::TPAY_PAYMENT_BLIK:
return new BasicPaymentHandler();
Expand Down
20 changes: 0 additions & 20 deletions src/Factory/PaymentOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
use Tpay\Service\PaymentOptions\Blik;
use Tpay\Service\PaymentOptions\Card;
use Tpay\Service\PaymentOptions\GatewayType;
use Tpay\Service\PaymentOptions\Generic;
use Tpay\Service\PaymentOptions\GooglePay;
use Tpay\Service\PaymentOptions\AliorInstallment;
use Tpay\Service\PaymentOptions\PekaoInstallment;
use Tpay\Service\PaymentOptions\Transfer;
use Tpay\Service\PaymentOptions\Twisto;

class PaymentOptionsFactory
{
Expand All @@ -40,27 +35,12 @@ public static function getOptionById(int $id)
case Config::GATEWAY_TRANSFER:
$paymentMethod = new Transfer();
break;
case Config::GATEWAY_ALIOR_RATY:
$paymentMethod = new AliorInstallment();
break;
case Config::GATEWAY_CARD:
$paymentMethod = new Card();
break;
case Config::GATEWAY_TWISTO:
$paymentMethod = new Twisto();
break;
case Config::GATEWAY_BLIK:
$paymentMethod = new Blik();
break;
case Config::GATEWAY_GOOGLE_PAY:
$paymentMethod = new GooglePay();
break;
case Config::GATEWAYS_PEKAO_RATY:
case Config::GATEWAYS_PEKAO_RATY_50:
case Config::GATEWAYS_PEKAO_RATY_10x0:
case Config::GATEWAYS_PEKAO_RATY_3x0:
$paymentMethod = new PekaoInstallment();
break;
default:
$paymentMethod = '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/Hook/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions src/Service/ConstraintValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function validate(array $constraints, string $browser): bool
if (!$this->validateMaximalTotal((float) $constraint['value'])) {
return false;
}

break;
case 'supported':
return $this->isApplePayPossible($constraint['field'], $browser);
default:
Expand Down
Loading

0 comments on commit 4c22038

Please sign in to comment.