diff --git a/app/Helpers/Bank/Yodlee/Yodlee.php b/app/Helpers/Bank/Yodlee/Yodlee.php index 6a84fd850de7..f021f5ec7e9d 100644 --- a/app/Helpers/Bank/Yodlee/Yodlee.php +++ b/app/Helpers/Bank/Yodlee/Yodlee.php @@ -174,6 +174,20 @@ class Yodlee } + public function getAccount($account_id) + { + + $token = $this->getAccessToken(); + + $response = Http::withHeaders($this->getHeaders(["Authorization" => "Bearer {$token}"]))->get($this->getEndpoint(). "/accounts/{$account_id}", []); + + if($response->successful()) + return true; + + if($response->failed()) + return false; + } + public function deleteAccount($account_id) { diff --git a/app/Http/Controllers/Bank/YodleeController.php b/app/Http/Controllers/Bank/YodleeController.php index ddf8b2100d79..b743822c0a8c 100644 --- a/app/Http/Controllers/Bank/YodleeController.php +++ b/app/Http/Controllers/Bank/YodleeController.php @@ -33,6 +33,8 @@ class YodleeController extends BaseController $company = $request->getCompany(); + //ensure user is enterprise!! + if($company->account->bank_integration_account_id){ $flow = 'edit'; diff --git a/app/Http/Controllers/OpenAPI/QuoteSchema.php b/app/Http/Controllers/OpenAPI/QuoteSchema.php index d05264bd4411..b33eddafcb10 100644 --- a/app/Http/Controllers/OpenAPI/QuoteSchema.php +++ b/app/Http/Controllers/OpenAPI/QuoteSchema.php @@ -26,7 +26,7 @@ * @OA\Property(property="tax_name3", type="string", example="", description="The tax name"), * @OA\Property(property="tax_rate3", type="number", format="float", example="10.00", description="The tax rate"), * @OA\Property(property="total_taxes", type="number", format="float", example="10.00", description="The total taxes for the quote"), - * @OA\Property(property="line_items", type="object", example="[{"product_key":"test", "unit_cost":10},{"product_key":"test", "unit_cost":10}]", description="An array of line items of the quote"), + * @OA\Property(property="line_items", type="object", example="", description="An array of line items of the quote"), * @OA\Property(property="amount", type="number", format="float", example="10.00", description="The total amount of the quote"), * @OA\Property(property="balance", type="number", format="float", example="10.00", description="The balance due of the quote"), * @OA\Property(property="paid_to_date", type="number", format="float", example="10.00", description="The amount that has been paid to date on the quote"), diff --git a/app/Jobs/Bank/ProcessBankTransactions.php b/app/Jobs/Bank/ProcessBankTransactions.php index 7e7c85083e9e..d213be664a7a 100644 --- a/app/Jobs/Bank/ProcessBankTransactions.php +++ b/app/Jobs/Bank/ProcessBankTransactions.php @@ -68,7 +68,13 @@ class ProcessBankTransactions implements ShouldQueue do{ - $this->processTransactions(); + try { + $this->processTransactions(); + } + catch(\Exception $e) { + nlog("{$this->bank_integration_account_id} - exited abnormally => ". $e->getMessage()); + return; + } } while($this->stop_loop); @@ -83,6 +89,14 @@ class ProcessBankTransactions implements ShouldQueue $yodlee = new Yodlee($this->bank_integration_account_id); + if(!$yodlee->getAccount($this->bank_integration->bank_account_id)) + { + $this->bank_integration->disabled_upstream = true; + $this->bank_integration->save(); + $this->stop_loop = false; + return; + } + $data = [ 'top' => 500, 'fromDate' => $this->from_date, @@ -102,7 +116,8 @@ class ProcessBankTransactions implements ShouldQueue //if no transactions, update the from_date and move on if(count($transactions) == 0){ - $this->bank_integration->from_date = now(); + $this->bank_integration->from_date = now()->subDays(2); + $this->bank_integration->disabled_upstream = false; $this->bank_integration->save(); $this->stop_loop = false; return; @@ -144,8 +159,7 @@ class ProcessBankTransactions implements ShouldQueue if($count < 500){ $this->stop_loop = false; - - $this->bank_integration->from_date = now(); + $this->bank_integration->from_date = now()->subDays(2); $this->bank_integration->save(); } diff --git a/app/Jobs/Ninja/BankTransactionSync.php b/app/Jobs/Ninja/BankTransactionSync.php index d657f4c66843..227f8ec8d9dc 100644 --- a/app/Jobs/Ninja/BankTransactionSync.php +++ b/app/Jobs/Ninja/BankTransactionSync.php @@ -64,8 +64,8 @@ class BankTransactionSync implements ShouldQueue // $queue = Ninja::isHosted() ? 'bank' : 'default'; - // if($account->isPaid()) - // { + if($account->isPaid() && $account->plan == 'enterprise') + { $account->bank_integrations->each(function ($bank_integration) use ($account){ @@ -73,7 +73,7 @@ class BankTransactionSync implements ShouldQueue }); - // } + } }); } diff --git a/app/Transformers/BankIntegrationTransformer.php b/app/Transformers/BankIntegrationTransformer.php index 131259f498a6..cae21bbf4377 100644 --- a/app/Transformers/BankIntegrationTransformer.php +++ b/app/Transformers/BankIntegrationTransformer.php @@ -60,6 +60,7 @@ class BankIntegrationTransformer extends EntityTransformer '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, 'created_at' => (int) $bank_integration->created_at, 'updated_at' => (int) $bank_integration->updated_at, 'archived_at' => (int) $bank_integration->deleted_at, diff --git a/database/migrations/2022_11_04_013539_disabled_upstream_bank_integrations_table.php b/database/migrations/2022_11_04_013539_disabled_upstream_bank_integrations_table.php new file mode 100644 index 000000000000..736de042740d --- /dev/null +++ b/database/migrations/2022_11_04_013539_disabled_upstream_bank_integrations_table.php @@ -0,0 +1,32 @@ +boolean('disabled_upstream')->default(false); + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}; diff --git a/resources/views/bank/yodlee/auth.blade.php b/resources/views/bank/yodlee/auth.blade.php index 81b2ab9fe73f..906e0e6c1748 100644 --- a/resources/views/bank/yodlee/auth.blade.php +++ b/resources/views/bank/yodlee/auth.blade.php @@ -43,14 +43,14 @@