From 2501ca17c9550f33e5d2bd10e48caf7324e12daa Mon Sep 17 00:00:00 2001 From: Dave Shoreman Date: Thu, 19 Dec 2024 14:44:26 +0000 Subject: [PATCH] Allow setting number of days of transactions If e.g. `&tx_days=365` is added to the URL, this will use it to set the amount of history that's fetched from Nordigen on sync, with basic safeguards to prevent it being set too low or above the bank's max. --- app/Helpers/Bank/Nordigen/Nordigen.php | 14 +++++++++++--- app/Http/Controllers/Bank/NordigenController.php | 8 +++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/Helpers/Bank/Nordigen/Nordigen.php b/app/Helpers/Bank/Nordigen/Nordigen.php index 5d541d7bc8..dc4964fb16 100644 --- a/app/Helpers/Bank/Nordigen/Nordigen.php +++ b/app/Helpers/Bank/Nordigen/Nordigen.php @@ -61,14 +61,22 @@ class Nordigen } // requisition-section - public function createRequisition(string $redirect, array $institution, string $reference, string $userLanguage) - { + public function createRequisition( + string $redirect, + array $institution, + int $transactionDays, + string $reference, + string $userLanguage, + ): array { if ($this->test_mode && $institution['id'] != $this->sandbox_institutionId) { throw new \Exception('invalid institutionId while in test-mode'); } + $txDays = $transactionDays < 30 ? 30 : $transactionDays; + $max = $institution['transaction_total_days']; + $eua = $this->client->endUserAgreement->createEndUserAgreement( - maxHistoricalDays: $institution['transaction_total_days'], + maxHistoricalDays: $txDays > $max ? $max : $txDays, institutionId: $institution['id'], ); diff --git a/app/Http/Controllers/Bank/NordigenController.php b/app/Http/Controllers/Bank/NordigenController.php index f656e3503e..5fe366e97e 100644 --- a/app/Http/Controllers/Bank/NordigenController.php +++ b/app/Http/Controllers/Bank/NordigenController.php @@ -98,7 +98,13 @@ class NordigenController extends BaseController // redirect to requisition flow try { - $requisition = $nordigen->createRequisition(config('ninja.app_url') . '/nordigen/confirm', $institution, $request->token, $lang); + $requisition = $nordigen->createRequisition( + config('ninja.app_url') . '/nordigen/confirm', + $institution, + (int) ($data['tx_days'] ?? 0), + $request->token, + $lang, + ); } catch (NordigenException $e) { // TODO: property_exists returns null in these cases... => why => therefore we just get unknown error everytime $responseBody is typeof GuzzleHttp\Psr7\Stream $responseBody = (string) $e->getResponse()->getBody();