James Cole 2 years ago
parent
commit
24f7ed3944
No known key found for this signature in database GPG Key ID: B49A324B7EAD6D80
  1. 32
      app/Http/Controllers/Import/ConfigurationController.php
  2. 4
      app/Http/Controllers/Import/ConversionController.php
  3. 2
      app/Http/Controllers/Import/DownloadController.php
  4. 28
      app/Http/Controllers/Import/File/RoleController.php
  5. 23
      app/Http/Controllers/Import/MapController.php
  6. 4
      app/Http/Controllers/Import/Nordigen/LinkController.php
  7. 8
      app/Http/Controllers/Import/Nordigen/SelectionController.php
  8. 8
      app/Http/Controllers/Import/Spectre/ConnectionController.php
  9. 6
      app/Http/Controllers/Import/SubmitController.php
  10. 24
      app/Http/Middleware/IsReadyForStep.php
  11. 2
      app/Services/CSV/File/FileReader.php
  12. 3
      app/Services/CSV/Roles/RoleService.php
  13. 4
      app/Services/Camt/Conversion/RoutineManager.php
  14. 41
      app/Services/Nordigen/Authentication/SecretManager.php
  15. 43
      app/Services/Nordigen/Request/PostNewTokenRequest.php
  16. 33
      app/Services/Nordigen/Services/AccountInformationCollector.php
  17. 20
      app/Services/Nordigen/TokenManager.php
  18. 54
      app/Services/Shared/Configuration/Configuration.php
  19. 2
      app/Services/Spectre/Authentication/SecretManager.php
  20. 2
      app/Support/Http/RestoresConfiguration.php

32
app/Http/Controllers/Import/ConfigurationController.php

