osb/app/Console/Commands/Intuit/PaymentGet.php

61 lines
1.3 KiB
PHP
Raw Normal View History

2023-05-13 11:20:56 +00:00
<?php
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;
use App\Jobs\AccountingPaymentSync as Job;
use App\Models\{ProviderOauth,User};
2023-05-13 11:20:56 +00:00
class PaymentGet extends Command
2023-05-13 11:20:56 +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'
.' {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()
{
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
2023-05-13 11:20:56 +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();
$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;
}
if ($acc)
Job::dispatchSync($to,$acc);
return self::SUCCESS;
2023-05-13 11:20:56 +00:00
}
}