Customer account sync with Intuit
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Leenooks\Traits\ScopeActive;
|
||||
|
||||
use App\Interfaces\IDs;
|
||||
use App\Traits\SiteID;
|
||||
|
||||
/**
|
||||
* Class Account
|
||||
@@ -22,6 +23,7 @@ use App\Interfaces\IDs;
|
||||
*/
|
||||
class Account extends Model implements IDs
|
||||
{
|
||||
use SiteID;
|
||||
use HasFactory,ScopeActive;
|
||||
|
||||
/* INTERFACES */
|
||||
@@ -43,6 +45,13 @@ class Account extends Model implements IDs
|
||||
return $this->hasMany(Charge::class);
|
||||
}
|
||||
|
||||
public function providers()
|
||||
{
|
||||
return $this->belongsToMany(ProviderOauth::class,'account_provider')
|
||||
->where('account_provider.site_id',$this->site_id)
|
||||
->withPivot('ref','synctoken','created_at','updated_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the country the user belongs to
|
||||
*/
|
||||
|
@@ -4,14 +4,25 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Traits\SiteID;
|
||||
|
||||
class ProviderOauth extends Model
|
||||
{
|
||||
use SiteID;
|
||||
|
||||
protected $table = 'provider_oauth';
|
||||
|
||||
protected $fillable = ['name','active'];
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function accounts()
|
||||
{
|
||||
return $this->belongsToMany(Account::class,'account_provider')
|
||||
->where('account_provider.site_id',$this->site_id)
|
||||
->withPivot('ref','synctoken','created_at','updated_at');
|
||||
}
|
||||
|
||||
public function tokens()
|
||||
{
|
||||
return $this->hasMany(ProviderToken::class);
|
||||
@@ -21,4 +32,26 @@ class ProviderOauth extends Model
|
||||
{
|
||||
return $this->hasMany(UserOauth::class);
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
public function api_class(): ?string
|
||||
{
|
||||
return config('services.provider.'.strtolower($this->name).'.api');
|
||||
}
|
||||
|
||||
public function API(ProviderToken $o,bool $tryprod=FALSE): mixed
|
||||
{
|
||||
return ($this->api_class() && $o->access_token) ? new ($this->api_class())($o,$tryprod) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do we have API details for this supplier
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAPIdetails(): bool
|
||||
{
|
||||
return $this->api_class() && $this->access_token && (! $this->hasAccessTokenExpired());
|
||||
}
|
||||
}
|
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Intuit\Models\ProviderToken as ProviderTokenBase;
|
||||
|
||||
use App\Traits\SiteID;
|
||||
|
||||
class ProviderToken extends Model
|
||||
class ProviderToken extends ProviderTokenBase
|
||||
{
|
||||
use SiteID;
|
||||
|
||||
|
Reference in New Issue
Block a user