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']], ] ); } } }