1. Reintentos automáticos (Telegram Job): usa autoAplicarRecarga para ejecutar la compra pendiente automáticamente al confirmar el pago, sin botón extra. 2. Pagar servicio directo con Bre-B sin recargar saldo previamente (ambos canales): botón 'Pagar con Bre-B directo' en el flujo de compra con saldo insuficiente. 3. Mensaje de gracias + bloque de credenciales fácil de copiar al entregar servicio: Telegram usa bloque de código (tiene botón Copy nativo), Chat Web muestra el texto completo de gracias con copia por campo y botón 'Copiar todo'. 4. Botón copiar llave Bre-B: ya existía en Chat Web, confirmado sin cambio. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
88 lines
3.0 KiB
PHP
88 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\SolicitudRecarga;
|
|
use App\Models\User;
|
|
use App\Services\PagoValidadorService;
|
|
use App\Services\TelegramBotService;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ValidarPagoTelegramJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public int $tries = 1;
|
|
public int $timeout = 60;
|
|
|
|
private const MAX_INTENTOS = 9;
|
|
private const STATE_TTL = 315360000;
|
|
|
|
public function __construct(
|
|
private string $chatId,
|
|
private array $datosPago,
|
|
private int $intento = 1
|
|
) {}
|
|
|
|
public function handle(): void
|
|
{
|
|
$cacheKey = "tgbot_state_{$this->chatId}";
|
|
$state = Cache::get($cacheKey, []);
|
|
$usuarioId = $state['user_id'] ?? null;
|
|
$bot = new TelegramBotService();
|
|
|
|
if (! $usuarioId) {
|
|
return;
|
|
}
|
|
|
|
$solicitud = SolicitudRecarga::pendiente($usuarioId);
|
|
if (! $solicitud) {
|
|
Log::info("[ValidarPagoTelegramJob] chatId={$this->chatId}: solicitud ya no está pendiente, abortando.");
|
|
return;
|
|
}
|
|
|
|
$nombreUsuario = $state['data']['nombre_remitente'] ?? null;
|
|
|
|
$resultado = app(PagoValidadorService::class)->validar(
|
|
$this->datosPago, $usuarioId, $nombreUsuario, 'telegram'
|
|
);
|
|
|
|
if ($resultado['estado'] === 'confirmado') {
|
|
$bot->autoAplicarRecarga($this->chatId, $state, $solicitud, $solicitud->monto);
|
|
return;
|
|
}
|
|
|
|
if ($resultado['estado'] === 'ya_usado') {
|
|
$bot->sendWithKeyboard($this->chatId,
|
|
"⛔ *Comprobante ya utilizado.*\nEste pago ya fue registrado anteriormente.",
|
|
[[['text' => '🔙 Menú principal', 'callback_data' => 'menu']]]
|
|
);
|
|
return;
|
|
}
|
|
|
|
// No encontrado — reintentar o agotar
|
|
if ($this->intento < self::MAX_INTENTOS) {
|
|
Log::info("[ValidarPagoTelegramJob] chatId={$this->chatId}: intento {$this->intento}/" . self::MAX_INTENTOS . " — reintentando en 20s");
|
|
self::dispatch($this->chatId, $this->datosPago, $this->intento + 1)
|
|
->delay(now()->addSeconds(20));
|
|
} else {
|
|
Log::info("[ValidarPagoTelegramJob] chatId={$this->chatId}: intentos agotados, mostrando botón manual");
|
|
$bot->sendWithKeyboard(
|
|
$this->chatId,
|
|
"⚠️ No pudimos confirmar tu pago automáticamente.\nSi ya realizaste la transferencia, presiona Reintentar.",
|
|
[
|
|
[['text' => '🔄 Reintentar', 'callback_data' => 'pay_retry']],
|
|
[['text' => '🔙 Menú principal', 'callback_data' => 'menu']],
|
|
]
|
|
);
|
|
}
|
|
}
|
|
|
|
}
|