mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
fixes
This commit is contained in:
parent
d5a9a1c839
commit
27ab262a4f
@ -29,13 +29,11 @@ class Nordigen
|
||||
|
||||
public function __construct(string $secret_id, string $secret_key)
|
||||
{
|
||||
|
||||
$this->test_mode = config('ninja.nordigen.test_mode');
|
||||
|
||||
$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
|
||||
|
||||
}
|
||||
|
||||
// metadata-section for frontend
|
||||
@ -64,22 +62,26 @@ class Nordigen
|
||||
// TODO: return null on not found
|
||||
public function getAccount(string $account_id)
|
||||
{
|
||||
try {
|
||||
$out = new \stdClass();
|
||||
|
||||
$out = new \stdClass();
|
||||
$out->data = $this->client->account($account_id)->getAccountDetails()["account"];
|
||||
$out->metadata = $this->client->account($account_id)->getAccountMetaData();
|
||||
$out->balances = $this->client->account($account_id)->getAccountBalances()["balances"];
|
||||
$out->institution = $this->client->institution->getInstitution($out->metadata["institution_id"]);
|
||||
|
||||
$out->data = $this->client->account($account_id)->getAccountDetails()["account"];
|
||||
$out->metadata = $this->client->account($account_id)->getAccountMetaData();
|
||||
$out->balances = $this->client->account($account_id)->getAccountBalances()["balances"];
|
||||
$out->institution = $this->client->institution->getInstitution($out->metadata["institution_id"]);
|
||||
|
||||
$it = new AccountTransformer();
|
||||
return $it->transform($out);
|
||||
$it = new AccountTransformer();
|
||||
return $it->transform($out);
|
||||
} catch (\Exception $e) {
|
||||
if (strpos($e->getMessage(), "Invalid Account ID") !== false)
|
||||
return null;
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function isAccountActive(string $account_id)
|
||||
{
|
||||
|
||||
try {
|
||||
$account = $this->client->account($account_id)->getAccountMetaData();
|
||||
|
||||
@ -88,10 +90,11 @@ class Nordigen
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
// TODO: check for not-found exception
|
||||
return false;
|
||||
}
|
||||
if (strpos($e->getMessage(), "Invalid Account ID") !== false)
|
||||
return false;
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,11 +103,9 @@ class Nordigen
|
||||
*/
|
||||
public function getTransactions(string $accountId, string $dateFrom = null)
|
||||
{
|
||||
|
||||
$transactionResponse = $this->client->account($accountId)->getAccountTransactions($dateFrom);
|
||||
|
||||
$it = new TransactionTransformer();
|
||||
return $it->transform($transactionResponse);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ class AccountTransformer implements AccountTransformerInterface
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => 'nordigen:' . $nordigen_account->metadata["id"],
|
||||
'id' => $nordigen_account->metadata["id"],
|
||||
'account_type' => "bank",
|
||||
'account_name' => $nordigen_account->data["iban"],
|
||||
'account_status' => $nordigen_account->metadata["status"],
|
||||
|
@ -95,7 +95,7 @@ class TransactionTransformer implements BankRevenueInterface
|
||||
'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' => 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',
|
||||
|
@ -270,7 +270,7 @@ class BankIntegrationController extends BaseController
|
||||
|
||||
$nordigen = ($account->bank_integration_nordigen_secret_id && $account->bank_integration_nordigen_secret_key) ? new Nordigen($account->bank_integration_nordigen_secret_id, $account->bank_integration_nordigen_secret_key) : new Nordigen(config('ninja.nordigen.secret_id'), config('ninja.nordigen.secret_key'));
|
||||
|
||||
BankIntegration::withTrashed()->where("integration_type", BankIntegration::INTEGRATION_TYPE_NORDIGEN)->each(function (BankIntegration $bank_integration) use ($nordigen) {
|
||||
BankIntegration::withTrashed()->where("integration_type", BankIntegration::INTEGRATION_TYPE_NORDIGEN)->whereNotNull('nordigen_account_id')->each(function (BankIntegration $bank_integration) use ($nordigen) {
|
||||
$account = $nordigen->getAccount($bank_integration->nordigen_account_id);
|
||||
|
||||
if (!$account) {
|
||||
@ -280,6 +280,7 @@ class BankIntegrationController extends BaseController
|
||||
return;
|
||||
}
|
||||
|
||||
$bank_integration->disabled_upstream = false;
|
||||
$bank_integration->bank_account_status = $account['account_status'];
|
||||
$bank_integration->balance = $account['current_balance'];
|
||||
$bank_integration->currency = $account['account_currency'];
|
||||
|
@ -50,20 +50,21 @@ class BankIntegrationTransformer extends EntityTransformer
|
||||
{
|
||||
return [
|
||||
'id' => (string) $this->encodePrimaryKey($bank_integration->id),
|
||||
'provider_name' => (string)$bank_integration->provider_name ?: '',
|
||||
'provider_name' => (string) $bank_integration->provider_name ?: '',
|
||||
'provider_id' => (int) $bank_integration->provider_id ?: 0,
|
||||
'bank_account_id' => (int) $bank_integration->bank_account_id ?: 0,
|
||||
'bank_account_name' => (string) $bank_integration->bank_account_name ?: '',
|
||||
'bank_account_number' => (string) $bank_integration->bank_account_number ?: '',
|
||||
'bank_account_status' => (string)$bank_integration->bank_account_status ?: '',
|
||||
'bank_account_type' => (string)$bank_integration->bank_account_type ?: '',
|
||||
'balance' => (float)$bank_integration->balance ?: 0,
|
||||
'currency' => (string)$bank_integration->currency ?: '',
|
||||
'nickname' => (string)$bank_integration->nickname ?: '',
|
||||
'from_date' => (string)$bank_integration->from_date ?: '',
|
||||
'bank_account_status' => (string) $bank_integration->bank_account_status ?: '',
|
||||
'bank_account_type' => (string) $bank_integration->bank_account_type ?: '',
|
||||
'nordigen_institution_id' => (string) $bank_integration->nordigen_institution_id ?: '',
|
||||
'balance' => (float) $bank_integration->balance ?: 0,
|
||||
'currency' => (string) $bank_integration->currency ?: '',
|
||||
'nickname' => (string) $bank_integration->nickname ?: '',
|
||||
'from_date' => (string) $bank_integration->from_date ?: '',
|
||||
'is_deleted' => (bool) $bank_integration->is_deleted,
|
||||
'disabled_upstream' => (bool) $bank_integration->disabled_upstream,
|
||||
'auto_sync' => (bool)$bank_integration->auto_sync,
|
||||
'auto_sync' => (bool) $bank_integration->auto_sync,
|
||||
'created_at' => (int) $bank_integration->created_at,
|
||||
'updated_at' => (int) $bank_integration->updated_at,
|
||||
'archived_at' => (int) $bank_integration->deleted_at,
|
||||
|
Loading…
Reference in New Issue
Block a user