feat(telepagos): enhance webhook handling and add TenantTransactionResetService
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Auth\Services\AdminCredentialVerifier;
|
||||
use App\Domains\Catalog\Services\ExpireStockReservationsService;
|
||||
use App\Domains\Purchase\Services\TenantTransactionResetService;
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Schedule;
|
||||
@@ -19,3 +21,64 @@ Artisan::command('reservations:expire', function (): void {
|
||||
Schedule::command('reservations:expire')
|
||||
->everyMinute()
|
||||
->withoutOverlapping();
|
||||
|
||||
Artisan::command(
|
||||
'tenants:reset-transactions
|
||||
{tenant : Código del tenant que se limpiará}
|
||||
{--dry-run : Mostrar el alcance sin modificar datos}
|
||||
{--force : Omitir la confirmación interactiva}',
|
||||
function (
|
||||
TenantTransactionResetService $resetService,
|
||||
AdminCredentialVerifier $adminCredentialVerifier,
|
||||
): int {
|
||||
$tenantCode = (string) $this->argument('tenant');
|
||||
|
||||
try {
|
||||
$preview = $resetService->preview($tenantCode);
|
||||
} catch (InvalidArgumentException $exception) {
|
||||
$this->error($exception->getMessage());
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->warn("Se eliminarán los datos transaccionales de: {$tenantCode}");
|
||||
$this->table(
|
||||
['Dato', 'Cantidad'],
|
||||
collect($preview)->map(fn (int $count, string $label): array => [$label, $count])->values(),
|
||||
);
|
||||
$this->info('Los usuarios, el catálogo, los eventos y la configuración se conservarán.');
|
||||
|
||||
if ($this->option('dry-run')) {
|
||||
$this->comment('Vista previa finalizada; no se modificaron datos.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
if (! $this->option('force') && ! $this->confirm('¿Confirmás esta limpieza irreversible?')) {
|
||||
$this->comment('Operación cancelada.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
$this->warn('Autorización administrativa requerida.');
|
||||
$adminEmail = (string) $this->ask('Email del administrador');
|
||||
$adminPassword = (string) $this->secret('Contraseña del administrador');
|
||||
|
||||
if (! $adminCredentialVerifier->verify($adminEmail, $adminPassword)) {
|
||||
$this->error('Las credenciales no son válidas o el usuario no posee el rol admin.');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$summary = $resetService->reset($tenantCode);
|
||||
|
||||
$this->info('Limpieza completada correctamente.');
|
||||
$this->table(
|
||||
['Resultado', 'Cantidad'],
|
||||
collect($summary)->map(fn (int $count, string $label): array => [$label, $count])->values(),
|
||||
);
|
||||
|
||||
return self::SUCCESS;
|
||||
},
|
||||
)->purpose('Delete tenant sales, carts, tickets and reservations while preserving users and catalog');
|
||||
|
||||
Reference in New Issue
Block a user