diff --git a/app/Http/Controllers/Bank/NordigenController.php b/app/Http/Controllers/Bank/NordigenController.php index b64773dae6..a990b9a8d9 100644 --- a/app/Http/Controllers/Bank/NordigenController.php +++ b/app/Http/Controllers/Bank/NordigenController.php @@ -202,7 +202,7 @@ class NordigenController extends BaseController $nordigen_account = $nordigen->getAccount($nordigenAccountId); - $existing_bank_integration = BankIntegration::where('nordigen_account_id', $nordigen_account['id'])->where('company_id', $company->id)->first(); + $existing_bank_integration = BankIntegration::withTrashed()->where('nordigen_account_id', $nordigen_account['id'])->where('company_id', $company->id)->first(); if (!$existing_bank_integration) { @@ -237,6 +237,7 @@ class NordigenController extends BaseController $existing_bank_integration->disabled_upstream = false; $existing_bank_integration->auto_sync = true; $existing_bank_integration->from_date = now()->subDays(90); // default max-fetch interval of nordigen is 90 days + $existing_bank_integration->deleted_at = null; $existing_bank_integration->save(); @@ -246,10 +247,8 @@ class NordigenController extends BaseController } // perform update in background - $company->account->bank_integrations->where("integration_type", BankIntegration::INTEGRATION_TYPE_NORDIGEN)->where('auto_sync', true)->where('is_deleted', false)->each(function ($bank_integration) { - + $company->account->bank_integrations->where("integration_type", BankIntegration::INTEGRATION_TYPE_NORDIGEN)->where('auto_sync', true)->each(function ($bank_integration) { ProcessBankTransactionsNordigen::dispatch($bank_integration); - }); // prevent rerun of this method with same ref diff --git a/app/Http/Controllers/Bank/YodleeController.php b/app/Http/Controllers/Bank/YodleeController.php index 87e13a2d92..6a180914ee 100644 --- a/app/Http/Controllers/Bank/YodleeController.php +++ b/app/Http/Controllers/Bank/YodleeController.php @@ -98,10 +98,8 @@ class YodleeController extends BaseController } - $company->account->bank_integrations->where("integration_type", BankIntegration::INTEGRATION_TYPE_YODLEE)->where('auto_sync', true)->where('is_deleted', false)->each(function ($bank_integration) use ($company) { // TODO: filter to yodlee only - + $company->account->bank_integrations->where("integration_type", BankIntegration::INTEGRATION_TYPE_YODLEE)->where('auto_sync', true)->each(function ($bank_integration) use ($company) { // TODO: filter to yodlee only ProcessBankTransactionsYodlee::dispatch($company->account, $bank_integration); - }); } diff --git a/app/Http/Controllers/BankIntegrationController.php b/app/Http/Controllers/BankIntegrationController.php index c2b35490ef..44f6fdde2f 100644 --- a/app/Http/Controllers/BankIntegrationController.php +++ b/app/Http/Controllers/BankIntegrationController.php @@ -210,16 +210,12 @@ class BankIntegrationController extends BaseController // Processing transactions for each bank account if (Ninja::isHosted() && $user->account->bank_integration_account_id) $user_account->bank_integrations->where("integration_type", BankIntegration::INTEGRATION_TYPE_YODLEE)->where('auto_sync', true)->each(function ($bank_integration) use ($user_account) { - ProcessBankTransactionsYodlee::dispatch($user_account, $bank_integration); - }); if (config('ninja.nordigen.secret_id') && config('ninja.nordigen.secret_key') && (Ninja::isSelfHost() || (Ninja::isHosted() && $user_account->isPaid() && $user_account->plan == 'enterprise'))) $user_account->bank_integrations->where("integration_type", BankIntegration::INTEGRATION_TYPE_NORDIGEN)->where('auto_sync', true)->each(function ($bank_integration) { - ProcessBankTransactionsNordigen::dispatch($bank_integration); - }); Cache::put("throttle_polling:{$user_account->key}", true, 300); @@ -272,9 +268,9 @@ class BankIntegrationController extends BaseController $nordigen = new Nordigen(); - BankIntegration::withTrashed()->where("integration_type", BankIntegration::INTEGRATION_TYPE_NORDIGEN)->whereNotNull('nordigen_account_id')->each(function (BankIntegration $bank_integration) use ($nordigen) { + BankIntegration::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); - + Log::info($bank_integration); if (!$account) { $bank_integration->disabled_upstream = true; @@ -340,13 +336,13 @@ class BankIntegrationController extends BaseController $account = auth()->user()->account(); if (Ninja::isHosted() && $account->isPaid() && $account->plan == 'enterprise') { - $account->bank_integrations()->where('integration_type', BankIntegration::INTEGRATION_TYPE_YODLEE)->where('auto_sync', true)->where('is_deleted', false)->cursor()->each(function ($bank_integration) use ($account) { + $account->bank_integrations()->where('integration_type', BankIntegration::INTEGRATION_TYPE_YODLEE)->where('auto_sync', true)->cursor()->each(function ($bank_integration) use ($account) { (new ProcessBankTransactionsYodlee($account, $bank_integration))->handle(); }); } if (config("ninja.nordigen.secret_id") && config("ninja.nordigen.secret_key") && (Ninja::isSelfHost() || (Ninja::isHosted() && $account->isPaid() && $account->plan == 'enterprise'))) { - $account->bank_integrations()->where('integration_type', BankIntegration::INTEGRATION_TYPE_NORDIGEN)->where('auto_sync', true)->where('is_deleted', false)->cursor()->each(function ($bank_integration) { + $account->bank_integrations()->where('integration_type', BankIntegration::INTEGRATION_TYPE_NORDIGEN)->where('auto_sync', true)->cursor()->each(function ($bank_integration) { (new ProcessBankTransactionsNordigen($bank_integration))->handle(); }); } diff --git a/app/Jobs/Ninja/BankTransactionSync.php b/app/Jobs/Ninja/BankTransactionSync.php index cfe218d91c..93c8a4277c 100644 --- a/app/Jobs/Ninja/BankTransactionSync.php +++ b/app/Jobs/Ninja/BankTransactionSync.php @@ -55,7 +55,7 @@ class BankTransactionSync implements ShouldQueue Account::with('bank_integrations')->whereNotNull('bank_integration_account_id')->cursor()->each(function ($account) { if ($account->isPaid() && $account->plan == 'enterprise') { - $account->bank_integrations()->where('integration_type', BankIntegration::INTEGRATION_TYPE_YODLEE)->where('auto_sync', true)->where('is_deleted', false)->cursor()->each(function ($bank_integration) use ($account) { + $account->bank_integrations()->where('integration_type', BankIntegration::INTEGRATION_TYPE_YODLEE)->where('auto_sync', true)->cursor()->each(function ($bank_integration) use ($account) { (new ProcessBankTransactionsYodlee($account, $bank_integration))->handle(); }); } @@ -69,7 +69,7 @@ class BankTransactionSync implements ShouldQueue Account::with('bank_integrations')->cursor()->each(function ($account) { if ((Ninja::isSelfHost() || (Ninja::isHosted() && $account->isPaid() && $account->plan == 'enterprise'))) { - $account->bank_integrations()->where('integration_type', BankIntegration::INTEGRATION_TYPE_NORDIGEN)->where('auto_sync', true)->where('is_deleted', false)->cursor()->each(function ($bank_integration) { + $account->bank_integrations()->where('integration_type', BankIntegration::INTEGRATION_TYPE_NORDIGEN)->where('auto_sync', true)->cursor()->each(function ($bank_integration) { (new ProcessBankTransactionsNordigen($bank_integration))->handle(); }); }