Inuit sync of tax, product accounting, accounts and invoices
This commit is contained in:
@@ -15,10 +15,38 @@ class ProviderToken extends ProviderTokenBase
|
||||
'refresh_token_expires_at',
|
||||
];
|
||||
|
||||
protected $with = ['provider'];
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function provider()
|
||||
{
|
||||
return $this->belongsTo(ProviderOauth::class,'provider_oauth_id');
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
/**
|
||||
* Return an API object to interact with this provider
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function API(): mixed
|
||||
{
|
||||
if (! $this->provider->api_class() || ! $this->access_token)
|
||||
throw new \Exception(sprintf('No API details for [%s]',$this->provider->name));
|
||||
|
||||
return new ($this->provider->api_class())($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do we have API details for this provider
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAPIdetails(): bool
|
||||
{
|
||||
return $this->provider->api_class() && $this->access_token && (! $this->hasAccessTokenExpired());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user