From bab1f452346c145bf3d92a33ca922aceb011c1e7 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 12 Aug 2024 20:58:35 +1000 Subject: [PATCH] Moved some basic intuit commands to leenooks/intuit --- app/Console/Commands/Intuit/AccountGet.php | 56 -------------------- app/Console/Commands/Intuit/InvoiceGet.php | 56 -------------------- app/Console/Commands/Intuit/ItemList.php | 32 +++++------- app/Console/Commands/Intuit/PaymentGet.php | 61 ---------------------- app/Traits/ProviderRef.php | 4 +- composer.json | 2 +- composer.lock | 32 ++++++------ 7 files changed, 32 insertions(+), 211 deletions(-) delete mode 100644 app/Console/Commands/Intuit/AccountGet.php delete mode 100644 app/Console/Commands/Intuit/InvoiceGet.php delete mode 100644 app/Console/Commands/Intuit/PaymentGet.php diff --git a/app/Console/Commands/Intuit/AccountGet.php b/app/Console/Commands/Intuit/AccountGet.php deleted file mode 100644 index f7cfc61..0000000 --- a/app/Console/Commands/Intuit/AccountGet.php +++ /dev/null @@ -1,56 +0,0 @@ -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)); - - try { - $api = $to->API(); - dump($api->getAccountQuery($this->argument('id'))); - - } catch (ConnectException|ConnectionIssueException $e) { - $this->error($e->getMessage()); - - return self::FAILURE; - } - - return self::SUCCESS; - } -} \ No newline at end of file diff --git a/app/Console/Commands/Intuit/InvoiceGet.php b/app/Console/Commands/Intuit/InvoiceGet.php deleted file mode 100644 index 1e1862c..0000000 --- a/app/Console/Commands/Intuit/InvoiceGet.php +++ /dev/null @@ -1,56 +0,0 @@ -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)); - - try { - $api = $to->API(); - dump($api->getInvoiceQuery($this->argument('id'))); - - } catch (ConnectException|ConnectionIssueException $e) { - $this->error($e->getMessage()); - - return self::FAILURE; - } - - return self::SUCCESS; - } -} \ No newline at end of file diff --git a/app/Console/Commands/Intuit/ItemList.php b/app/Console/Commands/Intuit/ItemList.php index 8444519..c628a37 100644 --- a/app/Console/Commands/Intuit/ItemList.php +++ b/app/Console/Commands/Intuit/ItemList.php @@ -3,13 +3,17 @@ namespace App\Console\Commands\Intuit; use Illuminate\Console\Command; +use Intuit\Exceptions\NotTokenException; +use Intuit\Traits\ProviderTokenTrait; -use App\Models\{Product,ProviderOauth,User}; -use App\Jobs\AccountingItemSync as Job; +use App\Models\Product; +/** + * Return a list of products and their accounting id + */ class ItemList extends Command { - private const provider = 'intuit'; + use ProviderTokenTrait; /** * The name and signature of the console command. @@ -30,16 +34,11 @@ class ItemList 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 (($x=$so->tokens->where('user_id',$uo->id))->count() !== 1) - abort(500,sprintf('Unknown Tokens for [%s]',$uo->email)); - - $to = $x->pop(); + $to = $this->providerToken($this->argument('user')); // Current Products used by services $products = Product::select(['products.*']) @@ -48,19 +47,12 @@ class ItemList extends Command ->where('services.active',TRUE) ->get(); - $api = $so->API($to,TRUE); // @todo Remove TRUE - - $acc = $api->getItems()->pluck('pid','FullyQualifiedName'); - foreach ($products as $po) { - if (! $po->accounting) - $this->error(sprintf('Product [%d](%s) doesnt have accounting set',$po->id,$po->name)); - - elseif ($acc->has($po->accounting) === FALSE) - $this->error(sprintf('Product [%d](%s) accounting [%s] doesnt exist?',$po->id,$po->name,$po->accounting)); + if (! $x=$po->provider_ref($to->provider)) + $this->error(sprintf('Product [%03d](%s) doesnt have accounting set',$po->id,$po->name)); else - $this->info(sprintf('Product [%d](%s) set to accounting [%s]',$po->id,$po->name,$po->accounting)); + $this->info(sprintf('Product [%03d](%s) set to accounting [%s]',$po->id,$po->name,$x)); } return self::SUCCESS; diff --git a/app/Console/Commands/Intuit/PaymentGet.php b/app/Console/Commands/Intuit/PaymentGet.php deleted file mode 100644 index 0be461a..0000000 --- a/app/Console/Commands/Intuit/PaymentGet.php +++ /dev/null @@ -1,61 +0,0 @@ -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)); - - try { - $api = $to->API(); - $acc = $api->getPayment($this->argument('id')); - dump($acc); - - } catch (ConnectException|ConnectionIssueException $e) { - $this->error($e->getMessage()); - - return Command::FAILURE; - } - - if ($acc) - Job::dispatchSync($to,$acc); - - return self::SUCCESS; - } -} \ No newline at end of file diff --git a/app/Traits/ProviderRef.php b/app/Traits/ProviderRef.php index 014ab84..5855d6b 100644 --- a/app/Traits/ProviderRef.php +++ b/app/Traits/ProviderRef.php @@ -11,6 +11,8 @@ trait ProviderRef { public function provider_ref(ProviderOauth $poo): ?string { - return (($x=$this->providers->where('pivot.provider_oauth_id',$poo->id))->count() === 1) ? $x->pop()->pivot->ref : NULL; + return (($x=$this->providers->where('pivot.provider_oauth_id',$poo->id))->count() === 1) + ? $x->pop()->pivot->ref + : NULL; } } \ No newline at end of file diff --git a/composer.json b/composer.json index 207c5c8..17aa252 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "laravel/socialite": "^5.15", "laravel/ui": "^4.5", "leenooks/dreamscape": "^0.1.4", - "leenooks/intuit": "^0.1.11", + "leenooks/intuit": "^0.2", "leenooks/laravel": "^11.1", "leenooks/passkey": "^0.2", "paypal/paypal-checkout-sdk": "^1.0", diff --git a/composer.lock b/composer.lock index 44eba91..2c92f25 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "72b6dd9641c690d74fbc9885084918d3", + "content-hash": "ae477f3c8e083f7f127d92de0a070e8d", "packages": [ { "name": "barryvdh/laravel-snappy", @@ -3021,11 +3021,11 @@ }, { "name": "leenooks/intuit", - "version": "0.1.11", + "version": "0.2.0", "source": { "type": "git", "url": "https://gitea.dege.au/laravel/intuit.git", - "reference": "c9523f595b0e860ccf8d8be327ad1903fe63c686" + "reference": "0cc4a217bdeabf0ad7973d9d159c823125492174" }, "require": { "jenssegers/model": "^1.5" @@ -3055,7 +3055,7 @@ "laravel", "leenooks" ], - "time": "2024-08-11T11:05:29+00:00" + "time": "2024-08-12T10:55:41+00:00" }, { "name": "leenooks/laravel", @@ -4017,16 +4017,16 @@ }, { "name": "phpseclib/phpseclib", - "version": "3.0.39", + "version": "3.0.41", "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "211ebc399c6e73c225a018435fe5ae209d1d1485" + "reference": "621c73f7dcb310b61de34d1da4c4204e8ace6ceb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/211ebc399c6e73c225a018435fe5ae209d1d1485", - "reference": "211ebc399c6e73c225a018435fe5ae209d1d1485", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/621c73f7dcb310b61de34d1da4c4204e8ace6ceb", + "reference": "621c73f7dcb310b61de34d1da4c4204e8ace6ceb", "shasum": "" }, "require": { @@ -4107,7 +4107,7 @@ ], "support": { "issues": "https://github.com/phpseclib/phpseclib/issues", - "source": "https://github.com/phpseclib/phpseclib/tree/3.0.39" + "source": "https://github.com/phpseclib/phpseclib/tree/3.0.41" }, "funding": [ { @@ -4123,7 +4123,7 @@ "type": "tidelift" } ], - "time": "2024-06-24T06:27:33+00:00" + "time": "2024-08-12T00:13:54+00:00" }, { "name": "psr/clock", @@ -9182,16 +9182,16 @@ }, { "name": "sebastian/comparator", - "version": "6.0.1", + "version": "6.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "131942b86d3587291067a94f295498ab6ac79c20" + "reference": "450d8f237bd611c45b5acf0733ce43e6bb280f81" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/131942b86d3587291067a94f295498ab6ac79c20", - "reference": "131942b86d3587291067a94f295498ab6ac79c20", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/450d8f237bd611c45b5acf0733ce43e6bb280f81", + "reference": "450d8f237bd611c45b5acf0733ce43e6bb280f81", "shasum": "" }, "require": { @@ -9247,7 +9247,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", "security": "https://github.com/sebastianbergmann/comparator/security/policy", - "source": "https://github.com/sebastianbergmann/comparator/tree/6.0.1" + "source": "https://github.com/sebastianbergmann/comparator/tree/6.0.2" }, "funding": [ { @@ -9255,7 +9255,7 @@ "type": "github" } ], - "time": "2024-07-03T04:48:07+00:00" + "time": "2024-08-12T06:07:25+00:00" }, { "name": "sebastian/complexity",