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,32 @@
|
||||
import { notFound } from 'next/navigation'
|
||||
import { getTranslations, setRequestLocale } from 'next-intl/server'
|
||||
import { redirect } from '@/i18n/navigation'
|
||||
import { getSession } from '@/lib/session'
|
||||
import { getGameCharacters } from '@/lib/characters'
|
||||
import { getPaidService } from '@/lib/paid-services'
|
||||
import { PaidServiceForm } from '@/components/PaidServiceForm'
|
||||
|
||||
/** Contenido común de una página de servicio de pago (guardas + form). */
|
||||
export async function ServicePageContent({ service, locale }: { service: string; locale: string }) {
|
||||
setRequestLocale(locale)
|
||||
const cfg = getPaidService(service)
|
||||
if (!cfg) notFound()
|
||||
|
||||
const t = await getTranslations('Paid')
|
||||
const session = await getSession()
|
||||
if (!session.bnetId) redirect({ href: '/login', locale })
|
||||
if (!session.username) redirect({ href: '/select-account', locale })
|
||||
|
||||
const [chars, price] = await Promise.all([getGameCharacters(session.accountId!), cfg!.getPrice()])
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-3xl px-4 py-8">
|
||||
<h1 className="mb-6 text-center text-2xl font-bold text-amber-500">{t(`${service}.title`)}</h1>
|
||||
<PaidServiceForm
|
||||
characters={chars.map((c) => c.name)}
|
||||
checkoutEndpoint={`/api/character/${service}/checkout`}
|
||||
payLabel={t(`${service}.pay`, { price })}
|
||||
/>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user