Skip to content

Commit

Permalink
Merge pull request #343 from Ubiquiti-App/feature/UCRM-6243-fio-plugi…
Browse files Browse the repository at this point in the history
…n-add-secondary-parameter

UCRM 6243 - FIO Plugin - add secondary parameter
  • Loading branch information
keksa authored Jan 28, 2025
2 parents 50f38c9 + a618c73 commit 84b46ff
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
Binary file modified plugins/fio_cz/fio_cz.zip
Binary file not shown.
16 changes: 8 additions & 8 deletions plugins/fio_cz/src/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions plugins/fio_cz/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
},
Expand Down
47 changes: 23 additions & 24 deletions plugins/fio_cz/src/src/Facade/UcrmFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand All @@ -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 {
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit 84b46ff

Please sign in to comment.