Generaliza los servicios de personaje de pago (5) con infra común
- lib/paid-services.ts: config PAID_SERVICES (rename/customize/change-race/ change-faction/level-up) con comando SOAP, precio y productName por servicio. - app/api/character/[service]/checkout: ruta de checkout GENÉRICA (valida servicio + personaje, crea la sesión Stripe con successUrl /service-success?service=...). - app/[locale]/service-success: página de éxito ÚNICA que verifica el pago (claimPaidCheckout) y ejecuta el comando SOAP del servicio. - components/ServicePageContent: contenido común (guardas + PaidServiceForm). - 5 páginas mínimas /rename /customize /change-race /change-faction /level-up. - Catálogo Paid (por servicio: title/pay/success) sustituye a Rename. Verificado: 5 páginas redirigen a login, checkout 401 sin sesión, servicio inválido 404, service-success con pago inválido no entrega (muestra error). Pendiente: gold (cantidad) y transfer (destino+token), variantes del patrón. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
||||
import { claimPaidCheckout } from '@/lib/stripe'
|
||||
import { executeSoapCommand } from '@/lib/soap'
|
||||
import { getPaidService } from '@/lib/paid-services'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
export default async function ServiceSuccessPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ locale: string }>
|
||||
searchParams: Promise<{ service?: string; session_id?: string }>
|
||||
}) {
|
||||
const { locale } = await params
|
||||
setRequestLocale(locale)
|
||||
const { service, session_id } = await searchParams
|
||||
const t = await getTranslations('Paid')
|
||||
const cfg = service ? getPaidService(service) : null
|
||||
|
||||
// Verifica el pago (una vez) y ejecuta el comando SOAP del servicio.
|
||||
let okName: string | null = null
|
||||
if (cfg && session_id) {
|
||||
const claim = await claimPaidCheckout(session_id)
|
||||
if (claim) {
|
||||
const resp = await executeSoapCommand(cfg.command(claim.characterName))
|
||||
if (resp !== null) okName = claim.characterName
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-lg px-4 py-12 text-center">
|
||||
<h1 className="mb-6 text-2xl font-bold text-amber-500">{service ? t(`${service}.title`) : ''}</h1>
|
||||
{okName ? (
|
||||
<p className="text-green-400">{t(`${service}.success`, { name: okName })}</p>
|
||||
) : (
|
||||
<p className="text-red-400">{t('error')}</p>
|
||||
)}
|
||||
</main>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user