feat(billing): planes Free/Pro con Suscripciones de Mercado Pago

- Módulo billing: suscripción Pro mensual vía /preapproval con credenciales
  de plataforma por país, webhook firmado y reconciliación por polling.
- PlanGuard en los use-cases que crean grupos/alumnos, cobran con MP o
  activan automatizaciones (402 plan_limit_reached / plan_feature_required /
  plan_read_only), detrás de BILLING_ENFORCEMENT.
- Onboarding: paso Plan obligatorio (POST /onboarding/plan); con Free se
  saltean Cobros y WhatsApp.
- Web: pantalla /billing, aviso de Pro desde el MutationCache.
- Migración billing_subscriptions y docs/billing.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-10-23 15:49:27 -03:00
parent f4d2c26e29
commit f5e77c99f6
93 changed files with 4402 additions and 117 deletions

View File

@@ -1,7 +1,8 @@
import type { GroupAutomationsDto } from '@gruperly/shared'
import { Link } from '@tanstack/react-router'
import { MessageCircle } from 'lucide-react'
import { Switch } from '../../../components/ui'
import { Badge, Switch } from '../../../components/ui'
import { hasPlanFeature, useBillingStatus } from '../../billing'
import { automationBlockedReason, useWhatsappStatus, WEEKLY_SEND_LABEL } from '../../whatsapp'
import { useGroupDetail } from './GroupDetailProvider'
@@ -35,7 +36,9 @@ const AUTOMATIONS: readonly Automation[] = [
export function GroupAutomationsCard() {
const { group, updateAutomations, isUpdatingAutomations, isGroupOwner } = useGroupDetail()
const whatsappQuery = useWhatsappStatus({ enabled: isGroupOwner })
const billingQuery = useBillingStatus({ enabled: isGroupOwner })
if (!group || !isGroupOwner) return null
const includedInPlan = hasPlanFeature(billingQuery.data, 'whatsappAutomations')
return (
<section className="rounded-xl border border-border bg-surface">
@@ -44,8 +47,22 @@ export function GroupAutomationsCard() {
<MessageCircle className="size-4 text-success" />
</span>
<div className="min-w-0 flex-1">
<h2 className="text-sm font-semibold text-primary">Mensajes automáticos por WhatsApp</h2>
<p className="text-xs text-foreground/50">{WEEKLY_SEND_LABEL}</p>
<div className="flex items-center gap-2">
<h2 className="text-sm font-semibold text-primary">Mensajes automáticos por WhatsApp</h2>
{includedInPlan ? null : <Badge variant="info">Pro</Badge>}
</div>
<p className="text-xs text-foreground/50">
{WEEKLY_SEND_LABEL}
{includedInPlan ? null : (
<>
{' '}
Disponible en el plan Pro.{' '}
<Link to="/billing" className="font-medium text-accent-fg underline">
Ver planes
</Link>
</>
)}
</p>
</div>
</header>
@@ -75,7 +92,9 @@ export function GroupAutomationsCard() {
</div>
<Switch
checked={checked}
disabled={isUpdatingAutomations || (!checked && blocked !== null)}
disabled={
isUpdatingAutomations || (!checked && (blocked !== null || !includedInPlan))
}
aria-label={automation.title}
aria-describedby={hintId}
onCheckedChange={(next) => updateAutomations({ [automation.key]: next })}