diff --git a/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php b/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php index d45eb6b60f..c8a4359aee 100644 --- a/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php +++ b/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php @@ -70,6 +70,9 @@ class AccountTransformer implements AccountTransformerInterface $data = []; + if(!property_exists($yodlee_account, 'account')) + return []; + foreach($yodlee_account->account as $account) { $data[] = $this->transformAccount($account); diff --git a/app/Helpers/Bank/Yodlee/Transformer/IncomeTransformer.php b/app/Helpers/Bank/Yodlee/Transformer/IncomeTransformer.php index 0ffe924867..8fde691498 100644 --- a/app/Helpers/Bank/Yodlee/Transformer/IncomeTransformer.php +++ b/app/Helpers/Bank/Yodlee/Transformer/IncomeTransformer.php @@ -119,6 +119,9 @@ class IncomeTransformer implements BankRevenueInterface $data = []; + if(!property_exists($transaction, 'transaction')) + return []; + foreach($transaction->transaction as $transaction) { $data[] = $this->transformTransaction($transaction); diff --git a/app/Helpers/Bank/Yodlee/Yodlee.php b/app/Helpers/Bank/Yodlee/Yodlee.php index 05091df4e4..59d42602dd 100644 --- a/app/Helpers/Bank/Yodlee/Yodlee.php +++ b/app/Helpers/Bank/Yodlee/Yodlee.php @@ -11,6 +11,7 @@ namespace App\Helpers\Bank\Yodlee; +use App\Exceptions\YodleeApiException; use App\Helpers\Bank\Yodlee\Transformer\AccountTransformer; use App\Helpers\Bank\Yodlee\Transformer\IncomeTransformer; use Illuminate\Support\Facades\Http; @@ -83,8 +84,7 @@ class Yodlee $user = $this->bank_account_id ?: $this->admin_name; $response = $this->bankFormRequest('/auth/token', 'post', [], ['loginName' => $user]); - //catch failures here - nlog($response); + return $response->token->accessToken; } @@ -135,10 +135,7 @@ class Yodlee return $response->object(); if($response->failed()) - return $response->body(); - - - return $response; + throw new YodleeApiException($response->body()); } @@ -152,15 +149,13 @@ class Yodlee if($response->successful()){ $at = new AccountTransformer(); - nlog($response->object()); return $at->transform($response->object()); + } + if($response->failed()) - return $response->body(); - - - return $response; + throw new YodleeApiException($response->body()); } @@ -178,7 +173,7 @@ class Yodlee } if($response->failed()) - return $response->body(); + throw new YodleeApiException($response->body()); } @@ -192,7 +187,7 @@ class Yodlee return $response->object(); if($response->failed()) - return $response->body(); + throw new YodleeApiException($response->body()); } @@ -205,7 +200,7 @@ class Yodlee return $response->object(); if($response->failed()) - return $response->body(); + throw new YodleeApiException($response->body()); } diff --git a/app/Http/Requests/Yodlee/YodleeAdminRequest.php b/app/Http/Requests/Yodlee/YodleeAdminRequest.php new file mode 100644 index 0000000000..8b361a0d84 --- /dev/null +++ b/app/Http/Requests/Yodlee/YodleeAdminRequest.php @@ -0,0 +1,39 @@ +user()->isAdmin(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return []; + } + +} \ No newline at end of file diff --git a/database/migrations/2022_08_05_023357_bank_integration.php b/database/migrations/2022_08_05_023357_bank_integration.php index 555f9dad5f..f39de10f83 100644 --- a/database/migrations/2022_08_05_023357_bank_integration.php +++ b/database/migrations/2022_08_05_023357_bank_integration.php @@ -21,8 +21,8 @@ return new class extends Migration $table->unsignedInteger('user_id'); $table->text('provider_bank_name'); //providerName ie Chase - $table->bigUnsignedInteger('provider_id'); //id of the bank - $table->bigUnsignedInteger('bank_account_id'); //id + $table->bigInteger('provider_id'); //id of the bank + $table->bigInteger('bank_account_id'); //id $table->text('bank_account_name')->nullable(); //accountName $table->text('bank_account_number')->nullable(); //accountNumber $table->text('bank_account_status')->nullable(); //accountStatus diff --git a/tests/Feature/Bank/YodleeApiTest.php b/tests/Feature/Bank/YodleeApiTest.php index 4cc37cb00b..38db2162d3 100644 --- a/tests/Feature/Bank/YodleeApiTest.php +++ b/tests/Feature/Bank/YodleeApiTest.php @@ -69,14 +69,10 @@ class YodleeApiTest extends TestCase $this->assertTrue($hit); - $transaction->contains(function ($value, $key) { - return str_contains($value->description, 'tinker'); - }); - $invoice = $transaction->first(function ($value, $key) { - return str_contains($value->number, 'tinker'); + return str_contains($value->description, 'tinker'); }); @@ -102,7 +98,7 @@ class YodleeApiTest extends TestCase $yodlee = new Yodlee('sbMem62e1e69547bfb1'); $yodlee->setTestMode(); - $access_token = $yodlee->getAccessToken(true); + $access_token = $yodlee->getAccessToken(); $this->assertNotNull($access_token); } @@ -405,7 +401,7 @@ class YodleeApiTest extends TestCase $yodlee->setTestMode(); $accounts = $yodlee->getAccounts(); - +nlog($accounts); $this->assertIsArray($accounts); } @@ -465,7 +461,6 @@ class YodleeApiTest extends TestCase $transactions = $yodlee->getTransactions(['categoryId' => 2, 'fromDate' => '2000-01-01']); $this->assertIsArray($transactions); - //nlog($transactions); }