From f8e06d7ca313c07caff8b2f2f8911eb01894d1c5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 21 Aug 2024 13:22:46 +1000 Subject: [PATCH] Refactor QB --- .../Quickbooks/AuthQuickbooksRequest.php | 69 ++++++++++++++++++ .../Import/Quickbooks/QuickbooksService.php | 72 +++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 app/Http/Requests/Quickbooks/AuthQuickbooksRequest.php create mode 100644 app/Services/Import/Quickbooks/QuickbooksService.php diff --git a/app/Http/Requests/Quickbooks/AuthQuickbooksRequest.php b/app/Http/Requests/Quickbooks/AuthQuickbooksRequest.php new file mode 100644 index 000000000000..9e462ce6e319 --- /dev/null +++ b/app/Http/Requests/Quickbooks/AuthQuickbooksRequest.php @@ -0,0 +1,69 @@ +getTokenContent()); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + // + ]; + } + + /** + * Resolve one-time token instance. + * + * @return mixed + */ + public function getTokenContent() + { + if ($this->state) { + $this->token = $this->state; + } + + $data = Cache::get($this->token); + + return $data; + } + + public function getContact(): ?User + { + return User::findOrFail($this->getTokenContent()['user_id']); + } + + public function getCompany(): ?Company + { + return Company::where('company_key', $this->getTokenContent()['company_key'])->firstOrFail(); + } +} diff --git a/app/Services/Import/Quickbooks/QuickbooksService.php b/app/Services/Import/Quickbooks/QuickbooksService.php new file mode 100644 index 000000000000..8832ee15713f --- /dev/null +++ b/app/Services/Import/Quickbooks/QuickbooksService.php @@ -0,0 +1,72 @@ +init() + ->auth(); + } + + private function init(): self + { + + $this->sdk = DataService::Configure([ + 'ClientID' => config('services.quickbooks.client_id'), + 'ClientSecret' => config('services.quickbooks.client_secret'), + 'auth_mode' => 'oauth2', + 'scope' => "com.intuit.quickbooks.accounting", + 'RedirectURI' => 'https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl', + // 'RedirectURI' => route('quickbooks.authorized'), + ]); + + // if (env('APP_DEBUG')) { + // $sdk->setLogLocation(storage_path("logs/quickbooks.log")); + // $sdk->enableLog(); + // } + + $this->sdk->setMinorVersion("73"); + $this->sdk->throwExceptionOnError(true); + + return $this; + } + + private function auth(): self + { + $wrapper = new SdkWrapper($this->sdk); + $this->auth = new Auth($wrapper); + + return $this; + } + + public function getSdk(): DataService + { + return $this->sdk; + } + + public function getAuth(): Auth + { + return $this->auth; + } +}