feat: refresh & getAccounts

This commit is contained in:
paulwer 2023-12-05 07:17:07 +01:00
parent db407f6925
commit 5616da03c5
3 changed files with 10 additions and 14 deletions

View File

@ -31,9 +31,6 @@ class Nordigen
public function __construct(string $secret_id, string $secret_key)
{
Log::info($secret_id);
Log::info($secret_key);
$this->client = new \Nordigen\NordigenPHP\API\NordigenClient($secret_id, $secret_key);
$this->client->createAccessToken(); // access_token is valid 24h -> so we dont have to implement a refresh-cycle
@ -92,8 +89,6 @@ class Nordigen
$nordigen_accountIds = array_unique($nordigen_accountIds);
Log::info($nordigen_accountIds);
$nordigen_accounts = [];
foreach ($nordigen_accountIds as $accountId) {
$nordigen_account = $this->getAccount($accountId);
@ -101,8 +96,6 @@ class Nordigen
array_push($nordigen_accounts, $nordigen_account);
}
Log::info($nordigen_accounts);
return $nordigen_accounts;
}
@ -117,8 +110,6 @@ class Nordigen
$out->balances = $this->client->account($account_id)->getAccountBalances()["balances"];
$out->institution = $this->client->institution->getInstitution($out->metadata["institution_id"]);
Log::info($out->data);
$it = new AccountTransformer();
return $it->transform($out);

View File

@ -102,15 +102,15 @@ class AccountTransformer implements AccountTransformerInterface
}
return [
'id' => $nordigen_account->metadata["id"],
'account_type' => "bank_account", // TODO: not creditCard
'id' => $nordigen_account->metadata["id"], // TODO: maybe add prefix for unique id between yodlee and nordigen?
'account_type' => "bank_account", // TODO: not creditCard, which type should be used here?!
'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"],
'provider_id' => $nordigen_account->institution["id"],
'provider_name' => $nordigen_account->institution["name"],
'nickname' => $nordigen_account->data?["ownerName"] ? $nordigen_account->data["ownerName"] : '',
'nickname' => $nordigen_account->data["ownerName"] ? $nordigen_account->data["ownerName"] : '',
'current_balance' => (int) $used_balance ? $used_balance["balanceAmount"]["amount"] : 0,
'account_currency' => $used_balance ? $used_balance["balanceAmount"]["currency"] : '',
];

View File

@ -19,6 +19,7 @@ use App\Jobs\Bank\ProcessBankTransactionsNordigen;
use App\Models\Account;
use App\Models\BankIntegration;
use Illuminate\Http\Request;
use Log;
class NordigenController extends BaseController
{
@ -86,12 +87,16 @@ class NordigenController extends BaseController
$accounts = $nordigen->getAccounts();
foreach ($account->companies() as $company) {
$account->companies()->each(function ($company) use ($accounts) {
foreach ($accounts as $account) {
if (!BankIntegration::where('bank_account_id', $account['id'])->where('company_id', $company->id)->exists()) {
Log::info("Creating new BankIntegration");
$bank_integration = new BankIntegration();
$bank_integration->integration_type = BankIntegration::INTEGRATION_TYPE_NORDIGEN;
$bank_integration->company_id = $company->id;
$bank_integration->account_id = $company->account_id;
$bank_integration->user_id = $company->owner()->id;
@ -119,7 +124,7 @@ class NordigenController extends BaseController
});
}
});
}