diff --git a/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php b/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php index fe08a7ed7463..5ed0b020799b 100644 --- a/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php +++ b/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php @@ -12,61 +12,79 @@ namespace App\Helpers\Bank\Yodlee\Transformer; /** -[account] => Array - ( - [0] => stdClass Object - ( - [CONTAINER] => bank - [providerAccountId] => 11308693 - [accountName] => My CD - 8878 - [accountStatus] => ACTIVE - [accountNumber] => xxxx8878 - [aggregationSource] => USER - [isAsset] => 1 - [balance] => stdClass Object - ( - [currency] => USD - [amount] => 49778.07 - ) +[0] => stdClass Object +( + [CONTAINER] => bank + [providerAccountId] => 11308693 + [accountName] => My CD - 8878 + [accountStatus] => ACTIVE + [accountNumber] => xxxx8878 + [aggregationSource] => USER + [isAsset] => 1 + [balance] => stdClass Object + ( + [currency] => USD + [amount] => 49778.07 + ) - [id] => 12331861 - [includeInNetWorth] => 1 - [providerId] => 18769 - [providerName] => Dag Site Captcha - [isManual] => - [currentBalance] => stdClass Object - ( - [currency] => USD - [amount] => 49778.07 - ) + [id] => 12331861 + [includeInNetWorth] => 1 + [providerId] => 18769 + [providerName] => Dag Site Captcha + [isManual] => + [currentBalance] => stdClass Object + ( + [currency] => USD + [amount] => 49778.07 + ) - [accountType] => CD - [displayedName] => LORETTA - [createdDate] => 2022-07-28T06:55:33Z - [lastUpdated] => 2022-07-28T06:56:09Z - [dataset] => Array - ( - [0] => stdClass Object - ( - [name] => BASIC_AGG_DATA - [additionalStatus] => AVAILABLE_DATA_RETRIEVED - [updateEligibility] => ALLOW_UPDATE - [lastUpdated] => 2022-07-28T06:55:50Z - [lastUpdateAttempt] => 2022-07-28T06:55:50Z - ) + [accountType] => CD + [displayedName] => LORETTA + [createdDate] => 2022-07-28T06:55:33Z + [lastUpdated] => 2022-07-28T06:56:09Z + [dataset] => Array + ( + [0] => stdClass Object + ( + [name] => BASIC_AGG_DATA + [additionalStatus] => AVAILABLE_DATA_RETRIEVED + [updateEligibility] => ALLOW_UPDATE + [lastUpdated] => 2022-07-28T06:55:50Z + [lastUpdateAttempt] => 2022-07-28T06:55:50Z + ) - ) + ) - ) +) ) */ class AccountTransformer { - public static function transform(array $account) + public function transform($yodlee_account){ + + $data = []; + + foreach($yodlee_account->account as $account) + { + $data[] = $this->transformAccount($account); + } + + return $data; + } + + public function transformAccount($account) { + nlog($account); return [ + 'id' => $account->id, + 'account_type' => $account->CONTAINER, + 'account_name' => $account->accountName, + 'account_status' => $account->accountStatus, + 'account_number' => $account->accountNumber, + 'current_balance' => property_exists($account, 'currentBalance') ? $account->currentBalance->amount : 0, + 'account_currency' => property_exists($account, 'currency') ? $account->currentBalance->currency : '', ]; } } diff --git a/app/Helpers/Bank/Yodlee/Yodlee.php b/app/Helpers/Bank/Yodlee/Yodlee.php index 8ff9275cce0f..86554ec2711a 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\Helpers\Bank\Yodlee\Transformer\AccountTransformer; use Illuminate\Support\Facades\Http; class Yodlee @@ -137,8 +138,13 @@ class Yodlee $response = Http::withHeaders($this->getHeaders(["Authorization" => "Bearer {$token}"]))->get($this->getEndpoint(). "/accounts", $params); - if($response->successful()) - return $response->object(); + + if($response->successful()){ + + $at = new AccountTransformer(); + return $at->transform($response->object()); + // return $response->object(); + } if($response->failed()) return $response->body(); diff --git a/tests/Feature/Bank/YodleeApiTest.php b/tests/Feature/Bank/YodleeApiTest.php index 032eee142779..9df4e6e9bb2d 100644 --- a/tests/Feature/Bank/YodleeApiTest.php +++ b/tests/Feature/Bank/YodleeApiTest.php @@ -350,7 +350,9 @@ class YodleeApiTest extends TestCase $accounts = $yodlee->getAccounts(); - $this->assertIsArray($accounts->account); +nlog($accounts); + + $this->assertIsArray($accounts); }