1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 21:52:35 +01:00
invoiceninja/app/Helpers/Bank/Yodlee/Transformer/AccountTransformer.php

155 lines
5.2 KiB
PHP
Raw Normal View History

2022-08-05 06:25:06 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2022-08-05 06:25:06 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Helpers\Bank\Yodlee\Transformer;
2022-08-08 04:46:41 +02:00
use App\Helpers\Bank\AccountTransformerInterface;
2023-02-16 02:36:09 +01:00
2022-08-05 06:25:06 +02:00
/**
2022-08-08 01:15:31 +02:00
[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
)
2022-08-05 06:25:06 +02:00
2022-08-08 01:15:31 +02:00
[id] => 12331861
[includeInNetWorth] => 1
[providerId] => 18769
[providerName] => Dag Site Captcha
2023-02-16 02:36:09 +01:00
[isManual] =>
2022-08-08 01:15:31 +02:00
[currentBalance] => stdClass Object
(
[currency] => USD
[amount] => 49778.07
)
2022-08-05 06:25:06 +02:00
2022-08-08 01:15:31 +02:00
[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
)
2022-08-05 06:25:06 +02:00
2022-08-08 01:15:31 +02:00
)
2022-08-05 06:25:06 +02:00
2022-08-08 01:15:31 +02:00
)
2022-08-05 06:25:06 +02:00
)
*/
2022-08-10 03:56:46 +02:00
2022-08-08 04:46:41 +02:00
class AccountTransformer implements AccountTransformerInterface
2022-08-05 06:25:06 +02:00
{
2023-08-10 04:17:37 +02:00
2022-08-08 04:46:41 +02:00
public function transform($yodlee_account)
{
2022-08-08 01:15:31 +02:00
$data = [];
2023-02-16 02:36:09 +01:00
if (!property_exists($yodlee_account, 'account')) {
2022-08-11 06:19:35 +02:00
return $data;
2023-02-16 02:36:09 +01:00
}
2022-08-11 04:39:43 +02:00
2023-02-16 02:36:09 +01:00
foreach ($yodlee_account->account as $account) {
2022-08-08 01:15:31 +02:00
$data[] = $this->transformAccount($account);
}
return $data;
}
public function transformAccount($account)
2022-08-05 06:25:06 +02:00
{
$current_balance = 0;
$account_currency = '';
if(property_exists($account, 'currentBalance')) {
$current_balance = $account->currentBalance->amount ?? 0;
$account_currency = $account->currentBalance->currency ?? '';
}
elseif(property_exists($account, 'balance')){
$current_balance = $account->balance->amount ?? 0;
$account_currency = $account->balance->currency ?? '';
}
2023-08-10 04:17:37 +02:00
$account_status = $account->accountStatus;
if(property_exists($account, 'dataset')){
$dataset = $account->dataset[0];
$status = false;
$update = false;
match($dataset->additionalStatus ?? ''){
'LOGIN_IN_PROGRESS' => $status = 'Data retrieval in progress.',
'USER_INPUT_REQUIRED' => $status = 'Please reconnect your account, authentication required.',
'LOGIN_SUCCESS' => $status = 'Data retrieval in progress',
'ACCOUNT_SUMMARY_RETRIEVED' => $status = 'Account summary retrieval in progress.',
'NEVER_INITIATED' => $status = 'Upstream working on connecting to your account.',
'LOGIN_FAILED' => $status = 'Authentication failed, please try reauthenticating.',
'REQUEST_TIME_OUT' => $status = 'Timeout encountered retrieving data.',
'DATA_RETRIEVAL_FAILED' => $status = 'Login successful, but data retrieval failed.',
'PARTIAL_DATA_RETRIEVED' => $status = 'Partial data update failed.',
'PARTIAL_DATA_RETRIEVED_REM_SCHED' => $status = 'Partial data update failed.',
'SUCCESS' => $status = 'All accounts added or updated successfully.',
default => $status = false
};
if($status){
$account_status = $status;
}
match($dataset->updateEligibility ?? ''){
'ALLOW_UPDATE' => $update = 'Account connection stable.',
'ALLOW_UPDATE_WITH_CREDENTIALS' => $update = 'Please reconnect your account with updated credentials.',
'DISALLOW_UPDATE' => $update = 'Update not available due to technical issues.',
default => $update = false,
};
if($status && $update){
$account_status = $status . ' - ' . $update;
}
elseif($update){
$account_status = $update;
}
}
2022-08-05 06:25:06 +02:00
return [
2022-08-08 01:15:31 +02:00
'id' => $account->id,
'account_type' => $account->CONTAINER,
// 'account_name' => $account->accountName,
'account_name' => property_exists($account, 'accountName') ? $account->accountName : $account->nickname,
2023-08-10 04:17:37 +02:00
'account_status' => $account_status,
2022-11-06 09:03:27 +01:00
'account_number' => property_exists($account, 'accountNumber') ? '**** ' . substr($account?->accountNumber, -7) : '',
2022-08-10 03:56:46 +02:00
'provider_account_id' => $account->providerAccountId,
'provider_id' => $account->providerId,
'provider_name' => $account->providerName,
2022-08-11 06:19:35 +02:00
'nickname' => property_exists($account, 'nickname') ? $account->nickname : '',
'current_balance' => $current_balance,
'account_currency' => $account_currency,
2022-08-05 06:25:06 +02:00
];
}
}