Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UCRM 6243 - FIO Plugin - add secondary parameter #343

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading