diff --git a/app/Console/Commands/Intuit/AccountAdd.php b/app/Console/Commands/Intuit/AccountAdd.php index f46043a..d19621d 100644 --- a/app/Console/Commands/Intuit/AccountAdd.php +++ b/app/Console/Commands/Intuit/AccountAdd.php @@ -3,14 +3,16 @@ namespace App\Console\Commands\Intuit; use Illuminate\Console\Command; +use Intuit\Exceptions\NotTokenException; use Intuit\Jobs\AccountingCustomerUpdate; use Intuit\Models\Customer as AccAccount; +use Intuit\Traits\ProviderTokenTrait; -use App\Models\{Account,ProviderOauth,User}; +use App\Models\Account; class AccountAdd extends Command { - private const provider = 'intuit'; + use ProviderTokenTrait; /** * The name and signature of the console command. @@ -32,15 +34,10 @@ class AccountAdd extends Command * Execute the console command. * * @return int + * @throws NotTokenException */ public function handle() { - $uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail(); - - $so = ProviderOauth::where('name',self::provider)->singleOrFail(); - if (! ($to=$so->token($uo))) - abort(500,sprintf('Unknown Tokens for [%s]',$uo->email)); - $o = Account::findOrFail($this->argument('id')); $acc = new AccAccount; @@ -53,6 +50,9 @@ class AccountAdd extends Command $acc->FullyQualifiedName = $o->name; $acc->Active = (bool)$o->active; - return AccountingCustomerUpdate::dispatchSync($to,$acc); + return AccountingCustomerUpdate::dispatchSync( + $this->providerToken($this->argument('user')), + $acc + ); } } \ No newline at end of file diff --git a/app/Console/Commands/Intuit/AccountSync.php b/app/Console/Commands/Intuit/AccountSync.php index 0223655..ad5e3d4 100644 --- a/app/Console/Commands/Intuit/AccountSync.php +++ b/app/Console/Commands/Intuit/AccountSync.php @@ -3,16 +3,17 @@ namespace App\Console\Commands\Intuit; use Illuminate\Console\Command; +use Intuit\Exceptions\NotTokenException; +use Intuit\Traits\ProviderTokenTrait; -use App\Models\{ProviderOauth,User}; -use App\Jobs\AccountingAccountSync as Job; +use App\Jobs\AccountingAccountSync; /** * Synchronise Customers with Accounts */ class AccountSync extends Command { - private const provider = 'intuit'; + use ProviderTokenTrait; /** * The name and signature of the console command. @@ -33,16 +34,11 @@ class AccountSync extends Command * Execute the console command. * * @return int + * @throws NotTokenException */ public function handle() { - $uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail(); - - $so = ProviderOauth::where('name',self::provider)->singleOrFail(); - if (! ($to=$so->token($uo))) - abort(500,sprintf('Unknown Tokens for [%s]',$uo->email)); - - Job::dispatchSync($to); + AccountingAccountSync::dispatchSync($this->providerToken($this->argument('user'))); return self::SUCCESS; }