diff --git a/app/Http/Controllers/Bank/NordigenController.php b/app/Http/Controllers/Bank/NordigenController.php index a990b9a8d9..f7f5f8e56d 100644 --- a/app/Http/Controllers/Bank/NordigenController.php +++ b/app/Http/Controllers/Bank/NordigenController.php @@ -135,9 +135,9 @@ class NordigenController extends BaseController public function confirm(ConfirmNordigenBankIntegrationRequest $request) { $data = $request->all(); + $context = $request->getTokenContent(); $lang = $data['lang'] ?? 'en'; - $context = Cache::get($data["ref"]); if (!$context || $context["context"] != "nordigen" || !array_key_exists("requisitionId", $context)) return view('bank.nordigen.handler', [ 'lang' => $lang, @@ -145,7 +145,7 @@ class NordigenController extends BaseController "redirectUrl" => ($context && array_key_exists("redirect", $context) ? $context["redirect"] : config('ninja.app_url')) . "?action=nordigen_connect&status=failed&reason=ref-invalid", ]); - $company = Company::where('company_key', $context["company_key"])->firstOrFail(); + $company = $request->getCompany(); $account = $company->account; if (!(config('ninja.nordigen.secret_id') && config('ninja.nordigen.secret_key'))) diff --git a/app/Http/Requests/Nordigen/ConfirmNordigenBankIntegrationRequest.php b/app/Http/Requests/Nordigen/ConfirmNordigenBankIntegrationRequest.php index a529b46ed1..12c8126696 100644 --- a/app/Http/Requests/Nordigen/ConfirmNordigenBankIntegrationRequest.php +++ b/app/Http/Requests/Nordigen/ConfirmNordigenBankIntegrationRequest.php @@ -12,6 +12,9 @@ namespace App\Http\Requests\Nordigen; use App\Http\Requests\Request; +use App\Libraries\MultiDB; +use App\Models\Company; +use Cache; class ConfirmNordigenBankIntegrationRequest extends Request { @@ -37,4 +40,21 @@ class ConfirmNordigenBankIntegrationRequest extends Request 'lang' => 'string', ]; } + public function getTokenContent() + { + if ($this->state) { + $this->token = $this->state; + } + + $data = Cache::get($this->token); + + return $data; + } + + public function getCompany() + { + MultiDB::findAndSetDbByCompanyKey($this->getTokenContent()['company_key']); + + return Company::where('company_key', $this->getTokenContent()['company_key'])->firstOrFail(); + } } diff --git a/app/Http/Requests/Nordigen/ConnectNordigenBankIntegrationRequest.php b/app/Http/Requests/Nordigen/ConnectNordigenBankIntegrationRequest.php index b3c0ebf89b..bcf87a93b9 100644 --- a/app/Http/Requests/Nordigen/ConnectNordigenBankIntegrationRequest.php +++ b/app/Http/Requests/Nordigen/ConnectNordigenBankIntegrationRequest.php @@ -40,7 +40,7 @@ class ConnectNordigenBankIntegrationRequest extends Request return [ 'lang' => 'string', 'institution_id' => 'string', - 'redirect' => 'string', // TODO: @turbo124 @todo validate, that this is a url without / at the end + 'redirect' => 'string', ]; } @@ -52,7 +52,7 @@ class ConnectNordigenBankIntegrationRequest extends Request if (!array_key_exists('redirect', $input)) { $context = $this->getTokenContent(); - $input["redirect"] = isset($context['is_react']) && $context['is_react'] ? config('ninja.react_url') : config('ninja.app_url'); + $input["redirect"] = isset($context["is_react"]) && $context['is_react'] ? redirect(config('ninja.react_url') . "/#/settings/bank_accounts") : redirect(config('ninja.app_url')); $this->replace($input); } @@ -68,13 +68,6 @@ class ConnectNordigenBankIntegrationRequest extends Request return $data; } - public function getContact() - { - MultiDB::findAndSetDbByCompanyKey($this->getTokenContent()['company_key']); - - return User::findOrFail($this->getTokenContent()['user_id']); - } - public function getCompany() { MultiDB::findAndSetDbByCompanyKey($this->getTokenContent()['company_key']); diff --git a/resources/views/bank/nordigen/handler.blade.php b/resources/views/bank/nordigen/handler.blade.php index 6795d4344b..309a401e72 100644 --- a/resources/views/bank/nordigen/handler.blade.php +++ b/resources/views/bank/nordigen/handler.blade.php @@ -18,8 +18,6 @@