feat: custom recharge amount in web chat and Telegram

- Web chat: 'Otro valor' button sets flujo=recarga.monto_custom,
  next text message is parsed as the amount (min $1.000)
- Telegram: '✏️ Otro valor' button sets step=await_amount,
  next message is parsed and routed to method selection
- Preset amounts in Telegram now show 2 per row for compactness

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro
2026-07-14 12:57:36 +00:00
co-authored by Claude Sonnet 4.6
parent 2fc2aba8a3
commit a5bac9cee7
2 changed files with 72 additions and 12 deletions
+47 -11
View File
@@ -71,12 +71,13 @@ class TelegramBotService
$step = $state['step'] ?? 'await_email';
match ($step) {
'await_email' => $this->processEmail($chatId, $text, $nombre),
'await_otp' => $this->processOtp($chatId, $text),
'await_nombre' => $this->processNombre($chatId, $text),
'await_cedula' => $this->processCedula($chatId, $text),
'await_celular'=> $this->processCelular($chatId, $text),
default => $this->handleFreeText($chatId, $state),
'await_email' => $this->processEmail($chatId, $text, $nombre),
'await_otp' => $this->processOtp($chatId, $text),
'await_nombre' => $this->processNombre($chatId, $text),
'await_cedula' => $this->processCedula($chatId, $text),
'await_celular' => $this->processCelular($chatId, $text),
'await_amount' => $this->processCustomAmount($chatId, $text),
default => $this->handleFreeText($chatId, $state),
};
}
@@ -107,6 +108,7 @@ class TelegramBotService
'promo_saldo' => $this->buyPromoSaldo($chatId, (int) ($parts[1] ?? 0)),
'promo_mp' => $this->buyPromoMP($chatId, (int) ($parts[1] ?? 0)),
'rec_init' => $this->showRechargeAmounts($chatId),
'rec_custom' => $this->askCustomAmount($chatId),
'rec_amount' => $this->chooseRechargeMethod($chatId, (int) ($parts[1] ?? 0)),
'rec_mp' => $this->rechargeMP($chatId, (int) ($parts[1] ?? 0)),
'rec_breb' => $this->rechargeBreb($chatId, (int) ($parts[1] ?? 0)),
@@ -729,15 +731,49 @@ class TelegramBotService
private function showRechargeAmounts(string $chatId): void
{
$buttons = [];
foreach ([20000, 50000, 100000, 200000, 500000] as $m) {
$buttons[] = [['text' => '$' . number_format($m), 'callback_data' => 'rec_amount|' . $m]];
}
$buttons[] = [['text' => '🔙 Menú principal', 'callback_data' => 'menu']];
$buttons = [
[
['text' => '$20.000', 'callback_data' => 'rec_amount|20000'],
['text' => '$50.000', 'callback_data' => 'rec_amount|50000'],
],
[
['text' => '$100.000', 'callback_data' => 'rec_amount|100000'],
['text' => '$200.000', 'callback_data' => 'rec_amount|200000'],
],
[
['text' => '$500.000', 'callback_data' => 'rec_amount|500000'],
['text' => '✏️ Otro valor', 'callback_data' => 'rec_custom'],
],
[['text' => '🔙 Menú principal', 'callback_data' => 'menu']],
];
$this->sendWithKeyboard($chatId, "💰 *¿Cuánto quieres recargar?*", $buttons);
}
private function askCustomAmount(string $chatId): void
{
$state = $this->getState($chatId);
$state['step'] = 'await_amount';
$this->setState($chatId, $state);
$this->send($chatId, "Escribe el monto que deseas recargar (mínimo \$1.000):");
}
private function processCustomAmount(string $chatId, string $text): void
{
$monto = (int) preg_replace('/\D/', '', $text);
if ($monto < 1000) {
$this->send($chatId, "El monto debe ser al menos \$1.000. Escríbelo de nuevo:");
return;
}
$state = $this->getState($chatId);
$state['step'] = 'menu';
$this->setState($chatId, $state);
$this->chooseRechargeMethod($chatId, $monto);
}
private function chooseRechargeMethod(string $chatId, int $monto): void
{
if ($monto <= 0) {