Stubs for yodlee

This commit is contained in:
David Bomba 2022-07-28 17:33:47 +10:00
parent b44e1a02ca
commit 15b53ca617
4 changed files with 54 additions and 42 deletions

View File

@ -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();

View File

@ -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
];

View File

@ -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);
}
},

View File

@ -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);
// }
}