2023-05-13 11:20:56 +00:00
|
|
|
<?php
|
|
|
|
|
2024-07-14 03:49:00 +00:00
|
|
|
namespace App\Console\Commands\Intuit;
|
2023-05-13 11:20:56 +00:00
|
|
|
|
|
|
|
use GuzzleHttp\Exception\ConnectException;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Intuit\Exceptions\ConnectionIssueException;
|
|
|
|
|
2023-05-13 12:01:43 +00:00
|
|
|
use App\Jobs\AccountingPaymentSync as Job;
|
2024-07-14 03:49:00 +00:00
|
|
|
use App\Models\{ProviderOauth,User};
|
2023-05-13 11:20:56 +00:00
|
|
|
|
2024-07-14 03:49:00 +00:00
|
|
|
class PaymentGet extends Command
|
2023-05-13 11:20:56 +00:00
|
|
|
{
|
2024-07-14 03:49:00 +00:00
|
|
|
private const provider = 'intuit';
|
|
|
|
|
2023-05-13 11:20:56 +00:00
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'accounting:payment:get'
|
2024-07-14 03:49:00 +00:00
|
|
|
.' {id : Payment ID}'
|
|
|
|
.' {user? : User Email}';
|
2023-05-13 11:20:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Get a payment from the accounting provider';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2024-07-14 03:49:00 +00:00
|
|
|
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
|
2023-05-13 11:20:56 +00:00
|
|
|
|
2024-07-14 03:49:00 +00:00
|
|
|
$so = ProviderOauth::where('name',self::provider)->singleOrFail();
|
2023-05-13 11:20:56 +00:00
|
|
|
if (! ($to=$so->token($uo)))
|
|
|
|
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
|
|
|
|
|
|
|
|
try {
|
|
|
|
$api = $to->API();
|
2023-05-13 12:01:43 +00:00
|
|
|
$acc = $api->getPayment($this->argument('id'));
|
|
|
|
dump($acc);
|
2023-05-13 11:20:56 +00:00
|
|
|
|
|
|
|
} catch (ConnectException|ConnectionIssueException $e) {
|
|
|
|
$this->error($e->getMessage());
|
|
|
|
|
|
|
|
return Command::FAILURE;
|
|
|
|
}
|
2023-05-13 12:01:43 +00:00
|
|
|
|
|
|
|
if ($acc)
|
|
|
|
Job::dispatchSync($to,$acc);
|
2024-07-14 03:49:00 +00:00
|
|
|
|
|
|
|
return self::SUCCESS;
|
2023-05-13 11:20:56 +00:00
|
|
|
}
|
|
|
|
}
|