@ -26,7 +26,6 @@ namespace App\Http\Controllers\Import;
use App\Exceptions\AgreementExpiredException; use App\Exceptions\AgreementExpiredException;
use App\Exceptions\ImporterErrorException; use App\Exceptions\ImporterErrorException;
use App\Exceptions\ImporterHttpException;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Middleware\ConfigurationControllerMiddleware; use App\Http\Middleware\ConfigurationControllerMiddleware;
use App\Http\Request\ConfigurationPostRequest; use App\Http\Request\ConfigurationPostRequest;
@ -39,15 +38,12 @@ use App\Support\Http\RestoresConfiguration;
use App\Support\Internal\CollectsAccounts; use App\Support\Internal\CollectsAccounts;
use App\Support\Internal\MergesAccountLists; use App\Support\Internal\MergesAccountLists;
use Carbon\Carbon; use Carbon\Carbon;
use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\Factory;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\View\View; use Illuminate\View\View;
use JsonException; use JsonException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/** /**
* Class ConfigurationController * Class ConfigurationController
@ -71,15 +67,9 @@ class ConfigurationController extends Controller
} }
/** /**
* @param Request $request
* @param Request $request
* *
* @return Factory|RedirectResponse|View * @return Factory|RedirectResponse|View
* @throws ImporterErrorException
* @throws ImporterHttpException
* @throws ApiHttpException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws AgreementExpiredException
*/ */
public function index(Request $request) public function index(Request $request)
{ {
@ -113,7 +103,23 @@ class ConfigurationController extends Controller
$importerAccounts = []; $importerAccounts = [];
$uniqueColumns = config('csv.unique_column_options'); $uniqueColumns = config('csv.unique_column_options');
if ('nordigen' === $flow) { if ('nordigen' === $flow) {
// TODO here we need to redirect to Nordigen.
try {
$importerAccounts = $this->getNordigenAccounts($configuration); $importerAccounts = $this->getNordigenAccounts($configuration);
} catch (AgreementExpiredException $e) {
app('log')->error($e->getMessage());
// remove thing from configuration
$configuration->clearRequisitions();
// save configuration in session and on disk:
session()->put(Constants::CONFIGURATION, $configuration->toSessionArray());
$configFileName = StorageService::storeContent(json_encode($configuration->toArray(), JSON_PRETTY_PRINT));
session()->put(Constants::UPLOAD_CONFIG_FILE, $configFileName);
// redirect to selection.
return redirect()->route('009-selection.index');
}
$uniqueColumns = config('nordigen.unique_column_options'); $uniqueColumns = config('nordigen.unique_column_options');
$importerAccounts = $this->mergeNordigenAccountLists($importerAccounts, $fireflyIIIaccounts); $importerAccounts = $this->mergeNordigenAccountLists($importerAccounts, $fireflyIIIaccounts);
} }
@ -140,7 +146,7 @@ class ConfigurationController extends Controller
/** /**
* @param Request $request
* @param Request $request
* *
* @return JsonResponse * @return JsonResponse
*/ */
@ -156,7 +162,7 @@ class ConfigurationController extends Controller
} }
/** /**
* @param ConfigurationPostRequest $request
* @param ConfigurationPostRequest $request
* *
* @return RedirectResponse * @return RedirectResponse
* @throws ImporterErrorException * @throws ImporterErrorException

4
app/Http/Controllers/Import/ConversionController.php

@ -150,10 +150,6 @@ class ConversionController extends Controller
* @param Request $request * @param Request $request
* *
* @return JsonResponse * @return JsonResponse
* @throws ImporterErrorException
* @throws ImporterHttpException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function start(Request $request): JsonResponse public function start(Request $request): JsonResponse
{ {

2
app/Http/Controllers/Import/DownloadController.php

@ -41,8 +41,6 @@ class DownloadController extends Controller
/** /**
* @return Application|ResponseFactory|Response * @return Application|ResponseFactory|Response
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function download(): Response|Application|ResponseFactory public function download(): Response|Application|ResponseFactory
{ {

28
app/Http/Controllers/Import/File/RoleController.php

@ -65,13 +65,6 @@ class RoleController extends Controller
* @param Request $request * @param Request $request
* *
* @return View|void * @return View|void
* @throws JsonException
* @throws Exception
* @throws InvalidArgument
* @throws UnableToProcessCsv
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ImporterErrorException
*/ */
public function index(Request $request) public function index(Request $request)
{ {
@ -98,11 +91,6 @@ class RoleController extends Controller
* @param RolesPostRequest $request * @param RolesPostRequest $request
* *
* @return RedirectResponse * @return RedirectResponse
* @throws ContainerExceptionInterface
* @throws FilesystemException
* @throws ImporterErrorException
* @throws JsonException
* @throws NotFoundExceptionInterface
*/ */
public function postIndex(RolesPostRequest $request): RedirectResponse public function postIndex(RolesPostRequest $request): RedirectResponse
{ {
@ -126,9 +114,6 @@ class RoleController extends Controller
* @param Configuration $configuration * @param Configuration $configuration
* *
* @return View * @return View
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
private function camtIndex(Request $request, Configuration $configuration): View private function camtIndex(Request $request, Configuration $configuration): View
{ {
@ -222,10 +207,6 @@ class RoleController extends Controller
* @param Configuration $configuration * @param Configuration $configuration
* *
* @return RedirectResponse * @return RedirectResponse
* @throws ContainerExceptionInterface
* @throws FilesystemException
* @throws JsonException
* @throws NotFoundExceptionInterface
*/ */
private function camtPostIndex(RolesPostRequest $request, Configuration $configuration): RedirectResponse private function camtPostIndex(RolesPostRequest $request, Configuration $configuration): RedirectResponse
{ {
@ -267,12 +248,6 @@ class RoleController extends Controller
* @param Configuration $configuration * @param Configuration $configuration
* *
* @return View * @return View
* @throws ContainerExceptionInterface
* @throws Exception
* @throws InvalidArgument
* @throws JsonException
* @throws NotFoundExceptionInterface
* @throws UnableToProcessCsv
*/ */
private function csvIndex(Request $request, Configuration $configuration): View private function csvIndex(Request $request, Configuration $configuration): View
{ {
@ -306,9 +281,6 @@ class RoleController extends Controller
* @param Configuration $configuration * @param Configuration $configuration
* *
* @return RedirectResponse * @return RedirectResponse
* @throws ContainerExceptionInterface
* @throws JsonException
* @throws NotFoundExceptionInterface
*/ */
private function csvPostIndex(RolesPostRequest $request, Configuration $configuration): RedirectResponse private function csvPostIndex(RolesPostRequest $request, Configuration $configuration): RedirectResponse
{ {

23
app/Http/Controllers/Import/MapController.php

@ -66,10 +66,6 @@ class MapController extends Controller
/** /**
* @return Factory|View * @return Factory|View
* @throws ContainerExceptionInterface
* @throws FileNotFoundException
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
public function index() public function index()
{ {
@ -121,9 +117,6 @@ class MapController extends Controller
* @param Request $request * @param Request $request
* *
* @return RedirectResponse * @return RedirectResponse
* @throws ContainerExceptionInterface
* @throws JsonException
* @throws NotFoundExceptionInterface
*/ */
public function postIndex(Request $request): RedirectResponse public function postIndex(Request $request): RedirectResponse
{ {
@ -209,9 +202,6 @@ class MapController extends Controller
* TODO needs renaming or specific CAMT counterpart. * TODO needs renaming or specific CAMT counterpart.
* *
* @return array * @return array
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
private function getCSVMapInformation(): array private function getCSVMapInformation(): array
{ {
@ -284,9 +274,6 @@ class MapController extends Controller
* TODO needs refactoring and proper splitting into helpers. * TODO needs refactoring and proper splitting into helpers.
* *
* @return array * @return array
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
private function getCamtMapInformation(): array private function getCamtMapInformation(): array
{ {
@ -344,9 +331,6 @@ class MapController extends Controller
/** /**
* @return array * @return array
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
private function getCategories(): array private function getCategories(): array
{ {
@ -383,10 +367,6 @@ class MapController extends Controller
* Weird bunch of code to return info on Spectre and Nordigen. * Weird bunch of code to return info on Spectre and Nordigen.
* *
* @return array * @return array
* @throws ContainerExceptionInterface
* @throws FileNotFoundException
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
private function getImporterMapInformation(): array private function getImporterMapInformation(): array
{ {
@ -446,9 +426,6 @@ class MapController extends Controller
/** /**
* @return array * @return array
* @throws ImporterErrorException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* *
* TODO move to helper or something * TODO move to helper or something
*/ */

4
app/Http/Controllers/Import/Nordigen/LinkController.php

@ -132,10 +132,6 @@ class LinkController extends Controller
* @param Request $request * @param Request $request
* *
* @return Application|RedirectResponse|Redirector * @return Application|RedirectResponse|Redirector
* @throws ImporterErrorException
* @throws ImporterHttpException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function callback(Request $request) public function callback(Request $request)
{ {

8
app/Http/Controllers/Import/Nordigen/SelectionController.php

@ -67,10 +67,6 @@ class SelectionController extends Controller
* Step 9, select a country + bank. * Step 9, select a country + bank.
* *
* @return Factory|View * @return Factory|View
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
* @throws AgreementExpiredException
*/ */
public function index() public function index()
{ {
@ -115,10 +111,6 @@ class SelectionController extends Controller
* @param SelectionRequest $request * @param SelectionRequest $request
* *
* @return Application|RedirectResponse|Redirector * @return Application|RedirectResponse|Redirector
* @throws ImporterErrorException
* @throws FilesystemException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function postIndex(SelectionRequest $request) public function postIndex(SelectionRequest $request)
{ {

8
app/Http/Controllers/Import/Spectre/ConnectionController.php

@ -72,10 +72,6 @@ class ConnectionController extends Controller
/** /**
* *
* @return Application|Factory|View * @return Application|Factory|View
* @throws ImporterErrorException
* @throws ImporterHttpException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function index() public function index()
{ {
@ -144,10 +140,6 @@ class ConnectionController extends Controller
* @param Request $request * @param Request $request
* *
* @return Application|RedirectResponse|Redirector * @return Application|RedirectResponse|Redirector
* @throws ImporterErrorException
* @throws ImporterHttpException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function post(Request $request) public function post(Request $request)
{ {

6
app/Http/Controllers/Import/SubmitController.php

@ -67,9 +67,6 @@ class SubmitController extends Controller
/** /**
* @return Application|Factory|View * @return Application|Factory|View
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
public function index() public function index()
{ {
@ -102,9 +99,6 @@ class SubmitController extends Controller
* @param Request $request * @param Request $request
* *
* @return JsonResponse * @return JsonResponse
* @throws ContainerExceptionInterface
* @throws FilesystemException
* @throws NotFoundExceptionInterface
*/ */
public function start(Request $request): JsonResponse public function start(Request $request): JsonResponse
{ {

24
app/Http/Middleware/IsReadyForStep.php

@ -45,9 +45,6 @@ trait IsReadyForStep
* @param Closure $next * @param Closure $next
* *
* @return mixed * @return mixed
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
public function handle(Request $request, Closure $next): mixed public function handle(Request $request, Closure $next): mixed
{ {
@ -67,9 +64,6 @@ trait IsReadyForStep
* @param Request $request * @param Request $request
* *
* @return bool * @return bool
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
protected function isReadyForStep(Request $request): bool protected function isReadyForStep(Request $request): bool
{ {
@ -99,9 +93,6 @@ trait IsReadyForStep
* @param Request $request * @param Request $request
* *
* @return RedirectResponse|null * @return RedirectResponse|null
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
protected function redirectToCorrectStep(Request $request): ?RedirectResponse protected function redirectToCorrectStep(Request $request): ?RedirectResponse
{ {
@ -141,9 +132,6 @@ trait IsReadyForStep
/** /**
* @return bool * @return bool
* @throws ImporterErrorException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
private function isReadyForFileStep(): bool private function isReadyForFileStep(): bool
{ {
@ -200,9 +188,6 @@ trait IsReadyForStep
/** /**
* @return bool * @return bool
* @throws ImporterErrorException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
private function isReadyForNordigenStep(): bool private function isReadyForNordigenStep(): bool
{ {
@ -291,9 +276,6 @@ trait IsReadyForStep
/** /**
* @return bool * @return bool
* @throws ImporterErrorException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
private function isReadyForSpectreStep(): bool private function isReadyForSpectreStep(): bool
{ {
@ -437,9 +419,6 @@ trait IsReadyForStep
/** /**
* @return RedirectResponse * @return RedirectResponse
* @throws ImporterErrorException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
private function redirectToCorrectNordigenStep(): RedirectResponse private function redirectToCorrectNordigenStep(): RedirectResponse
{ {
@ -502,9 +481,6 @@ trait IsReadyForStep
/** /**
* @return RedirectResponse * @return RedirectResponse
* @throws ImporterErrorException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
private function redirectToCorrectSpectreStep(): RedirectResponse private function redirectToCorrectSpectreStep(): RedirectResponse
{ {

2
app/Services/CSV/File/FileReader.php

@ -60,8 +60,6 @@ class FileReader
* @param bool $convert * @param bool $convert
* *
* @return Reader * @return Reader
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public static function getReaderFromSession(bool $convert = false): Reader public static function getReaderFromSession(bool $convert = false): Reader
{ {

3
app/Services/CSV/Roles/RoleService.php

@ -175,9 +175,6 @@ class RoleService
* @param Configuration $configuration * @param Configuration $configuration
* *
* @return array * @return array
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
public static function getExampleDataFromCamt(string $content, Configuration $configuration): array public static function getExampleDataFromCamt(string $content, Configuration $configuration): array
{ {

4
app/Services/Camt/Conversion/RoutineManager.php

@ -105,9 +105,6 @@ class RoutineManager implements RoutineManagerInterface
/** /**
* @inheritDoc * @inheritDoc
* @return array * @return array
* @throws ContainerExceptionInterface
* @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
public function start(): array public function start(): array
{ {
@ -154,7 +151,6 @@ class RoutineManager implements RoutineManagerInterface
/** /**
* @return Message|null * @return Message|null
* @throws ContainerExceptionInterface|NotFoundExceptionInterface|ImporterErrorException
*/ */
private function getCamtMessage(): ?Message private function getCamtMessage(): ?Message
{ {

41
app/Services/Nordigen/Authentication/SecretManager.php

@ -27,22 +27,19 @@ namespace App\Services\Nordigen\Authentication;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\HttpFoundation\Cookie;
/** /**
* Class SecretManager * Class SecretManager
*/ */
class SecretManager class SecretManager
{ {
public const NORDIGEN_ID = 'nordigen_id';
public const NORDIGEN_KEY = 'nordigen_key';
public const string NORDIGEN_ID = 'nordigen_id';
public const string NORDIGEN_KEY = 'nordigen_key';
/** /**
* Will return the Nordigen ID. From a cookie if its there, otherwise from configuration. * Will return the Nordigen ID. From a cookie if its there, otherwise from configuration.
* *
* @return string * @return string
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public static function getId(): string public static function getId(): string
{ {
@ -51,15 +48,18 @@ class SecretManager
return (string)config('nordigen.id'); return (string)config('nordigen.id');
} }
return (string)session()->get(self::NORDIGEN_ID);
try {
$id = (string)session()->get(self::NORDIGEN_ID);
} catch (ContainerExceptionInterface | NotFoundExceptionInterface $e) {
$id = '(super invalid)';
}
return $id;
} }
/** /**
* Will return the Nordigen ID. From a cookie if its there, otherwise from configuration. * Will return the Nordigen ID. From a cookie if its there, otherwise from configuration.
* *
* @return string * @return string
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public static function getKey(): string public static function getKey(): string
{ {
@ -69,7 +69,12 @@ class SecretManager
return (string)config('nordigen.key'); return (string)config('nordigen.key');
} }
return (string)session()->get(self::NORDIGEN_KEY);
try {
$key = (string)session()->get(self::NORDIGEN_KEY);
} catch (NotFoundExceptionInterface | ContainerExceptionInterface $e) {
$key = '(super invalid key)';
}
return $key;
} }
/** /**
@ -100,23 +105,29 @@ class SecretManager
* Will verify if the user has a Nordigen ID (in a cookie) * Will verify if the user has a Nordigen ID (in a cookie)
* *
* @return bool * @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
private static function hasId(): bool private static function hasId(): bool
{ {
return '' !== (string)session()->get(self::NORDIGEN_ID);
try {
$id = (string)session()->get(self::NORDIGEN_ID);
} catch (NotFoundExceptionInterface | ContainerExceptionInterface $e) {
$id = '';
}
return '' !== $id;
} }
/** /**
* Will verify if the user has a Nordigen Key (in a cookie) * Will verify if the user has a Nordigen Key (in a cookie)
* *
* @return bool * @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
private static function hasKey(): bool private static function hasKey(): bool
{ {
return '' !== (string)session()->get(self::NORDIGEN_KEY);
try {
$key = (string)session()->get(self::NORDIGEN_KEY);
} catch (NotFoundExceptionInterface | ContainerExceptionInterface $e) {
$key = '';
}
return '' !== $key;
} }
} }

43
app/Services/Nordigen/Request/PostNewTokenRequest.php

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace App\Services\Nordigen\Request; namespace App\Services\Nordigen\Request;
use App\Exceptions\ImporterHttpException;
use App\Services\Nordigen\Response\TokenSetResponse; use App\Services\Nordigen\Response\TokenSetResponse;
use App\Services\Shared\Response\Response; use App\Services\Shared\Response\Response;
use GuzzleHttp\Client; use GuzzleHttp\Client;
@ -46,33 +47,35 @@ class PostNewTokenRequest extends Request
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function get(): Response
{
}
public function get(): Response {}
/** /**
* @inheritDoc * @inheritDoc
* @throws GuzzleException
*/ */
public function post(): Response public function post(): Response
{ {
$url = sprintf('%s/%s', config('nordigen.url'), 'api/v2/token/new/'); $url = sprintf('%s/%s', config('nordigen.url'), 'api/v2/token/new/');
$client = new Client(); $client = new Client();
$res = $client->post(
$url,
[
'json' => [
'secret_id' => $this->identifier,
'secret_key' => $this->key,
],
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'user-agent' => sprintf('Firefly III Universal Data Importer / %s / %s', config('importer.version'), config('auth.line_a')),
],
]
);
try {
$res = $client->post(
$url,
[
'json' => [
'secret_id' => $this->identifier,
'secret_key' => $this->key,
],
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
'user-agent' => sprintf('Firefly III Universal Data Importer / %s / %s', config('importer.version'), config('auth.line_a')),
],
]
);
} catch (GuzzleException $e) {
app('log')->error($e->getMessage());
throw new ImporterHttpException($e->getMessage(), 0, $e);
}
$body = (string)$res->getBody(); $body = (string)$res->getBody();
$json = json_decode($body, true, JSON_THROW_ON_ERROR); $json = json_decode($body, true, JSON_THROW_ON_ERROR);
@ -82,7 +85,5 @@ class PostNewTokenRequest extends Request
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function put(): Response
{
}
public function put(): Response {}
} }

33
app/Services/Nordigen/Services/AccountInformationCollector.php

@ -43,7 +43,7 @@ use App\Services\Nordigen\TokenManager;
class AccountInformationCollector class AccountInformationCollector
{ {
/** /**
* @param Account $account
* @param Account $account
* *
* @return Account * @return Account
* @throws AgreementExpiredException * @throws AgreementExpiredException
@ -56,7 +56,7 @@ class AccountInformationCollector
$detailedAccount = $account; $detailedAccount = $account;
try { try {
$detailedAccount = self::getAccountDetails($account); $detailedAccount = self::getAccountDetails($account);
} catch (ImporterHttpException|ImporterErrorException $e) {
} catch (ImporterErrorException $e) {
app('log')->error($e->getMessage()); app('log')->error($e->getMessage());
// ignore error otherwise for now. // ignore error otherwise for now.
$detailedAccount->setStatus('no-info'); $detailedAccount->setStatus('no-info');
@ -66,7 +66,7 @@ class AccountInformationCollector
try { try {
$balanceAccount = self::getBalanceDetails($account); $balanceAccount = self::getBalanceDetails($account);
} catch (ImporterHttpException|ImporterErrorException $e) {
} catch (ImporterHttpException | ImporterErrorException $e) {
app('log')->error($e->getMessage()); app('log')->error($e->getMessage());
// ignore error otherwise for now. // ignore error otherwise for now.
$status = $balanceAccount->getStatus(); $status = $balanceAccount->getStatus();
@ -83,12 +83,10 @@ class AccountInformationCollector
} }
/** /**
* @param Account $account
* @param Account $account
* *
* @return Account * @return Account
* @throws ImporterErrorException
* @throws ImporterHttpException
* @throws AgreementExpiredException
* @throws ImporterErrorException|AgreementExpiredException
*/ */
protected static function getAccountDetails(Account $account): Account protected static function getAccountDetails(Account $account): Account
{ {
@ -99,11 +97,18 @@ class AccountInformationCollector
$request = new GetAccountInformationRequest($url, $accessToken, $account->getIdentifier()); $request = new GetAccountInformationRequest($url, $accessToken, $account->getIdentifier());
/** @var ArrayResponse $response */ /** @var ArrayResponse $response */
$response = $request->get();
try {
$response = $request->get();
} catch (AgreementExpiredException $e) {
// need to redirect user at some point.
throw new AgreementExpiredException($e->getMessage(), 0, $e);
} catch (ImporterHttpException | ImporterErrorException $e) {
throw new ImporterErrorException($e->getMessage(), 0, $e);
}
if (!array_key_exists('account', $response->data)) { if (!array_key_exists('account', $response->data)) {
app('log')->error('Missing account array', $response->data); app('log')->error('Missing account array', $response->data);
throw new ImporterHttpException('No account array, exit.');
throw new ImporterErrorException('No account array, exit.');
} }
$information = $response->data['account']; $information = $response->data['account'];
@ -143,11 +148,9 @@ class AccountInformationCollector
} }
/** /**
* @param Account $account
* @param Account $account
* *
* @return Account * @return Account
* @throws ImporterErrorException
* @throws ImporterHttpException
*/ */
private static function getBalanceDetails(Account $account): Account private static function getBalanceDetails(Account $account): Account
{ {
@ -170,11 +173,9 @@ class AccountInformationCollector
} }
/** /**
* @param Account $account
* @param Account $account
*
* @return Account * @return Account
* @throws AgreementExpiredException
* @throws ImporterErrorException
* @throws ImporterHttpException
*/ */
private static function getBasicDetails(Account $account): Account private static function getBasicDetails(Account $account): Account
{ {

20
app/Services/Nordigen/TokenManager.php

@ -48,7 +48,7 @@ class TokenManager
self::validateAllTokens(); self::validateAllTokens();
try { try {
$token = session()->get(Constants::NORDIGEN_ACCESS_TOKEN); $token = session()->get(Constants::NORDIGEN_ACCESS_TOKEN);
} catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
} catch (NotFoundExceptionInterface | ContainerExceptionInterface $e) {
throw new ImporterErrorException($e->getMessage(), 0, $e); throw new ImporterErrorException($e->getMessage(), 0, $e);
} }
@ -101,8 +101,6 @@ class TokenManager
/** /**
* @return bool * @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public static function hasValidAccessToken(): bool public static function hasValidAccessToken(): bool
{ {
@ -113,7 +111,11 @@ class TokenManager
return false; return false;
} }
$tokenValidity = session()->get(Constants::NORDIGEN_ACCESS_EXPIRY_TIME) ?? 0;
try {
$tokenValidity = session()->get(Constants::NORDIGEN_ACCESS_EXPIRY_TIME) ?? 0;
} catch (ContainerExceptionInterface | NotFoundExceptionInterface $e) {
$tokenValidity = 0;
}
//app('log')->debug(sprintf('Nordigen token is valid until %s', date('Y-m-d H:i:s', $tokenValidity))); //app('log')->debug(sprintf('Nordigen token is valid until %s', date('Y-m-d H:i:s', $tokenValidity)));
$result = time() < $tokenValidity; $result = time() < $tokenValidity;
if (false === $result) { if (false === $result) {
@ -129,8 +131,6 @@ class TokenManager
/** /**
* @return bool * @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public static function hasValidRefreshToken(): bool public static function hasValidRefreshToken(): bool
{ {
@ -141,15 +141,17 @@ class TokenManager
return false; return false;
} }
$tokenValidity = session()->get(Constants::NORDIGEN_REFRESH_EXPIRY_TIME) ?? 0;
try {
$tokenValidity = session()->get(Constants::NORDIGEN_REFRESH_EXPIRY_TIME) ?? 0;
} catch (ContainerExceptionInterface | NotFoundExceptionInterface $e) {
$tokenValidity = 0;
}
return time() < $tokenValidity; return time() < $tokenValidity;
} }
/** /**
* @throws ContainerExceptionInterface
* @throws ImporterErrorException * @throws ImporterErrorException
* @throws NotFoundExceptionInterface
*/ */
public static function validateAllTokens(): void public static function validateAllTokens(): void
{ {

54
app/Services/Shared/Configuration/Configuration.php

@ -163,7 +163,7 @@ class Configuration
} }
/** /**
* @param array $array
* @param array $array
* *
* @return static * @return static
*/ */
@ -253,7 +253,7 @@ class Configuration
} }
/** /**
* @param array $data
* @param array $data
* *
* @return $this * @return $this
*/ */
@ -281,7 +281,7 @@ class Configuration
} }
/** /**
* @param array $array
* @param array $array
* *
* @return $this * @return $this
*/ */
@ -379,8 +379,8 @@ class Configuration
} }
/** /**
* @param string $unit
* @param int $number
* @param string $unit
* @param int $number
* *
* @return string|null * @return string|null
*/ */
@ -405,7 +405,7 @@ class Configuration
} }
/** /**
* @param array $data
* @param array $data
* *
* @return static * @return static
*/ */
@ -521,7 +521,7 @@ class Configuration
} }
/** /**
* @param array $data
* @param array $data
* *
* @return static * @return static
*/ */
@ -534,7 +534,7 @@ class Configuration
} }
/** /**
* @param array $data
* @param array $data
* *
* @return static * @return static
*/ */
@ -544,8 +544,8 @@ class Configuration
} }
/** /**
* @param string $key
* @param string $identifier
* @param string $key
* @param string $identifier
*/ */
public function addRequisition(string $key, string $identifier) public function addRequisition(string $key, string $identifier)
{ {
@ -561,7 +561,7 @@ class Configuration
} }
/** /**
* @param array $accounts
* @param array $accounts
*/ */
public function setAccounts(array $accounts): void public function setAccounts(array $accounts): void
{ {
@ -577,7 +577,7 @@ class Configuration
} }
/** /**
* @param string $connection
* @param string $connection
*/ */
public function setConnection(string $connection): void public function setConnection(string $connection): void
{ {
@ -593,7 +593,7 @@ class Configuration
} }
/** /**
* @param string $contentType
* @param string $contentType
*/ */
public function setContentType(string $contentType): void public function setContentType(string $contentType): void
{ {
@ -673,7 +673,7 @@ class Configuration
} }
/** /**
* @param array $doMapping
* @param array $doMapping
*/ */
public function setDoMapping(array $doMapping): void public function setDoMapping(array $doMapping): void
{ {
@ -697,7 +697,7 @@ class Configuration
} }
/** /**
* @param string $flow
* @param string $flow
*/ */
public function setFlow(string $flow): void public function setFlow(string $flow): void
{ {
@ -721,7 +721,15 @@ class Configuration
} }
/** /**
* @param string $identifier
* @return void
*/
public function clearRequisitions(): void
{
$this->nordigenRequisitions = [];
}
/**
* @param string $identifier
*/ */
public function setIdentifier(string $identifier): void public function setIdentifier(string $identifier): void
{ {
@ -737,7 +745,7 @@ class Configuration
} }
/** /**
* @param array $mapping
* @param array $mapping
*/ */
public function setMapping(array $mapping): void public function setMapping(array $mapping): void
{ {
@ -758,7 +766,7 @@ class Configuration
} }
/** /**
* @param string $nordigenBank
* @param string $nordigenBank
*/ */
public function setNordigenBank(string $nordigenBank): void public function setNordigenBank(string $nordigenBank): void
{ {
@ -774,7 +782,7 @@ class Configuration
} }
/** /**
* @param string $nordigenCountry
* @param string $nordigenCountry
*/ */
public function setNordigenCountry(string $nordigenCountry): void public function setNordigenCountry(string $nordigenCountry): void
{ {
@ -790,7 +798,7 @@ class Configuration
} }
/** /**
* @param string $nordigenMaxDays
* @param string $nordigenMaxDays
*/ */
public function setNordigenMaxDays(string $nordigenMaxDays): void public function setNordigenMaxDays(string $nordigenMaxDays): void
{ {
@ -806,7 +814,7 @@ class Configuration
} }
/** /**
* @param string $key
* @param string $key
* *
* @return string|null * @return string|null
*/ */
@ -824,7 +832,7 @@ class Configuration
} }
/** /**
* @param array $roles
* @param array $roles
*/ */
public function setRoles(array $roles): void public function setRoles(array $roles): void
{ {
@ -856,7 +864,7 @@ class Configuration
} }
/** /**
* @param string $name
* @param string $name
* *
* @return bool * @return bool
*/ */

2
app/Services/Spectre/Authentication/SecretManager.php

@ -41,8 +41,6 @@ class SecretManager
* Will return the Nordigen ID. From a cookie if its there, otherwise from configuration. * Will return the Nordigen ID. From a cookie if its there, otherwise from configuration.
* *
* @return string * @return string
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public static function getAppId(): string public static function getAppId(): string
{ {

2
app/Support/Http/RestoresConfiguration.php

@ -37,8 +37,6 @@ trait RestoresConfiguration
* Restore configuration from session and drive. * Restore configuration from session and drive.
* *
* @return Configuration * @return Configuration
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
protected function restoreConfiguration(): Configuration protected function restoreConfiguration(): Configuration
{ {

Loading…
Cancel
Save