Browse Source

Merge pull request #970 from firefly-iii/release-1757995507

🤖 Automatically merge the PR into the develop branch.
pull/971/head develop-20250916.1
github-actions[bot] 4 weeks ago
committed by GitHub
parent
commit
763fe77994
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 63
      app/Services/Nordigen/Model/Transaction.php
  2. 3
      app/Services/Nordigen/Request/GetTransactionsRequest.php
  3. 10
      app/Services/Nordigen/Response/GetTransactionsResponse.php
  4. 2
      config/importer.php

63
app/Services/Nordigen/Model/Transaction.php

@ -90,7 +90,7 @@ class Transaction
public string $ultimateDebtor;
// new fields
public ?Carbon $valueDate = null;
public ?Carbon $valueDate = null;
/**
* Creates a transaction from a downloaded array.
@ -100,12 +100,12 @@ class Transaction
public static function fromArray($array): self
{
Log::debug('GoCardless transaction from array', $array);
$object = new self();
$object->tags = [];
$object->additionalInformation = trim($array['additionalInformation'] ?? '');
$object->additionalInformationStructured = trim($array['additionalInformationStructured'] ?? '');
$object->bankTransactionCode = trim($array['bankTransactionCode'] ?? '');
$object->bookingDate = array_key_exists('bookingDate', $array) ? Carbon::createFromFormat('!Y-m-d', $array['bookingDate'], config('app.timezone')) : null;
$object = new self();
$object->tags = [];
$object->additionalInformation = trim($array['additionalInformation'] ?? '');
$object->additionalInformationStructured = trim($array['additionalInformationStructured'] ?? '');
$object->bankTransactionCode = trim($array['bankTransactionCode'] ?? '');
$object->bookingDate = array_key_exists('bookingDate', $array) ? Carbon::createFromFormat('!Y-m-d', $array['bookingDate'], config('app.timezone')) : null;
// overrule with "bookingDateTime" if present:
if (array_key_exists('bookingDateTime', $array)) {
@ -139,11 +139,11 @@ class Transaction
$object->valueDate = array_key_exists('valueDate', $array) ? Carbon::createFromFormat('!Y-m-d', $array['valueDate'], config('app.timezone')) : null;
// undocumented values
$object->endToEndId = trim($array['endToEndId'] ?? ''); // from Rabobank NL
$object->endToEndId = trim($array['endToEndId'] ?? ''); // from Rabobank NL
// overrule transaction id when empty using the internal ID:
// 2025-09-07: switch to using internal transaction ID, never "transactionId".
$object->transactionId = trim($array['internalTransactionId'] ?? '');
$object->transactionId = trim($array['internalTransactionId'] ?? '');
// models:
if (array_key_exists('balanceAfterTransaction', $array) && is_array($array['balanceAfterTransaction'])) {
@ -158,35 +158,35 @@ class Transaction
}
// add "pending" or "booked" if it exists.
$key = (string)$array['key'];
$key = (string)$array['key'];
if ('' !== $key) {
$object->tags[] = $key;
}
// add merchant category code, if it exists:
$merchantCode = (string)($array['merchant_category_code'] ?? '');
$merchantCode = (string)($array['merchant_category_code'] ?? '');
if ('' !== $merchantCode) {
$object->tags[] = $merchantCode;
}
// array values:
$object->creditorAccountIban = trim($array['creditorAccount']['iban'] ?? '');
$object->creditorAccountBban = trim($array['creditorAccount']['bban'] ?? '');
$object->creditorAccountCurrency = trim($array['creditorAccount']['currency'] ?? '');
$object->creditorAccountIban = trim($array['creditorAccount']['iban'] ?? '');
$object->creditorAccountBban = trim($array['creditorAccount']['bban'] ?? '');
$object->creditorAccountCurrency = trim($array['creditorAccount']['currency'] ?? '');
$object->debtorAccountIban = trim($array['debtorAccount']['iban'] ?? '');
$object->debtorAccountBban = trim($array['debtorAccount']['bban'] ?? '');
$object->debtorAccountCurrency = trim($array['debtorAccount']['currency'] ?? '');
$object->debtorAccountIban = trim($array['debtorAccount']['iban'] ?? '');
$object->debtorAccountBban = trim($array['debtorAccount']['bban'] ?? '');
$object->debtorAccountCurrency = trim($array['debtorAccount']['currency'] ?? '');
$object->transactionAmount = trim($array['transactionAmount']['amount'] ?? '');
$object->currencyCode = trim($array['transactionAmount']['currency'] ?? '');
$object->transactionAmount = trim($array['transactionAmount']['amount'] ?? '');
$object->currencyCode = trim($array['transactionAmount']['currency'] ?? '');
// other fields:
$object->accountIdentifier = $array['account_id'] ?? '';
$object->accountIdentifier = $array['account_id'] ?? '';
// generate transactionID if empty:
if ('' === $object->transactionId) {
$hash = hash('sha256', (string)microtime());
$hash = hash('sha256', (string)microtime());
try {
$hash = hash('sha256', json_encode($array, JSON_THROW_ON_ERROR));
@ -209,7 +209,7 @@ class Transaction
*/
public static function fromLocalArray(array $array): self
{
$object = new self();
$object = new self();
$object->tags = [];
$object->additionalInformation = $array['additional_information'];
@ -248,23 +248,23 @@ class Transaction
}
// undocumented values:
$object->endToEndId = $array['end_to_end_id'];
$object->endToEndId = $array['end_to_end_id'];
// TODO copy paste code.
$object->debtorAccountIban = array_key_exists('iban', $array['debtor_account']) ? $array['debtor_account']['iban'] : '';
$object->creditorAccountIban = array_key_exists('iban', $array['creditor_account']) ? $array['creditor_account']['iban'] : '';
$object->debtorAccountIban = array_key_exists('iban', $array['debtor_account']) ? $array['debtor_account']['iban'] : '';
$object->creditorAccountIban = array_key_exists('iban', $array['creditor_account']) ? $array['creditor_account']['iban'] : '';
$object->debtorAccountBban = array_key_exists('bban', $array['debtor_account']) ? $array['debtor_account']['bban'] : '';
$object->creditorAccountBban = array_key_exists('bban', $array['creditor_account']) ? $array['creditor_account']['bban'] : '';
$object->debtorAccountBban = array_key_exists('bban', $array['debtor_account']) ? $array['debtor_account']['bban'] : '';
$object->creditorAccountBban = array_key_exists('bban', $array['creditor_account']) ? $array['creditor_account']['bban'] : '';
$object->debtorAccountCurrency = array_key_exists('currency', $array['debtor_account']) ? $array['debtor_account']['currency'] : '';
$object->creditorAccountCurrency = array_key_exists('currency', $array['creditor_account']) ? $array['creditor_account']['currency'] : '';
$object->debtorAccountCurrency = array_key_exists('currency', $array['debtor_account']) ? $array['debtor_account']['currency'] : '';
$object->creditorAccountCurrency = array_key_exists('currency', $array['creditor_account']) ? $array['creditor_account']['currency'] : '';
// $object-> = $array[''];
// generate transactionID if empty:
if ('' === $object->transactionId) {
$hash = hash('sha256', (string)microtime());
$hash = hash('sha256', (string)microtime());
try {
$hash = hash('sha256', json_encode($array, JSON_THROW_ON_ERROR));
@ -347,6 +347,7 @@ class Transaction
$transactionId = substr(trim((string)preg_replace('/\s+/', ' ', $this->transactionId)), 0, 125);
Log::debug(sprintf('Returning transaction ID: %s and %s are joined.', $accountId, $transactionId));
return trim(sprintf('%s-%s', $accountId, $transactionId));
}
@ -430,7 +431,7 @@ class Transaction
// room for other fields
if (str_contains("\n", $this->getDescription())) {
$notes .= "\n\n" . $this->getDescription();
$notes .= "\n\n".$this->getDescription();
}
return trim($notes);

3
app/Services/Nordigen/Request/GetTransactionsRequest.php

@ -39,6 +39,7 @@ use Illuminate\Support\Facades\Log;
class GetTransactionsRequest extends Request
{
private string $identifier = '';
public function __construct(string $url, string $token, string $identifier)
{
$this->identifier = $identifier;
@ -78,7 +79,7 @@ class GetTransactionsRequest extends Request
}
$total = count($return);
Log::debug(sprintf('Downloaded [%d:%d] transactions from bank account "%s"', $count, $total, $this->identifier));
$response = new GetTransactionsResponse($return);
$response = new GetTransactionsResponse($return);
$response->setAccountId($this->identifier);
$response->processData();

10
app/Services/Nordigen/Response/GetTransactionsResponse.php

@ -39,13 +39,13 @@ class GetTransactionsResponse extends Response implements Iterator, Countable
{
private readonly Collection $collection;
private int $position = 0;
private string $accountId = '';
private string $accountId = '';
private array $data;
public function __construct(array $data)
{
$this->collection = new Collection();
$this->data = $data;
$this->data = $data;
Log::debug('Created new GetTransactionsResponse');
@ -57,8 +57,10 @@ class GetTransactionsResponse extends Response implements Iterator, Countable
Log::debug(sprintf('Set account ID to "%s" in GetTransactionsResponse', $accountId));
}
public function processData(): void {
public function processData(): void
{
Log::debug('Processing data in GetTransactionsResponse');
/** @var array $array */
foreach ($this->data as $array) {
$array['account_id'] = $this->accountId;
@ -67,8 +69,6 @@ class GetTransactionsResponse extends Response implements Iterator, Countable
Log::debug('Done processing data in GetTransactionsResponse');
}
/**
* Count elements of an object.
*

2
config/importer.php

@ -25,7 +25,7 @@ declare(strict_types=1);
return [
'version' => 'develop/2025-09-16',
'build_time' => 1757993195,
'build_time' => 1757995468,
'flows' => ['nordigen', 'spectre', 'file', 'simplefin'],
'enabled_flows' => [
'nordigen' => true,

Loading…
Cancel
Save