Income / Expense TransformeR

This commit is contained in:
David Bomba 2022-08-05 13:45:53 +10:00
parent d1530c4477
commit 6dd9f7302d
4 changed files with 184 additions and 13 deletions

View File

@ -0,0 +1,80 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Helpers\Bank\Yodlee\Transformer;
/**
"date": "string",
"sourceId": "string",
"symbol": "string",
"cusipNumber": "string",
"highLevelCategoryId": 0,
"detailCategoryId": 0,
"description": {},
"memo": "string",
"settleDate": "string",
"type": "string",
"intermediary": [],
"baseType": "CREDIT",
"categorySource": "SYSTEM",
"principal": {},
"lastUpdated": "string",
"interest": {},
"price": {},
"commission": {},
"id": 0,
"merchantType": "string",
"amount": {
"amount": 0,
"convertedAmount": 0,
"currency": "USD",
"convertedCurrency": "USD"
},
"checkNumber": "string",
"isPhysical": true,
"quantity": 0,
"valoren": "string",
"isManual": true,
"merchant": {
"website": "string",
"address": {},
"contact": {},
"categoryLabel": [],
"coordinates": {},
"name": "string",
"id": "string",
"source": "YODLEE",
"logoURL": "string"
},
"sedol": "string",
"transactionDate": "string",
"categoryType": "TRANSFER",
"accountId": 0,
"createdDate": "string",
"sourceType": "AGGREGATED",
"CONTAINER": "bank",
"postDate": "string",
"parentCategoryId": 0,
"subType": "OVERDRAFT_CHARGE",
"category": "string",
"runningBalance": {},
"categoryId": 0,
"holdingDescription": "string",
"isin": "string",
"status": "POSTED"
*/
class ExpenseTransformer
{
}

View File

@ -0,0 +1,80 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Helpers\Bank\Yodlee\Transformer;
/**
"date": "string",
"sourceId": "string",
"symbol": "string",
"cusipNumber": "string",
"highLevelCategoryId": 0,
"detailCategoryId": 0,
"description": {},
"memo": "string",
"settleDate": "string",
"type": "string",
"intermediary": [],
"baseType": "CREDIT",
"categorySource": "SYSTEM",
"principal": {},
"lastUpdated": "string",
"interest": {},
"price": {},
"commission": {},
"id": 0,
"merchantType": "string",
"amount": {
"amount": 0,
"convertedAmount": 0,
"currency": "USD",
"convertedCurrency": "USD"
},
"checkNumber": "string",
"isPhysical": true,
"quantity": 0,
"valoren": "string",
"isManual": true,
"merchant": {
"website": "string",
"address": {},
"contact": {},
"categoryLabel": [],
"coordinates": {},
"name": "string",
"id": "string",
"source": "YODLEE",
"logoURL": "string"
},
"sedol": "string",
"transactionDate": "string",
"categoryType": "TRANSFER",
"accountId": 0,
"createdDate": "string",
"sourceType": "AGGREGATED",
"CONTAINER": "bank",
"postDate": "string",
"parentCategoryId": 0,
"subType": "OVERDRAFT_CHARGE",
"category": "string",
"runningBalance": {},
"categoryId": 0,
"holdingDescription": "string",
"isin": "string",
"status": "POSTED"
*/
class IncomeTransformer
{
}

View File

@ -18,7 +18,7 @@ class Yodlee
public bool $test_mode;
private string $api_endpoint = '';
private string $api_endpoint = 'https://production.api.yodlee.com/ysl';
private string $test_api_endpoint = 'https://sandbox.api.yodlee.com/ysl';
@ -69,21 +69,26 @@ class Yodlee
}
public function getAccounts($token)
public function getAccounts($token, $params = [])
{
$response = $this->bankRequest('/accounts', 'get', [], ["Authorization" => "Bearer {$token}"]);
$response = Http::withHeaders($this->getHeaders(["Authorization" => "Bearer {$token}"]))->get($this->api_endpoint. "/accounts", $params);
if($response->successful())
return $response->object();
if($response->failed())
return $response->body();
return $response;
}
public function getTransactions($token)
public function getTransactions($token, $params = [])
{
$response = Http::withHeaders($this->getHeaders(["Authorization" => "Bearer {$token}"]))->get($this->api_endpoint. "/transactions", ['categoryType' => 'EXPENSE']);
// $response = Http::withHeaders($this->getHeaders(["Authorization" => "Bearer {$token}"]))->get($this->api_endpoint. "/transactions");
$response = Http::withHeaders($this->getHeaders(["Authorization" => "Bearer {$token}"]))->get($this->api_endpoint. "/transactions", $params);
if($response->successful())
return $response->object();
@ -93,12 +98,16 @@ class Yodlee
}
public function getTransactionCategories($token)
public function getTransactionCategories($token, $params = [])
{
$response = $this->bankRequest('/transactions/categories', 'get', [], ["Authorization" => "Bearer {$token}"]);
$response = Http::withHeaders($this->getHeaders(["Authorization" => "Bearer {$token}"]))->get($this->api_endpoint. "/transactions/categories", $params);
return $response;
if($response->successful())
return $response->object();
if($response->failed())
return $response->body();
}

View File

@ -221,7 +221,7 @@ class YodleeApiTest extends TestCase
$yodlee = new Yodlee(true);
$access_token = $yodlee->getAccessToken('sbMem62e1e69547bfb1');
$access_token = $yodlee->getAccessToken('sbMem62e1e69547bfb2');
$transactions = $yodlee->getTransactionCategories($access_token);
@ -394,9 +394,11 @@ class YodleeApiTest extends TestCase
$yodlee = new Yodlee(true);
$access_token = $yodlee->getAccessToken('sbMem62e1e69547bfb3');
$access_token = $yodlee->getAccessToken('sbMem62e1e69547bfb1');
$transactions = $yodlee->getTransactions($access_token);
nlog($access_token);
$transactions = $yodlee->getTransactions($access_token, ['categoryId' => 2, 'fromDate' => '2000-01-01']);
nlog($transactions);