mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
minor additions for IncomeTransformer
This commit is contained in:
parent
fa5edbc29c
commit
a244faaaee
@ -92,28 +92,6 @@ class Nordigen
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* this method will remove all according requisitions => this can result in removing multiple accounts, if a user reuses a requisition
|
||||
*/
|
||||
public function deleteAccount(string $account_id)
|
||||
{
|
||||
|
||||
// get all valid requisitions
|
||||
$requisitions = $this->client->requisition->getRequisitions();
|
||||
|
||||
// fetch all valid accounts for activated requisitions
|
||||
foreach ($requisitions as $requisition) {
|
||||
foreach ($requisition->accounts as $accountId) {
|
||||
|
||||
if ($accountId) {
|
||||
$this->client->requisition->deleteRequisition($accountId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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?!
|
||||
|
@ -83,33 +83,35 @@ use App\Helpers\Bank\AccountTransformerInterface;
|
||||
*/
|
||||
|
||||
|
||||
class AccountTransformer implements AccountTransformerInterface {
|
||||
class AccountTransformer implements AccountTransformerInterface
|
||||
{
|
||||
|
||||
public function transform($nordigen_account) {
|
||||
public function transform($nordigen_account)
|
||||
{
|
||||
|
||||
if(!property_exists($nordigen_account, 'data') || !property_exists($nordigen_account, 'metadata') || !property_exists($nordigen_account, 'balances') || !property_exists($nordigen_account, 'institution'))
|
||||
if (!property_exists($nordigen_account, 'data') || !property_exists($nordigen_account, 'metadata') || !property_exists($nordigen_account, 'balances') || !property_exists($nordigen_account, 'institution'))
|
||||
throw new \Exception('invalid dataset');
|
||||
|
||||
$used_balance = $nordigen_account->balances[0];
|
||||
// prefer entry with closingBooked
|
||||
foreach($nordigen_account->balances as $entry) {
|
||||
if($entry["balanceType"] === 'closingBooked') { // available: closingBooked, interimAvailable
|
||||
foreach ($nordigen_account->balances as $entry) {
|
||||
if ($entry["balanceType"] === 'closingBooked') { // available: closingBooked, interimAvailable
|
||||
$used_balance = $entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $nordigen_account->metadata["id"],
|
||||
'id' => 'nordigen:' . $nordigen_account->metadata["id"],
|
||||
'account_type' => "bank",
|
||||
'account_name' => $nordigen_account->data["iban"],
|
||||
'account_status' => $nordigen_account->metadata["status"],
|
||||
'account_number' => '**** '.substr($nordigen_account->data["iban"], -7),
|
||||
'provider_account_id' => $nordigen_account->data["iban"],
|
||||
'account_number' => '**** ' . substr($nordigen_account->data["iban"], -7),
|
||||
'provider_account_id' => $nordigen_account->metadata["id"],
|
||||
'provider_id' => $nordigen_account->institution["id"],
|
||||
'provider_name' => $nordigen_account->institution["name"],
|
||||
'nickname' => $nordigen_account->data["ownerName"] ? $nordigen_account->data["ownerName"] : '',
|
||||
'current_balance' => (int)$used_balance ? $used_balance["balanceAmount"]["amount"] : 0,
|
||||
'current_balance' => (int) $used_balance ? $used_balance["balanceAmount"]["amount"] : 0,
|
||||
'account_currency' => $used_balance ? $used_balance["balanceAmount"]["currency"] : '',
|
||||
];
|
||||
|
||||
|
@ -15,6 +15,7 @@ use App\Helpers\Bank\BankRevenueInterface;
|
||||
use App\Models\BankIntegration;
|
||||
use App\Utils\Traits\AppSetup;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
{
|
||||
@ -65,15 +66,16 @@ class IncomeTransformer implements BankRevenueInterface
|
||||
{
|
||||
use AppSetup;
|
||||
|
||||
public function transform($transaction)
|
||||
public function transform($transactionResponse)
|
||||
{
|
||||
|
||||
Log::info($transactionResponse);
|
||||
$data = [];
|
||||
|
||||
if (!property_exists($transaction, 'transactions') || !property_exists($transaction->transactions, 'booked'))
|
||||
if (!array_key_exists('transactions', $transactionResponse) || !array_key_exists('booked', $transactionResponse["transactions"]))
|
||||
throw new \Exception('invalid dataset');
|
||||
|
||||
foreach ($transaction->transactions->booked as $transaction) {
|
||||
foreach ($transactionResponse["transactions"]["booked"] as $transaction) {
|
||||
$data[] = $this->transformTransaction($transaction);
|
||||
}
|
||||
|
||||
@ -83,18 +85,20 @@ class IncomeTransformer implements BankRevenueInterface
|
||||
public function transformTransaction($transaction)
|
||||
{
|
||||
|
||||
if (!property_exists($transaction, 'transactionId') || !property_exists($transaction, 'transactionAmount') || !property_exists($transaction, 'balances') || !property_exists($transaction, 'institution'))
|
||||
if (!array_key_exists('transactionId', $transaction) || !array_key_exists('transactionAmount', $transaction))
|
||||
throw new \Exception('invalid dataset');
|
||||
|
||||
return [
|
||||
'transaction_id' => $transaction->transactionId,
|
||||
'amount' => abs($transaction->transactionAmount->amount),
|
||||
'currency_id' => $this->convertCurrency($transaction->transactionAmount->currency),
|
||||
'category_id' => $transaction->highLevelCategoryId, // TODO
|
||||
'category_type' => $transaction->categoryType, // TODO
|
||||
'date' => $transaction->bookingDate,
|
||||
'description' => $transaction->remittanceInformationUnstructured,
|
||||
'base_type' => $transaction->transactionAmount->amount > 0 ? 'DEBIT' : 'CREDIT',
|
||||
'transaction_id' => 'nordigen:' . $transaction["transactionId"],
|
||||
'amount' => abs((int) $transaction["transactionAmount"]["amount"]),
|
||||
'currency_id' => $this->convertCurrency($transaction["transactionAmount"]["currency"]),
|
||||
'category_id' => 0, // TODO: institution specific keys like: GUTSCHRIFT, ABSCHLUSS, MONATSABSCHLUSS etc
|
||||
'category_type' => $transaction["additionalInformation"], // TODO: institution specific keys like: GUTSCHRIFT, ABSCHLUSS, MONATSABSCHLUSS etc
|
||||
'date' => $transaction["bookingDate"],
|
||||
'description' => array_key_exists('bank_remittanceInformationStructured', $transaction) ? $transaction["bank_remittanceInformationStructured"] : array_key_exists('bank_remittanceInformationStructuredArray', $transaction) ? implode($transaction["bank_remittanceInformationStructured"], '\r\n') : '',
|
||||
// 'description' => `IBAN: ${elem . json["bank_debtorAccount"] && elem . json["bank_debtorAccount"]["iban"] ? elem . json["bank_debtorAccount"]["iban"] : ' -'}\nVerwendungszweck: ${elem . json["bank_remittanceInformationStructured"] || ' -'}\nName: ${elem . json["bank_debtorName"] || ' -'}`, // 2 fields to get data from (structured and structuredArray (have to be joined))
|
||||
// TODO: debitor name & iban & bic
|
||||
'base_type' => (int) $transaction["transactionAmount"]["amount"] > 0 ? 'DEBIT' : 'CREDIT',
|
||||
];
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ return new class extends Migration {
|
||||
{
|
||||
Schema::table('bank_integrations', function (Blueprint $table) {
|
||||
$table->string('integration_type')->nullable();
|
||||
// $table->string('provider_id'); // migrate to string, because nordigen provides a string like: SANDBOXFINANCE_SFIN0000
|
||||
// $table->string('bank_account_id'); // migrate to string, because nordigen uses uuid() strings
|
||||
});
|
||||
|
||||
// migrate old account to be used with yodlee
|
||||
|
Loading…
x
Reference in New Issue
Block a user