Services and promos purchasable only with balance; redirect to recharge if short
Remove MercadoPago as a direct payment option for services and promotions. If the user has enough balance: show only "Pagar con saldo". If not: show current balance, amount missing, and a "Recargar saldo" button that leads to the recharge flow (where MercadoPago and Bre-B remain available). Applies to both TelegramBotService (startPurchase, viewPromo) and PublicChat (iniciarCompra, verPromocion). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2f5be9253b
commit
b26f6f1130
@@ -648,26 +648,36 @@ class PublicChat extends Component
|
|||||||
'pantallas' => $tarifa->pantallas,
|
'pantallas' => $tarifa->pantallas,
|
||||||
];
|
];
|
||||||
|
|
||||||
$detalle = $tarifa->servicio->por_tiempo
|
$detalle = $tarifa->servicio->por_tiempo
|
||||||
? "{$tarifa->dias} dias"
|
? "{$tarifa->dias} dias"
|
||||||
: "{$tarifa->pantallas} pantalla(s) / {$tarifa->dias} dias";
|
: "{$tarifa->pantallas} pantalla(s) / {$tarifa->dias} dias";
|
||||||
$saldoInsuficiente = ! $this->userId || ((float) $this->saldoUsuario < $precio);
|
|
||||||
|
|
||||||
ChatMessage::create([
|
if ((float) $this->saldoUsuario >= $precio) {
|
||||||
'conversation_id' => $this->convId,
|
ChatMessage::create([
|
||||||
'tipo' => 'bot',
|
'conversation_id' => $this->convId,
|
||||||
'tipo_ui' => 'buttons',
|
'tipo' => 'bot',
|
||||||
'contenido' => "{$tarifa->servicio->nombre} - {$detalle}\nPrecio: $" . number_format($precio) . "\n\nElige como pagar:",
|
'tipo_ui' => 'buttons',
|
||||||
'payload' => ['botones' => [
|
'contenido' => "{$tarifa->servicio->nombre} - {$detalle}\nPrecio: $" . number_format($precio) . "\n\nElige como pagar:",
|
||||||
['label' => 'Saldo ($' . number_format($precio) . ')',
|
'payload' => ['botones' => [
|
||||||
'action' => 'compra.pagar.saldo',
|
['label' => 'Pagar con saldo ($' . number_format($precio) . ')', 'action' => 'compra.pagar.saldo', 'data' => []],
|
||||||
'data' => [],
|
['label' => 'Volver', 'action' => 'servicios.listar', 'data' => []],
|
||||||
'disabled' => $saldoInsuficiente],
|
]],
|
||||||
['label' => 'MercadoPago', 'action' => 'compra.pagar.mp', 'data' => []],
|
'leido' => true,
|
||||||
['label' => 'Volver', 'action' => 'servicios.listar', 'data' => []],
|
]);
|
||||||
]],
|
} else {
|
||||||
'leido' => true,
|
$falta = $precio - (float) $this->saldoUsuario;
|
||||||
]);
|
ChatMessage::create([
|
||||||
|
'conversation_id' => $this->convId,
|
||||||
|
'tipo' => 'bot',
|
||||||
|
'tipo_ui' => 'buttons',
|
||||||
|
'contenido' => "{$tarifa->servicio->nombre} - {$detalle}\nPrecio: $" . number_format($precio) . "\n\nSaldo actual: $" . number_format($this->saldoUsuario) . " — te faltan $" . number_format($falta) . "\n\nRecarga tu saldo para continuar:",
|
||||||
|
'payload' => ['botones' => [
|
||||||
|
['label' => 'Recargar saldo', 'action' => 'recarga.iniciar', 'data' => []],
|
||||||
|
['label' => 'Volver', 'action' => 'servicios.listar', 'data' => []],
|
||||||
|
]],
|
||||||
|
'leido' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function pagarConSaldo(): void
|
private function pagarConSaldo(): void
|
||||||
@@ -843,23 +853,32 @@ class PublicChat extends Component
|
|||||||
$tp = $promo->tarifaPromo->first();
|
$tp = $promo->tarifaPromo->first();
|
||||||
$precio = $upric ? $upric->precio : ($tp ? $tp->precio : $promo->precio);
|
$precio = $upric ? $upric->precio : ($tp ? $tp->precio : $promo->precio);
|
||||||
|
|
||||||
$saldoInsuficiente = ! $this->userId || ($this->saldoUsuario < $precio);
|
if ((float) $this->saldoUsuario >= $precio) {
|
||||||
|
ChatMessage::create([
|
||||||
ChatMessage::create([
|
'conversation_id' => $this->convId,
|
||||||
'conversation_id' => $this->convId,
|
'tipo' => 'bot',
|
||||||
'tipo' => 'bot',
|
'tipo_ui' => 'buttons',
|
||||||
'tipo_ui' => 'buttons',
|
'contenido' => ($promo->nombre ?? 'Promocion') . "\n$" . number_format($precio) . "\n\nElige como pagar:",
|
||||||
'contenido' => ($promo->nombre ?? 'Promocion') . "\n$" . number_format($precio) . "\n\nElige como pagar:",
|
'payload' => ['botones' => [
|
||||||
'payload' => ['botones' => [
|
['label' => 'Pagar con saldo ($' . number_format($precio) . ')', 'action' => 'promo.comprar.saldo', 'data' => ['id' => $id]],
|
||||||
['label' => 'Saldo ($' . number_format($precio) . ')',
|
['label' => 'Volver', 'action' => 'promo.listar', 'data' => []],
|
||||||
'action' => 'promo.comprar.saldo',
|
]],
|
||||||
'data' => ['id' => $id],
|
'leido' => true,
|
||||||
'disabled' => $saldoInsuficiente],
|
]);
|
||||||
['label' => 'MercadoPago', 'action' => 'promo.comprar.mp', 'data' => ['id' => $id]],
|
} else {
|
||||||
['label' => 'Volver', 'action' => 'promo.listar', 'data' => []],
|
$falta = $precio - (float) $this->saldoUsuario;
|
||||||
]],
|
ChatMessage::create([
|
||||||
'leido' => true,
|
'conversation_id' => $this->convId,
|
||||||
]);
|
'tipo' => 'bot',
|
||||||
|
'tipo_ui' => 'buttons',
|
||||||
|
'contenido' => ($promo->nombre ?? 'Promocion') . "\n$" . number_format($precio) . "\n\nSaldo actual: $" . number_format($this->saldoUsuario) . " — te faltan $" . number_format($falta) . "\n\nRecarga tu saldo para continuar:",
|
||||||
|
'payload' => ['botones' => [
|
||||||
|
['label' => 'Recargar saldo', 'action' => 'recarga.iniciar', 'data' => []],
|
||||||
|
['label' => 'Volver', 'action' => 'promo.listar', 'data' => []],
|
||||||
|
]],
|
||||||
|
'leido' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function comprarPromoConSaldo(int $promoId): void
|
private function comprarPromoConSaldo(int $promoId): void
|
||||||
|
|||||||
@@ -700,17 +700,27 @@ class TelegramBotService
|
|||||||
: "{$tarifa->pantallas} pantalla(s) / {$tarifa->dias} días";
|
: "{$tarifa->pantallas} pantalla(s) / {$tarifa->dias} días";
|
||||||
|
|
||||||
$buttons = [];
|
$buttons = [];
|
||||||
|
|
||||||
if ($saldo >= $valor) {
|
if ($saldo >= $valor) {
|
||||||
$buttons[] = [['text' => "💳 Pagar con saldo (\$" . number_format($valor) . ")", 'callback_data' => 'buy_saldo']];
|
$buttons[] = [['text' => "💳 Pagar con saldo (\$" . number_format($valor) . ")", 'callback_data' => 'buy_saldo']];
|
||||||
}
|
$buttons[] = [['text' => '🔙 Ver planes', 'callback_data' => 'svc_view|' . $tarifa->servicio_id]];
|
||||||
$buttons[] = [['text' => '🏦 MercadoPago', 'callback_data' => 'buy_mp']];
|
|
||||||
$buttons[] = [['text' => '🔙 Ver planes', 'callback_data' => 'svc_view|' . $tarifa->servicio_id]];
|
|
||||||
|
|
||||||
$this->sendWithKeyboard(
|
$this->sendWithKeyboard(
|
||||||
$chatId,
|
$chatId,
|
||||||
"*{$tarifa->servicio->nombre}* — {$detalle}\nPrecio: *\$" . number_format($valor) . "*\n\nElige cómo pagar:",
|
"*{$tarifa->servicio->nombre}* — {$detalle}\nPrecio: *\$" . number_format($valor) . "*\n\nElige cómo pagar:",
|
||||||
$buttons
|
$buttons
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$falta = $valor - $saldo;
|
||||||
|
$buttons[] = [['text' => '💰 Recargar saldo', 'callback_data' => 'rec_init']];
|
||||||
|
$buttons[] = [['text' => '🔙 Ver planes', 'callback_data' => 'svc_view|' . $tarifa->servicio_id]];
|
||||||
|
|
||||||
|
$this->sendWithKeyboard(
|
||||||
|
$chatId,
|
||||||
|
"*{$tarifa->servicio->nombre}* — {$detalle}\nPrecio: *\$" . number_format($valor) . "*\n\nSaldo actual: \$" . number_format($saldo) . " — te faltan *\$" . number_format($falta) . "*\n\nRecarga para continuar:",
|
||||||
|
$buttons
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function payWithSaldo(string $chatId): void
|
private function payWithSaldo(string $chatId): void
|
||||||
@@ -883,17 +893,27 @@ class TelegramBotService
|
|||||||
$precio = $upric ? $upric->precio : ($tp ? $tp->precio : $promo->precio);
|
$precio = $upric ? $upric->precio : ($tp ? $tp->precio : $promo->precio);
|
||||||
|
|
||||||
$buttons = [];
|
$buttons = [];
|
||||||
|
|
||||||
if ($saldo >= $precio) {
|
if ($saldo >= $precio) {
|
||||||
$buttons[] = [['text' => "💳 Pagar con saldo (\$" . number_format($precio) . ")", 'callback_data' => 'promo_saldo|' . $promoId]];
|
$buttons[] = [['text' => "💳 Pagar con saldo (\$" . number_format($precio) . ")", 'callback_data' => 'promo_saldo|' . $promoId]];
|
||||||
}
|
$buttons[] = [['text' => '🔙 Promociones', 'callback_data' => 'promo_list']];
|
||||||
$buttons[] = [['text' => '🏦 MercadoPago', 'callback_data' => 'promo_mp|' . $promoId]];
|
|
||||||
$buttons[] = [['text' => '🔙 Promociones', 'callback_data' => 'promo_list']];
|
|
||||||
|
|
||||||
$this->sendWithKeyboard(
|
$this->sendWithKeyboard(
|
||||||
$chatId,
|
$chatId,
|
||||||
"*{$promo->nombre}*\n\$" . number_format($precio) . "\n\nElige cómo pagar:",
|
"*{$promo->nombre}*\n\$" . number_format($precio) . "\n\nElige cómo pagar:",
|
||||||
$buttons
|
$buttons
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$falta = $precio - $saldo;
|
||||||
|
$buttons[] = [['text' => '💰 Recargar saldo', 'callback_data' => 'rec_init']];
|
||||||
|
$buttons[] = [['text' => '🔙 Promociones', 'callback_data' => 'promo_list']];
|
||||||
|
|
||||||
|
$this->sendWithKeyboard(
|
||||||
|
$chatId,
|
||||||
|
"*{$promo->nombre}*\n\$" . number_format($precio) . "\n\nSaldo actual: \$" . number_format($saldo) . " — te faltan *\$" . number_format($falta) . "*\n\nRecarga para continuar:",
|
||||||
|
$buttons
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buyPromoSaldo(string $chatId, int $promoId): void
|
private function buyPromoSaldo(string $chatId, int $promoId): void
|
||||||
|
|||||||
Reference in New Issue
Block a user