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

@@ -2,6 +2,12 @@ import { useNavigate } from '@tanstack/react-router'
import { Loader2 } from 'lucide-react'
import { useState } from 'react'
import { Button } from '../../../components/ui'
import {
hasPlanFeature,
PLAN_FEATURE_REQUIRED_MESSAGES,
showPlanPrompt,
useBillingStatus,
} from '../../billing'
import { ChargeMembersModal } from './ChargeMembersModal'
import { GroupAutomationsCard } from './GroupAutomationsCard'
import { GroupHeader } from './GroupHeader'
@@ -23,16 +29,27 @@ export function GroupDetailView() {
firstWaitlistEntry,
waitlistTotal,
isSubmittingRemoval,
isGroupOwner,
} = useGroupDetail()
const navigate = useNavigate()
const [isChargeModalOpen, setIsChargeModalOpen] = useState(false)
// El plan que cuenta es el del dueño: para un ADMIN no sabemos el suyo y
// decide el backend (un 402 abre el mismo aviso).
const billingQuery = useBillingStatus({ enabled: isGroupOwner })
const handleCharge = () => {
if (isGroupOwner && !hasPlanFeature(billingQuery.data, 'mpCharges')) {
showPlanPrompt(PLAN_FEATURE_REQUIRED_MESSAGES.mpCharges)
return
}
setIsChargeModalOpen(true)
}
return (
<section className="animate-fade-in space-y-5 sm:space-y-6">
{/* The large title always renders, even while loading: it is what gives
the immersive bar its height and stops the layout from jumping when
the data arrives. */}
<GroupHeader onCharge={() => setIsChargeModalOpen(true)} />
<GroupHeader onCharge={handleCharge} />
{groupQueryPending ? (
<div className="flex items-center justify-center py-20">