latest changes

This commit is contained in:
paulwer 2023-12-09 17:16:01 +01:00
parent f3dfdc4d80
commit fa5edbc29c
3 changed files with 27 additions and 14 deletions

View File

@ -114,10 +114,17 @@ class Nordigen
} }
/**
* this method returns booked transactions from the bank_account, pending transactions are not part of the result
* @todo @turbo124 should we include pending transactions within the integration-process and mark them with a specific category?!
*/
public function getTransactions(string $accountId, string $dateFrom = null) public function getTransactions(string $accountId, string $dateFrom = null)
{ {
return $this->client->account($accountId)->getAccountTransactions($dateFrom); $transactionResponse = $this->client->account($accountId)->getAccountTransactions($dateFrom);
$it = new IncomeTransformer();
return $it->transform($transactionResponse);
} }
} }

View File

@ -65,7 +65,22 @@ class IncomeTransformer implements BankRevenueInterface
{ {
use AppSetup; use AppSetup;
public function transform(BankIntegration $bank_integration, $transaction) public function transform($transaction)
{
$data = [];
if (!property_exists($transaction, 'transactions') || !property_exists($transaction->transactions, 'booked'))
throw new \Exception('invalid dataset');
foreach ($transaction->transactions->booked as $transaction) {
$data[] = $this->transformTransaction($transaction);
}
return $data;
}
public function transformTransaction($transaction)
{ {
if (!property_exists($transaction, 'transactionId') || !property_exists($transaction, 'transactionAmount') || !property_exists($transaction, 'balances') || !property_exists($transaction, 'institution')) if (!property_exists($transaction, 'transactionId') || !property_exists($transaction, 'transactionAmount') || !property_exists($transaction, 'balances') || !property_exists($transaction, 'institution'))
@ -75,11 +90,9 @@ class IncomeTransformer implements BankRevenueInterface
'transaction_id' => $transaction->transactionId, 'transaction_id' => $transaction->transactionId,
'amount' => abs($transaction->transactionAmount->amount), 'amount' => abs($transaction->transactionAmount->amount),
'currency_id' => $this->convertCurrency($transaction->transactionAmount->currency), 'currency_id' => $this->convertCurrency($transaction->transactionAmount->currency),
'account_type' => 'bank', 'category_id' => $transaction->highLevelCategoryId, // TODO
'category_id' => $transaction->highLevelCategoryId, 'category_type' => $transaction->categoryType, // TODO
'category_type' => $transaction->categoryType,
'date' => $transaction->bookingDate, 'date' => $transaction->bookingDate,
'bank_account_id' => $bank_integration->id,
'description' => $transaction->remittanceInformationUnstructured, 'description' => $transaction->remittanceInformationUnstructured,
'base_type' => $transaction->transactionAmount->amount > 0 ? 'DEBIT' : 'CREDIT', 'base_type' => $transaction->transactionAmount->amount > 0 ? 'DEBIT' : 'CREDIT',
]; ];

View File

@ -99,18 +99,11 @@ class ProcessBankTransactionsNordigen implements ShouldQueue
return; return;
} }
$data = [
'top' => 500,
'fromDate' => $this->from_date,
'accountId' => $this->bank_integration->bank_account_id,
'skip' => $this->skip,
];
//Get transaction count object //Get transaction count object
$transactions = $nordigen->getTransactions($this->bank_integration->bank_account_id, $this->from_date); $transactions = $nordigen->getTransactions($this->bank_integration->bank_account_id, $this->from_date);
//Get int count //Get int count
$count = sizeof($transactions->transactions->booked); $count = sizeof($transactions);
//if no transactions, update the from_date and move on //if no transactions, update the from_date and move on
if (count($transactions) == 0) { if (count($transactions) == 0) {