mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
use repo and sdk for routines instead of service
This commit is contained in:
parent
ae75f7228c
commit
b057908164
@ -8,7 +8,6 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use QuickBooksOnline\API\DataService\DataService;
|
||||
use App\Services\Import\Quickbooks\Auth as QuickbooksService;
|
||||
use App\Services\Import\Quickbooks\Repositories\CompanyTokensRepository;
|
||||
|
||||
|
||||
@ -22,8 +21,8 @@ class QuickbooksSDKFactory
|
||||
{
|
||||
$company = $user->company();
|
||||
|
||||
$tokens = (new CompanyTokensRepository($company->company_key));
|
||||
$tokens = array_filter($tokens->get());
|
||||
$token_store = (new CompanyTokensRepository($company->company_key));
|
||||
$tokens = array_filter($token_store->get());
|
||||
if(!empty($tokens)) {
|
||||
$keys = ['refreshTokenKey','QBORealmID'];
|
||||
if(array_key_exists('access_token', $tokens)) {
|
||||
@ -47,9 +46,16 @@ class QuickbooksSDKFactory
|
||||
$sdk->throwExceptionOnError(true);
|
||||
if(array_key_exists('refreshTokenKey', $config) && !array_key_exists('accessTokenKey', $config))
|
||||
{
|
||||
$auth = new QuickbooksService($sdk);
|
||||
$tokens = $auth->refreshTokens();
|
||||
$auth->saveTokens($tokens);
|
||||
$tokens = ($sdk->getOAuth2LoginHelper())->refreshToken();
|
||||
$sdk = $sdk->updateOAuth2Token($tokens);
|
||||
$tokens = ($sdk->getOAuth2LoginHelper())->getAccessToken();
|
||||
$access_token = $tokens->getAccessToken();
|
||||
$realm = $tokens->getRealmID();
|
||||
$refresh_token = $tokens->getRefreshToken();
|
||||
$access_token_expires = $tokens->getAccessTokenExpiresAt();
|
||||
$refresh_token_expires = $tokens->getRefreshTokenExpiresAt();
|
||||
$tokens = compact('access_token', 'refresh_token','access_token_expires', 'refresh_token_expires','realm');
|
||||
$token_store->save($tokens);
|
||||
}
|
||||
|
||||
return $sdk;
|
||||
|
Loading…
Reference in New Issue
Block a user