separate auth logic from entity logic

This commit is contained in:
karneaud 2024-08-01 22:33:44 -04:00
parent af47d5d8e4
commit b3ab9e468c
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,37 @@
<?php
namespace App\Services\Import\Quickbooks;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use App\Services\Import\QuickBooks\Contracts\SDKInterface as QuickbooksInterface;
final class Auth
{
private QuickbooksInterface $sdk;
public function __construct(QuickbooksInterface $quickbooks) {
$this->sdk = $quickbooks;
}
public function accessToken(string $code, string $realm ) : array
{
// TODO: Get or put token in Cache or DB?
return $this->sdk->accessToken($code, $realm);
}
public function refreshToken() : array
{
// TODO: Get or put token in Cache or DB?
return $this->sdk->refreshToken();
}
public function getAuthorizationUrl(): string
{
return $this->sdk->getAuthorizationUrl();
}
public function getState() : string
{
return $this->sdk->getState();
}
}

View File

@ -3,6 +3,7 @@ namespace App\Services\Import\Quickbooks;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use App\Services\Import\Quickbooks\Auth;
use App\Repositories\Import\Quickbooks\Contracts\RepositoryInterface;
use App\Services\Import\QuickBooks\Contracts\SdkInterface as QuickbooksInterface;
@ -14,6 +15,11 @@ final class Service
$this->sdk = $quickbooks;
}
public function getOAuth() : Auth
{
return new Auth($this->sdk);
}
public function getAccessToken() : array
{
// TODO: Cache token and