From 0f0c5a7de8d4034a90cf10d614eb1e2264444113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 3 Jun 2024 20:01:01 +0200 Subject: [PATCH] gocardless oauth connection --- .../Gateways/GoCardlessOAuthController.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 app/Http/Controllers/Gateways/GoCardlessOAuthController.php diff --git a/app/Http/Controllers/Gateways/GoCardlessOAuthController.php b/app/Http/Controllers/Gateways/GoCardlessOAuthController.php new file mode 100644 index 000000000000..1dd1c094920a --- /dev/null +++ b/app/Http/Controllers/Gateways/GoCardlessOAuthController.php @@ -0,0 +1,54 @@ + config('services.gocardless.client_id'), + 'redirect_uri' => route('gocardless.oauth.confirm', ['token' => $request->getCompany()->company_key]), + 'scope' => 'read_write', + 'response_type' => 'code', + 'prefill[email]' => 'ben@invoiceninja.com', + 'prefill[given_name]' => 'Ben', + 'prefill[family_name]' => 'The Ninja', + 'prefill[organisation_name]' => 'Fishing Store', + 'prefill[country_code]' => 'GB', + ]; + + return redirect()->to( + sprintf('https://connect-sandbox.gocardless.com/oauth/authorize?%s', http_build_query($params)) + ); + } + + public function confirm(OAuthConnectRequest $request): \Illuminate\Foundation\Application|\Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse|\Illuminate\Contracts\Foundation\Application + { + $code = $request->query('code'); + + $response = Http::post('https://connect-sandbox.gocardless.com/oauth/access_token', [ + 'client_id' => config('services.gocardless.client_id'), + 'client_secret' => config('services.gocardless.client_secret'), + 'grant_type' => 'authorization_code', + 'code' => $code, + ]); + + dd($response->body()); + } +}