feat(billing): proveedores intercambiables (Mercado Pago en AR, Stripe en el resto)
- Puerto BillingProvider con adaptadores de Mercado Pago (/preapproval) y Stripe (Checkout en modo suscripción, fetch plano). El país elige proveedor solo para suscripciones nuevas; sync, cancel y webhook usan row.provider. - Migración add_billing_providers (provider, checkout_ref, ids genéricos). - fix: /authorized_payments/search respondía 400 "Invalid value for limit"; se pagina por offset sin limit. - fix: si falla la consulta de cobros, la sync guarda igual el estado de la suscripción (ya no queda PENDING tras autorizar) y reintenta los cobros. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { SelectPlanInput } from '@gruperly/shared'
|
||||
import { COUNTRY_CURRENCY, PLAN_LIMITS, PRO_PRICE_BY_COUNTRY } from '@gruperly/shared'
|
||||
import { billingProviderForCountry, COUNTRY_CURRENCY, PLAN_LIMITS, PRO_PRICE_BY_COUNTRY } from '@gruperly/shared'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { ArrowLeft, ArrowRight, CheckCircle2, Clock, Loader2, Sparkles } from 'lucide-react'
|
||||
import { type ReactNode, useEffect, useState } from 'react'
|
||||
@@ -8,6 +8,7 @@ import { useAuth } from '../../context/AuthProvider'
|
||||
import { ApiError, selectPlan } from '../../lib/api'
|
||||
import { formatPrice } from '../../lib/format'
|
||||
import {
|
||||
BILLING_PROVIDER_NAMES,
|
||||
PlanOptionCard,
|
||||
SubscribeForm,
|
||||
useBillingStatus,
|
||||
@@ -19,15 +20,16 @@ const SELECT_PLAN_ERROR_MESSAGE = 'No pudimos guardar tu plan. Revisá tu conexi
|
||||
|
||||
/**
|
||||
* Paso "Plan" del onboarding (obligatorio). Free sigue directo al primer grupo
|
||||
* (sin Cobros ni WhatsApp, que son de Pro). Pro lleva a Mercado Pago a
|
||||
* autorizar el débito y vuelve acá con `?sub=return`; mientras Mercado Pago
|
||||
* confirma se puede seguir igual.
|
||||
* (sin Cobros ni WhatsApp, que son de Pro). Pro lleva al checkout del
|
||||
* proveedor del país (Mercado Pago en Argentina, Stripe en el resto) y vuelve
|
||||
* acá con `?sub=return`; mientras el proveedor confirma se puede seguir igual.
|
||||
*/
|
||||
export function PlanStep() {
|
||||
const { user } = useAuth()
|
||||
const queryClient = useQueryClient()
|
||||
const { country, selectedPlan, setSelectedPlan, returnedFromSubscription, goTo, goBack, statusQuery } =
|
||||
useOnboarding()
|
||||
// Con Mercado Pago, el paso intermedio de pedir el email; con Stripe, el de confirmar.
|
||||
const [isEnteringEmail, setIsEnteringEmail] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [proUnavailable, setProUnavailable] = useState(false)
|
||||
@@ -42,6 +44,8 @@ export function PlanStep() {
|
||||
if (returnedFromSubscription) polling.startPolling()
|
||||
}, [returnedFromSubscription, polling.startPolling])
|
||||
|
||||
const provider = billingProviderForCountry(country)
|
||||
const providerName = BILLING_PROVIDER_NAMES[provider]
|
||||
const subscriptionStatus = billingQuery.data?.status ?? statusQuery.data?.subscriptionStatus ?? null
|
||||
|
||||
const mutation = useMutation({
|
||||
@@ -71,7 +75,7 @@ export function PlanStep() {
|
||||
setError(null)
|
||||
mutation.mutate({ plan: 'FREE', country })
|
||||
}
|
||||
const choosePro = (payerEmail: string) => {
|
||||
const choosePro = (payerEmail: string | undefined) => {
|
||||
setError(null)
|
||||
mutation.mutate({ plan: 'PRO', country, payerEmail })
|
||||
}
|
||||
@@ -109,8 +113,8 @@ export function PlanStep() {
|
||||
</p>
|
||||
<p className="text-xs text-foreground/50">
|
||||
{returnedFromSubscription
|
||||
? 'Mercado Pago puede tardar unos minutos en confirmarlo. Podés seguir mientras tanto: te avisamos cuando quede activa.'
|
||||
: 'No terminaste de autorizar el débito en Mercado Pago. Podés reintentarlo o seguir con Free.'}
|
||||
? `${providerName} puede tardar unos minutos en confirmarlo. Podés seguir mientras tanto: te avisamos cuando quede activa.`
|
||||
: `No terminaste de autorizar el pago en ${providerName}. Podés reintentarlo o seguir con Free.`}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -156,6 +160,7 @@ export function PlanStep() {
|
||||
<p className="text-xs text-foreground/50">Todavía no está disponible en tu país.</p>
|
||||
) : isEnteringEmail ? (
|
||||
<SubscribeForm
|
||||
provider={provider}
|
||||
defaultEmail={user?.email ?? ''}
|
||||
isPending={isLeavingToMp}
|
||||
error={null}
|
||||
|
||||
Reference in New Issue
Block a user