- 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>
81 lines
2.9 KiB
TypeScript
81 lines
2.9 KiB
TypeScript
import { PLAN_LIMITS } from '@gruperly/shared'
|
|
import { Link } from '@tanstack/react-router'
|
|
import { ChevronLeft, Sparkles } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import { Button } from '../../components/ui'
|
|
import { formatPrice } from '../../lib/format'
|
|
import { useBilling } from './BillingProvider'
|
|
import { CancelSubscriptionModal } from './CancelSubscriptionModal'
|
|
import { ChargesList } from './ChargesList'
|
|
import { PlanOptionCard } from './PlanOptionCard'
|
|
import { PlanSummaryCard } from './PlanSummaryCard'
|
|
import { SubscribeModal } from './SubscribeModal'
|
|
|
|
export function BillingView() {
|
|
const { statusQuery, openSubscribe, cancel, isCancelling } = useBilling()
|
|
const [isConfirmingCancel, setIsConfirmingCancel] = useState(false)
|
|
const status = statusQuery.data
|
|
|
|
const subscribed = status?.status === 'AUTHORIZED' || status?.status === 'PAUSED'
|
|
const pending = status?.status === 'PENDING'
|
|
const proPrice = status ? `${formatPrice(status.priceAmount, status.currency)} / mes` : undefined
|
|
|
|
return (
|
|
<section className="space-y-6">
|
|
<div>
|
|
<Link
|
|
to="/settings"
|
|
className="mb-2 hidden items-center gap-1 text-sm text-foreground/60 hover:text-primary lg:inline-flex"
|
|
>
|
|
<ChevronLeft className="size-4" />
|
|
Ajustes
|
|
</Link>
|
|
<h1 className="text-2xl font-bold text-primary">Tu plan</h1>
|
|
<p className="mt-1 text-sm text-foreground/60">Elegí cómo usar Gruperly.</p>
|
|
</div>
|
|
|
|
<PlanSummaryCard />
|
|
|
|
{status ? (
|
|
<div className="grid gap-4 sm:grid-cols-2">
|
|
<PlanOptionCard plan="FREE" limits={PLAN_LIMITS.FREE} current={status.plan === 'FREE'} />
|
|
<PlanOptionCard
|
|
plan="PRO"
|
|
limits={PLAN_LIMITS.PRO}
|
|
price={proPrice}
|
|
current={status.plan === 'PRO'}
|
|
highlighted={status.plan === 'FREE'}
|
|
>
|
|
{subscribed ? (
|
|
<Button variant="outline" className="w-full" onClick={() => setIsConfirmingCancel(true)}>
|
|
Cancelar suscripción
|
|
</Button>
|
|
) : status.availableInCountry ? (
|
|
<Button variant="primary" className="w-full" onClick={openSubscribe}>
|
|
<Sparkles className="size-4" />
|
|
{pending ? 'Reintentar el pago' : 'Pasar a Pro'}
|
|
</Button>
|
|
) : (
|
|
<p className="text-xs text-foreground/50">Todavía no está disponible en tu país.</p>
|
|
)}
|
|
</PlanOptionCard>
|
|
</div>
|
|
) : null}
|
|
|
|
<ChargesList />
|
|
|
|
<SubscribeModal />
|
|
<CancelSubscriptionModal
|
|
isOpen={isConfirmingCancel}
|
|
isPending={isCancelling}
|
|
paidThrough={status?.paidThrough ?? null}
|
|
onClose={() => setIsConfirmingCancel(false)}
|
|
onConfirm={() => {
|
|
setIsConfirmingCancel(false)
|
|
cancel()
|
|
}}
|
|
/>
|
|
</section>
|
|
)
|
|
}
|