diff --git a/plugins/fio_cz/fio_cz.zip b/plugins/fio_cz/fio_cz.zip index 19e344ea..ccb75d6f 100644 Binary files a/plugins/fio_cz/fio_cz.zip and b/plugins/fio_cz/fio_cz.zip differ diff --git a/plugins/fio_cz/src/composer.lock b/plugins/fio_cz/src/composer.lock index cb1a3e48..50445b0d 100644 --- a/plugins/fio_cz/src/composer.lock +++ b/plugins/fio_cz/src/composer.lock @@ -270,16 +270,16 @@ }, { "name": "php-di/php-di", - "version": "7.0.2", + "version": "7.0.7", "source": { "type": "git", "url": "https://github.com/PHP-DI/PHP-DI.git", - "reference": "5d1a8664e24f23b25e0426bbcb1288287fb49181" + "reference": "e87435e3c0e8f22977adc5af0d5cdcc467e15cf1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/5d1a8664e24f23b25e0426bbcb1288287fb49181", - "reference": "5d1a8664e24f23b25e0426bbcb1288287fb49181", + "url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/e87435e3c0e8f22977adc5af0d5cdcc467e15cf1", + "reference": "e87435e3c0e8f22977adc5af0d5cdcc467e15cf1", "shasum": "" }, "require": { @@ -293,13 +293,13 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3", + "friendsofphp/proxy-manager-lts": "^1", "mnapoli/phpunit-easymock": "^1.3", - "ocramius/proxy-manager": "^2.11.2", "phpunit/phpunit": "^9.5", "vimeo/psalm": "^4.6" }, "suggest": { - "ocramius/proxy-manager": "Install it if you want to use lazy injection (version ^2.3)" + "friendsofphp/proxy-manager-lts": "Install it if you want to use lazy injection (version ^1)" }, "type": "library", "autoload": { @@ -327,7 +327,7 @@ ], "support": { "issues": "https://github.com/PHP-DI/PHP-DI/issues", - "source": "https://github.com/PHP-DI/PHP-DI/tree/7.0.2" + "source": "https://github.com/PHP-DI/PHP-DI/tree/7.0.7" }, "funding": [ { @@ -339,7 +339,7 @@ "type": "tidelift" } ], - "time": "2023-02-07T17:34:03+00:00" + "time": "2024-07-21T15:55:45+00:00" }, { "name": "psr/container", diff --git a/plugins/fio_cz/src/manifest.json b/plugins/fio_cz/src/manifest.json index 378e6052..a3ed5bd0 100644 --- a/plugins/fio_cz/src/manifest.json +++ b/plugins/fio_cz/src/manifest.json @@ -5,7 +5,7 @@ "displayName": "Fio bank payment import", "description": "This plugin enables you to import payments from Fio bank to UCRM. See https://www.fio.cz/bankovni-sluzby/api-bankovnictvi", "url": "https://github.com/Ubiquiti-App/UCRM-plugins/tree/master/plugins/fio_cz", - "version": "1.2.12", + "version": "1.2.13", "unmsVersionCompliancy": { "min": "2.1.0", "max": null @@ -30,7 +30,7 @@ { "key": "paymentMatchAttribute", "label": "Match attribute from payment variable symbol to UCRM", - "description": "Can be 'invoiceNumber', 'clientId', 'clientUserIdent' or a custom attribute key.", + "description": "Can be 'invoiceNumber', 'clientId', 'clientUserIdent' or a custom attribute key. Also is possible to fill multiple attributes sorted by priority and separated by semicolon (eg. 'invoiceNumber; clientUserIdent')", "required": 1, "type": "text" }, diff --git a/plugins/fio_cz/src/src/Facade/UcrmFacade.php b/plugins/fio_cz/src/src/Facade/UcrmFacade.php index 5d8b9d82..cb31b361 100644 --- a/plugins/fio_cz/src/src/Facade/UcrmFacade.php +++ b/plugins/fio_cz/src/src/Facade/UcrmFacade.php @@ -10,26 +10,11 @@ class UcrmFacade { - /** - * @var Logger - */ - private $logger; - - /** - * @var OptionsManager - */ - private $optionsManager; - - /** - * @var UcrmApi - */ - private $ucrmApi; - - public function __construct(Logger $logger, OptionsManager $optionsManager, UcrmApi $ucrmApi) - { - $this->logger = $logger; - $this->optionsManager = $optionsManager; - $this->ucrmApi = $ucrmApi; + public function __construct( + private Logger $logger, + private OptionsManager $optionsManager, + private UcrmApi $ucrmApi + ) { } /** @@ -44,9 +29,18 @@ public function import( $this->logger->info(sprintf('Processing transaction %s.', $transaction['id'])); - $matched = $this->matchClientFromUcrm($transaction, $optionsData->paymentMatchAttribute); - if ($matched || $optionsData->importUnattached) { - if ($matched) { + $matchAttributes = explode(';', $optionsData->paymentMatchAttribute); + + $matched = null; + foreach ($matchAttributes as $matchAttribute) { + $matched = $this->matchClientFromUcrm($transaction, $matchAttribute); + if ($matched !== null) { + break; + } + } + + if ($matched !== null || $optionsData->importUnattached) { + if ($matched !== null) { [$clientId, $invoiceId] = $matched; $this->logger->info(sprintf('Matched transaction %s to client %s, invoice %s', $transaction['id'], $clientId, $invoiceId)); } else { @@ -87,8 +81,13 @@ public function getPaymentMethod(): string * @throws \FioCz\Exception\CurlException * @throws \ReflectionException */ - private function matchClientFromUcrm(array $transaction, $matchBy): ?array + private function matchClientFromUcrm(array $transaction, string $matchBy): ?array { + $matchBy = trim($matchBy); + if ($matchBy === '') { + return null; + } + $endpoint = 'clients'; if ($matchBy === 'invoiceNumber') {