mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-04 05:24:35 -04:00
feat: refresh & getAccounts
This commit is contained in:
parent
db407f6925
commit
5616da03c5
@ -31,9 +31,6 @@ class Nordigen
|
|||||||
public function __construct(string $secret_id, string $secret_key)
|
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 = 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
|
$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);
|
$nordigen_accountIds = array_unique($nordigen_accountIds);
|
||||||
|
|
||||||
Log::info($nordigen_accountIds);
|
|
||||||
|
|
||||||
$nordigen_accounts = [];
|
$nordigen_accounts = [];
|
||||||
foreach ($nordigen_accountIds as $accountId) {
|
foreach ($nordigen_accountIds as $accountId) {
|
||||||
$nordigen_account = $this->getAccount($accountId);
|
$nordigen_account = $this->getAccount($accountId);
|
||||||
@ -101,8 +96,6 @@ class Nordigen
|
|||||||
array_push($nordigen_accounts, $nordigen_account);
|
array_push($nordigen_accounts, $nordigen_account);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::info($nordigen_accounts);
|
|
||||||
|
|
||||||
return $nordigen_accounts;
|
return $nordigen_accounts;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -117,8 +110,6 @@ class Nordigen
|
|||||||
$out->balances = $this->client->account($account_id)->getAccountBalances()["balances"];
|
$out->balances = $this->client->account($account_id)->getAccountBalances()["balances"];
|
||||||
$out->institution = $this->client->institution->getInstitution($out->metadata["institution_id"]);
|
$out->institution = $this->client->institution->getInstitution($out->metadata["institution_id"]);
|
||||||
|
|
||||||
Log::info($out->data);
|
|
||||||
|
|
||||||
$it = new AccountTransformer();
|
$it = new AccountTransformer();
|
||||||
return $it->transform($out);
|
return $it->transform($out);
|
||||||
|
|
||||||
|
@ -102,15 +102,15 @@ class AccountTransformer implements AccountTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $nordigen_account->metadata["id"],
|
'id' => $nordigen_account->metadata["id"], // TODO: maybe add prefix for unique id between yodlee and nordigen?
|
||||||
'account_type' => "bank_account", // TODO: not creditCard
|
'account_type' => "bank_account", // TODO: not creditCard, which type should be used here?!
|
||||||
'account_name' => $nordigen_account->data["iban"],
|
'account_name' => $nordigen_account->data["iban"],
|
||||||
'account_status' => $nordigen_account->metadata["status"],
|
'account_status' => $nordigen_account->metadata["status"],
|
||||||
'account_number' => '**** ' . substr($nordigen_account->data["iban"], -7),
|
'account_number' => '**** ' . substr($nordigen_account->data["iban"], -7),
|
||||||
'provider_account_id' => $nordigen_account->data["iban"],
|
'provider_account_id' => $nordigen_account->data["iban"],
|
||||||
'provider_id' => $nordigen_account->institution["id"],
|
'provider_id' => $nordigen_account->institution["id"],
|
||||||
'provider_name' => $nordigen_account->institution["name"],
|
'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,
|
'current_balance' => (int) $used_balance ? $used_balance["balanceAmount"]["amount"] : 0,
|
||||||
'account_currency' => $used_balance ? $used_balance["balanceAmount"]["currency"] : '',
|
'account_currency' => $used_balance ? $used_balance["balanceAmount"]["currency"] : '',
|
||||||
];
|
];
|
||||||
|
@ -19,6 +19,7 @@ use App\Jobs\Bank\ProcessBankTransactionsNordigen;
|
|||||||
use App\Models\Account;
|
use App\Models\Account;
|
||||||
use App\Models\BankIntegration;
|
use App\Models\BankIntegration;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Log;
|
||||||
|
|
||||||
class NordigenController extends BaseController
|
class NordigenController extends BaseController
|
||||||
{
|
{
|
||||||
@ -86,12 +87,16 @@ class NordigenController extends BaseController
|
|||||||
|
|
||||||
$accounts = $nordigen->getAccounts();
|
$accounts = $nordigen->getAccounts();
|
||||||
|
|
||||||
foreach ($account->companies() as $company) {
|
$account->companies()->each(function ($company) use ($accounts) {
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
|
|
||||||
if (!BankIntegration::where('bank_account_id', $account['id'])->where('company_id', $company->id)->exists()) {
|
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 = new BankIntegration();
|
||||||
|
$bank_integration->integration_type = BankIntegration::INTEGRATION_TYPE_NORDIGEN;
|
||||||
$bank_integration->company_id = $company->id;
|
$bank_integration->company_id = $company->id;
|
||||||
$bank_integration->account_id = $company->account_id;
|
$bank_integration->account_id = $company->account_id;
|
||||||
$bank_integration->user_id = $company->owner()->id;
|
$bank_integration->user_id = $company->owner()->id;
|
||||||
@ -119,7 +124,7 @@ class NordigenController extends BaseController
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user