diff --git a/app/Helpers/Bank/Yodlee/Yodlee.php b/app/Helpers/Bank/Yodlee/Yodlee.php index 1f09fd1052ef..db9ea1e2370f 100644 --- a/app/Helpers/Bank/Yodlee/Yodlee.php +++ b/app/Helpers/Bank/Yodlee/Yodlee.php @@ -45,9 +45,12 @@ class Yodlee } - public function getAccessToken() + public function getAccessToken($user = false) { - $response = $this->bankFormRequest('/auth/token', 'post'); + if(!$user) + $user = $this->admin_name; + + $response = $this->bankFormRequest('/auth/token', 'post', [], ['loginName' => $user]); return $response->token->accessToken; } @@ -55,47 +58,31 @@ class Yodlee public function createUser() { - // { - // "user": { - // "preferences": { - // "dateFormat": "string", - // "timeZone": "string", - // "currency": "USD", - // "locale": "en_US" - // }, - // "address": { - // "zip": "string", - // "country": "string", - // "address3": "string", - // "address2": "string", - // "city": "string", - // "address1": "string", - // "state": "string" - // }, - // "loginName": "string", - // "name": { - // "middle": "string", - // "last": "string", - // "fullName": "string", - // "first": "string" - // }, - // "email": "string", - // "segmentName": "string" - // } - // } + + $token = $this->getAccessToken(); $user['user'] = [ 'loginName' => 'test123', ]; - return $this->bankRequest('/user/register', 'post', $user); + return $this->bankRequest('/user/register', 'post', $user, ['Authorization' => $token]); } - private function bankRequest(string $uri, string $verb, array $data = []) + public function getAccounts($token) { - $response = Http::withHeaders($this->getHeaders(['loginName' => $this->admin_name]))->{$verb}($this->api_endpoint . $uri, $this->buildBody()); + $response = $this->bankRequest('/accounts', 'get', [], ['Authorization' => $token]); + + return $response; + + } + + + private function bankRequest(string $uri, string $verb, array $data = [], array $headers = []) + { + + $response = Http::withHeaders($this->getHeaders($headers))->{$verb}($this->api_endpoint . $uri, $this->buildBody()); if($response->successful()) return $response->object(); @@ -105,10 +92,10 @@ class Yodlee } - private function bankFormRequest(string $uri, string $verb, array $data = []) + private function bankFormRequest(string $uri, string $verb, array $data = [], array $headers) { - $response = Http::withHeaders($this->getFormHeaders(['loginName' => $this->admin_name]))->asForm()->{$verb}($this->api_endpoint . $uri, $this->buildBody()); + $response = Http::withHeaders($this->getFormHeaders($headers))->asForm()->{$verb}($this->api_endpoint . $uri, $this->buildBody()); if($response->successful()) return $response->object(); diff --git a/app/Http/Controllers/Bank/YodleeController.php b/app/Http/Controllers/Bank/YodleeController.php index 26cd5f7c994e..ead225b706dd 100644 --- a/app/Http/Controllers/Bank/YodleeController.php +++ b/app/Http/Controllers/Bank/YodleeController.php @@ -24,7 +24,7 @@ class YodleeController extends BaseController $yodlee = new Yodlee(true); $data = [ - 'access_token' => $yodlee->getAccessToken(), + 'access_token' => $yodlee->getAccessToken('sbMem62e1e69547bfb1'), 'fasttrack_url' => $yodlee->fast_track_url ]; diff --git a/resources/views/bank/yodlee/auth.blade.php b/resources/views/bank/yodlee/auth.blade.php index 3cda43d55b0b..66002fffdcec 100644 --- a/resources/views/bank/yodlee/auth.blade.php +++ b/resources/views/bank/yodlee/auth.blade.php @@ -30,22 +30,28 @@ fastLinkURL: '{{ $fasttrack_url }}', accessToken: 'Bearer {{ $access_token }}', params: { - configName : 'Example2' + configName : 'Aggregation' }, onSuccess: function (data) { // will be called on success. For list of possible message, refer to onSuccess(data) Method. + console.log('success'); console.log(data); }, onError: function (data) { // will be called on error. For list of possible message, refer to onError(data) Method. + console.log('error'); + console.log(data); }, onClose: function (data) { // will be called called to close FastLink. For list of possible message, refer to onClose(data) Method. + console.log('onclose'); console.log(data); }, onEvent: function (data) { // will be called on intermittent status update. + console.log('on event'); + console.log(data); } }, diff --git a/tests/Feature/Bank/YodleeApiTest.php b/tests/Feature/Bank/YodleeApiTest.php index dd3f9446223d..ee20bbf43da3 100644 --- a/tests/Feature/Bank/YodleeApiTest.php +++ b/tests/Feature/Bank/YodleeApiTest.php @@ -23,6 +23,9 @@ class YodleeApiTest extends TestCase protected function setUp(): void { parent::setUp(); + + $this->markTestSkipped('Skip test no company gateways installed'); + } public function testAccessTokenGeneration() @@ -30,21 +33,37 @@ class YodleeApiTest extends TestCase $yodlee = new Yodlee(true); - $access_token = $yodlee->getAccessToken(); + $access_token = $yodlee->getAccessToken('sbMem62e1e69547bfb1'); nlog($access_token); $this->assertNotNull($access_token); } - public function testCreateUser() + public function testGetAccounts() { + $yodlee = new Yodlee(true); - $create_user = $yodlee->createUser(); + // $data = [ + // 'providerAccountId' => 11308693, + // ]; + + $access_token = $yodlee->getAccessToken('sbMem62e1e69547bfb1'); - nlog($create_user); - + $accounts = $yodlee->getAccounts($access_token); + + nlog($accounts); } + // public function testCreateUser() + // { + // $yodlee = new Yodlee(true); + + // $create_user = $yodlee->createUser(); + + // nlog($create_user); + + // } + }