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

48 lines
1005 B
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 Illuminate\Console\Command;
use App\Models\{ProviderOauth,User};
2023-05-13 11:20:56 +00:00
use App\Jobs\AccountingPaymentSync as Job;
class PaymentSync 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:sync'
.' {user? : User Email}';
2023-05-13 11:20:56 +00:00
/**
* The console command description.
*
* @var string
*/
protected $description = 'Synchronise payments with accounting system';
/**
* 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));
$api = $to->API();
foreach ($api->getPayments() as $acc)
Job::dispatchSync($to,$acc);
return self::SUCCESS;
2023-05-13 11:20:56 +00:00
}
}