feat: botón Reintentar cuando el correo de pago aún no llega
- sin_coincidencia muestra mensaje explicativo + botón Reintentar - datosPago guardado en estado para reintentar sin reenviar foto - pay_retry callback: re-corre validación con datos guardados - Si confirma: limpia pendiente y muestra botón aplicar recarga - Si sigue sin llegar: mantiene botón Reintentar disponible Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2972891974
commit
d408674e03
@@ -149,6 +149,7 @@ class TelegramBotService
|
|||||||
'profile' => $this->showProfile($chatId),
|
'profile' => $this->showProfile($chatId),
|
||||||
'agent' => $this->showMainMenu($chatId),
|
'agent' => $this->showMainMenu($chatId),
|
||||||
'pay_apply' => $this->applyPayment($chatId, (int) ($parts[1] ?? 0), $parts[2] ?? null),
|
'pay_apply' => $this->applyPayment($chatId, (int) ($parts[1] ?? 0), $parts[2] ?? null),
|
||||||
|
'pay_retry' => $this->retryPayment($chatId),
|
||||||
default => $this->showMainMenu($chatId),
|
default => $this->showMainMenu($chatId),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -230,19 +231,31 @@ class TelegramBotService
|
|||||||
[['text' => '🔙 Menú principal', 'callback_data' => 'menu']],
|
[['text' => '🔙 Menú principal', 'callback_data' => 'menu']],
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$motivo = match ($resultado['motivo'] ?? '') {
|
$motivo = $resultado['motivo'] ?? '';
|
||||||
|
if ($motivo === 'sin_coincidencia' || $motivo === 'sin_correos') {
|
||||||
|
// Guardar datosPago en estado para poder reintentar sin reenviar foto
|
||||||
|
$state['data']['pago_pendiente'] = $datosPago;
|
||||||
|
$this->setState($chatId, $state);
|
||||||
|
|
||||||
|
$texto .= "\nEstado: *⏳ Por ahora no encontramos tu pago de confirmación*\n"
|
||||||
|
. "_Puede demorar entre 1 y 2 minutos en llegar. Espera un momento y presiona Reintentar._";
|
||||||
|
$buttons = [
|
||||||
|
[['text' => '🔄 Reintentar', 'callback_data' => 'pay_retry']],
|
||||||
|
[['text' => '🔙 Menú principal', 'callback_data' => 'menu']],
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$motivoTexto = match ($motivo) {
|
||||||
'correo_deshabilitado' => '📧 Verificación por correo no configurada',
|
'correo_deshabilitado' => '📧 Verificación por correo no configurada',
|
||||||
'error_imap' => '📧 Error al leer correos IMAP',
|
'error_imap' => '📧 Error al leer correos IMAP',
|
||||||
'sin_correos' => '📧 Sin correos recientes en bandeja',
|
|
||||||
'sin_coincidencia' => '📧 Ningún correo coincide con este monto/fecha',
|
|
||||||
'error_sistema' => '⚙️ Error interno, intenta de nuevo en unos minutos',
|
'error_sistema' => '⚙️ Error interno, intenta de nuevo en unos minutos',
|
||||||
default => '📧 No se pudo verificar automáticamente',
|
default => '📧 No se pudo verificar automáticamente',
|
||||||
};
|
};
|
||||||
$texto .= "\nEstado: *⚠️ No confirmado*\n_{$motivo}_";
|
$texto .= "\nEstado: *⚠️ No confirmado*\n_{$motivoTexto}_";
|
||||||
$buttons = [
|
$buttons = [
|
||||||
[['text' => '🔙 Menú principal', 'callback_data' => 'menu']],
|
[['text' => '🔙 Menú principal', 'callback_data' => 'menu']],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->sendWithKeyboard($chatId, $texto, $buttons);
|
$this->sendWithKeyboard($chatId, $texto, $buttons);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
@@ -251,6 +264,56 @@ class TelegramBotService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function retryPayment(string $chatId): void
|
||||||
|
{
|
||||||
|
$state = $this->getState($chatId);
|
||||||
|
$this->convId = $state['conv_id'] ?? null;
|
||||||
|
$datosPago = $state['data']['pago_pendiente'] ?? null;
|
||||||
|
|
||||||
|
if (! $datosPago) {
|
||||||
|
$this->send($chatId, "No hay ningún comprobante pendiente. Envía la foto de tu comprobante.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->send($chatId, "⏳ Verificando de nuevo...");
|
||||||
|
|
||||||
|
$usuarioId = $state['user_id'] ?? null;
|
||||||
|
$nombreUsuario = $usuarioId ? (User::find($usuarioId)?->name ?? '') : '';
|
||||||
|
|
||||||
|
$resultado = app(PagoValidadorService::class)->validar($datosPago, $usuarioId, $nombreUsuario, 'telegram');
|
||||||
|
$monto = number_format($datosPago['valor'] ?? 0);
|
||||||
|
$ref = $datosPago['referencia'] ?? 'N/A';
|
||||||
|
$valor = (int) ($datosPago['valor'] ?? 0);
|
||||||
|
|
||||||
|
if ($resultado['estado'] === 'confirmado') {
|
||||||
|
$buttons = [
|
||||||
|
[['text' => "✅ Aplicar recarga de \$$monto", 'callback_data' => 'pay_apply|' . $valor . '|' . $ref]],
|
||||||
|
[['text' => '🔙 Menú principal', 'callback_data' => 'menu']],
|
||||||
|
];
|
||||||
|
// Limpiar pago pendiente del estado
|
||||||
|
unset($state['data']['pago_pendiente']);
|
||||||
|
$this->setState($chatId, $state);
|
||||||
|
$this->sendWithKeyboard($chatId, "✅ *¡Pago confirmado!* Tu recarga de \$$monto está lista.", $buttons);
|
||||||
|
|
||||||
|
} elseif ($resultado['estado'] === 'ya_usado') {
|
||||||
|
unset($state['data']['pago_pendiente']);
|
||||||
|
$this->setState($chatId, $state);
|
||||||
|
$this->sendWithKeyboard($chatId, "⛔ *Comprobante ya utilizado.*\nEste pago ya fue registrado anteriormente.", [
|
||||||
|
[['text' => '🔙 Menú principal', 'callback_data' => 'menu']],
|
||||||
|
]);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Sigue sin encontrarse — dejar pendiente para otro reintento
|
||||||
|
$this->sendWithKeyboard($chatId,
|
||||||
|
"⏳ *Aún no encontramos tu pago.*\nPuede demorar entre 1 y 2 minutos en llegar. Espera un momento y presiona Reintentar.",
|
||||||
|
[
|
||||||
|
[['text' => '🔄 Reintentar', 'callback_data' => 'pay_retry']],
|
||||||
|
[['text' => '🔙 Menú principal', 'callback_data' => 'menu']],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function handleVoice(string $chatId, string $fileId, string $nombre = '', int $duracionSegundos = 0): void
|
public function handleVoice(string $chatId, string $fileId, string $nombre = '', int $duracionSegundos = 0): void
|
||||||
{
|
{
|
||||||
$state = $this->getState($chatId);
|
$state = $this->getState($chatId);
|
||||||
|
|||||||
Reference in New Issue
Block a user