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

@@ -9,24 +9,27 @@ import { CountryStep } from './CountryStep'
import { FirstGroupStep } from './FirstGroupStep'
import { useOnboarding } from './OnboardingProvider'
import { PaymentStep } from './PaymentStep'
import { PlanStep } from './PlanStep'
import { STEP_LABELS } from './steps'
import { Stepper } from './Stepper'
import { WelcomeStep } from './WelcomeStep'
import { WhatsappStep } from './WhatsappStep'
const STEPS = [
{ label: 'Bienvenida' },
{ label: 'País' },
{ label: 'Cobros' },
{ label: 'WhatsApp' },
{ label: 'Tu grupo' },
{ label: 'Listo' },
]
export function OnboardingView() {
const { user, isPending: authPending } = useAuth()
const navigate = useNavigate()
const { step, setStep, mpFeedback, waFeedback, createdGroup, setCreatedGroup, statusQuery } =
useOnboarding()
const {
step,
steps,
goTo,
goNext,
goBack,
mpFeedback,
waFeedback,
createdGroup,
setCreatedGroup,
statusQuery,
} = useOnboarding()
useEffect(() => {
if (statusQuery.data?.completed) {
@@ -81,29 +84,33 @@ export function OnboardingView() {
<Logo className="h-6" />
</header>
<Stepper steps={STEPS} current={step} />
{/* Con Free no se muestran Cobros ni WhatsApp: el stepper refleja solo
los pasos que se van a recorrer. */}
<Stepper
steps={steps.map((id) => ({ label: STEP_LABELS[id] }))}
current={steps.indexOf(step)}
/>
<div key={step} className="mt-8 animate-step-enter">
{step === 0 ? <WelcomeStep name={firstName} onNext={() => setStep(1)} /> : null}
{step === 1 ? (
<CountryStep onNext={() => setStep(2)} onBack={() => setStep(0)} />
{step === 'welcome' ? <WelcomeStep name={firstName} onNext={goNext} /> : null}
{step === 'country' ? <CountryStep onNext={goNext} onBack={goBack} /> : null}
{step === 'plan' ? <PlanStep /> : null}
{step === 'payment' ? (
<PaymentStep feedback={mpFeedback} onNext={goNext} onBack={goBack} />
) : null}
{step === 2 ? (
<PaymentStep feedback={mpFeedback} onNext={() => setStep(3)} onBack={() => setStep(1)} />
{step === 'whatsapp' ? (
<WhatsappStep feedback={waFeedback} onNext={goNext} onBack={goBack} />
) : null}
{step === 3 ? (
<WhatsappStep feedback={waFeedback} onNext={() => setStep(4)} onBack={() => setStep(2)} />
) : null}
{step === 4 ? (
{step === 'group' ? (
<FirstGroupStep
onBack={() => setStep(3)}
onBack={goBack}
onCompleted={(group) => {
setCreatedGroup(group)
setStep(5)
goTo('done')
}}
/>
) : null}
{step === 5 && createdGroup ? <ConfirmationStep group={createdGroup} /> : null}
{step === 'done' && createdGroup ? <ConfirmationStep group={createdGroup} /> : null}
</div>
</main>
)