Skip to content

Commit

Permalink
Console Command : Check the fiscal receipt state and adjust it.
Browse files Browse the repository at this point in the history
  • Loading branch information
arhitov committed May 9, 2024
1 parent 3f0697f commit 518caa9
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/Console/Commands/FiscalReceiptCheckStateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Billing module for laravel projects
*
* @link https://github.com/arhitov/laravel-billing
* @package arhitov/laravel-billing
* @license MIT
* @copyright Copyright (c) 2024, Alexander Arhitov, clgsru@gmail.com
*/

namespace Arhitov\LaravelBilling\Console\Commands;

use Arhitov\LaravelBilling\Services\FiscalReceipt\FiscalReceiptCheckState;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

#[\Symfony\Component\Console\Attribute\AsCommand(name: 'billing:fiscal-receipt-check-state')]
class FiscalReceiptCheckStateCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'billing:fiscal-receipt-check-state {--operation_uuid=} {--gateway=}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Check the fiscal receipt state and adjust it.';

/**
* @return int
* @throws \Illuminate\Validation\ValidationException
*/
public function handle(): int
{
$input = Validator::make(
$this->options(),
[
'operation_uuid' => ['nullable', 'string'],
'gateway' => ['nullable', 'string', Rule::in(array_keys(config('billing.omnireceipt_gateway.gateways')))],
],
)->validate();

$gatewayName = $input['gateway'] ?? config('billing.omnireceipt_gateway.default');
$operationUuid = $input['operation_uuid'] ?? null;

$service = new FiscalReceiptCheckState(
$gatewayName
);
if ($operationUuid) {
$service->useOperationUuid($operationUuid);
}

$service->execute();

return self::SUCCESS;
}
}

0 comments on commit 518caa9

Please sign in to comment.