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:
@@ -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 })}
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user