mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
bank integration cleanup
This commit is contained in:
parent
c169d2af99
commit
d0358086fc
@ -39,7 +39,7 @@ class Nordigen
|
||||
|
||||
$this->client = new \Nordigen\NordigenPHP\API\NordigenClient(config('ninja.nordigen.secret_id'), config('ninja.nordigen.secret_key'));
|
||||
|
||||
$this->client->createAccessToken(); // access_token is valid 24h -> so we dont have to implement a refresh-cycle
|
||||
$this->client->createAccessToken();
|
||||
}
|
||||
|
||||
// metadata-section for frontend
|
||||
|
@ -31,6 +31,8 @@ class NordigenController extends BaseController
|
||||
public function connect(ConnectNordigenBankIntegrationRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
|
||||
/** @var array $context */
|
||||
$context = $request->getTokenContent();
|
||||
$lang = $data['lang'] ?? 'en';
|
||||
$context["lang"] = $lang;
|
||||
@ -62,7 +64,7 @@ class NordigenController extends BaseController
|
||||
"redirectUrl" => $context["redirect"] . "?action=nordigen_connect&status=failed&reason=account-config-invalid",
|
||||
]);
|
||||
|
||||
if (!(Ninja::isSelfHost() || (Ninja::isHosted() && $account->isPaid() && $account->plan == 'enterprise')))
|
||||
if (!(Ninja::isSelfHost() || (Ninja::isHosted() && $account->isEnterprisePaidClient())))
|
||||
return view('bank.nordigen.handler', [
|
||||
'lang' => $lang,
|
||||
'company' => $company,
|
||||
|
@ -298,11 +298,14 @@ class BankIntegrationController extends BaseController
|
||||
|
||||
$account = $user->account;
|
||||
|
||||
$bank_integration = BankIntegration::withTrashed()->where('bank_account_id', $acc_id)->orWhere('nordigen_account_id', $acc_id)->company()->firstOrFail(); // @turbo124 please check
|
||||
$bank_integration = BankIntegration::withTrashed()
|
||||
->where('bank_account_id', $acc_id)
|
||||
->orWhere('nordigen_account_id', $acc_id)
|
||||
->company()
|
||||
->firstOrFail();
|
||||
|
||||
if ($bank_integration->integration_type == BankIntegration::INTEGRATION_TYPE_YODLEE)
|
||||
$this->removeAccountYodlee($account, $bank_integration);
|
||||
// we dont remove Accounts from nordigen, because they could be used within other companies
|
||||
|
||||
$this->bank_integration_repo->delete($bank_integration);
|
||||
|
||||
|
@ -36,24 +36,19 @@ class ConnectNordigenBankIntegrationRequest extends Request
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'lang' => 'string',
|
||||
'institution_id' => 'string',
|
||||
'redirect' => 'string',
|
||||
];
|
||||
}
|
||||
|
||||
// @turbo124 @todo please check for validity, when request from frontend
|
||||
public function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if (!array_key_exists('redirect', $input)) {
|
||||
$context = $this->getTokenContent();
|
||||
$context = $this->getTokenContent();
|
||||
|
||||
$input["redirect"] = isset($context["is_react"]) && $context['is_react'] ? config('ninja.react_url') . "/#/settings/bank_accounts" : config('ninja.app_url');
|
||||
$input["redirect"] = isset($context["is_react"]) && $context['is_react'] ? config('ninja.react_url') . "/#/settings/bank_accounts" : config('ninja.app_url');
|
||||
|
||||
$this->replace($input);
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
}
|
||||
public function getTokenContent()
|
||||
{
|
||||
|
@ -162,7 +162,7 @@ class ProcessBankTransactionsYodlee implements ShouldQueue
|
||||
$now = now();
|
||||
|
||||
foreach ($transactions as $transaction) {
|
||||
if (BankTransaction::query()->where('transaction_id', $transaction['transaction_id'])->where('company_id', $this->company->id)->where('bank_integration_id', $this->bank_integration->id)->withTrashed()->exists()) { // @turbo124 was not scoped to bank_integration_id => from my pov this should be present, because when an account was historized (is_deleted) a transaction can occur multiple (in the archived bank_integration and in the new one
|
||||
if (BankTransaction::query()->where('transaction_id', $transaction['transaction_id'])->where('company_id', $this->company->id)->where('bank_integration_id', $this->bank_integration->id)->withTrashed()->exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -64,12 +64,12 @@ class BankTransactionSync implements ShouldQueue
|
||||
|
||||
private function processYodlee()
|
||||
{
|
||||
if (Ninja::isHosted()) { // @turbo124 @todo I migrated the schedule for the job within the kernel to execute on all platforms and use the same expression here to determine if yodlee can run or not. Please chek/verify
|
||||
if (Ninja::isHosted()) {
|
||||
nlog("syncing transactions - yodlee");
|
||||
|
||||
Account::with('bank_integrations')->whereNotNull('bank_integration_account_id')->cursor()->each(function ($account) {
|
||||
|
||||
if ($account->isPaid() && $account->plan == 'enterprise') {
|
||||
if ($account->isEnterprisePaidClient()) {
|
||||
$account->bank_integrations()->where('integration_type', BankIntegration::INTEGRATION_TYPE_YODLEE)->where('auto_sync', true)->cursor()->each(function ($bank_integration) use ($account) {
|
||||
(new ProcessBankTransactionsYodlee($account->id, $bank_integration))->handle();
|
||||
});
|
||||
@ -80,12 +80,12 @@ class BankTransactionSync implements ShouldQueue
|
||||
}
|
||||
private function processNordigen()
|
||||
{
|
||||
if (config("ninja.nordigen.secret_id") && config("ninja.nordigen.secret_key")) { // @turbo124 check condition, when to execute this should be placed here (isSelfHosted || isPro/isEnterprise)
|
||||
if (config("ninja.nordigen.secret_id") && config("ninja.nordigen.secret_key")) {
|
||||
nlog("syncing transactions - nordigen");
|
||||
|
||||
Account::with('bank_integrations')->cursor()->each(function ($account) {
|
||||
|
||||
if ((Ninja::isSelfHost() || (Ninja::isHosted() && $account->isPaid() && $account->plan == 'enterprise'))) {
|
||||
if ((Ninja::isSelfHost() || (Ninja::isHosted() && $account->isEnterprisePaidClient()))) {
|
||||
$account->bank_integrations()->where('integration_type', BankIntegration::INTEGRATION_TYPE_NORDIGEN)->where('auto_sync', true)->cursor()->each(function ($bank_integration) {
|
||||
(new ProcessBankTransactionsNordigen($bank_integration))->handle();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user