87f9b0b003
- 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>
46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
import { getSession } from '@/lib/session'
|
|
import { getGameCharacters } from '@/lib/characters'
|
|
import { createCheckoutSession } from '@/lib/stripe'
|
|
import { getPaidService } from '@/lib/paid-services'
|
|
|
|
export async function POST(request: Request, { params }: { params: Promise<{ service: string }> }) {
|
|
const { service } = await params
|
|
const cfg = getPaidService(service)
|
|
if (!cfg) return Response.json({ success: false, error: 'invalidService' }, { status: 404 })
|
|
|
|
const session = await getSession()
|
|
if (!session.accountId) return Response.json({ success: false, error: 'notAuthenticated' }, { status: 401 })
|
|
|
|
let character = ''
|
|
try {
|
|
const body = await request.json()
|
|
character = String(body.character ?? '')
|
|
} catch {
|
|
return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 })
|
|
}
|
|
if (!character) return Response.json({ success: false, error: 'invalidCharacter' })
|
|
|
|
const chars = await getGameCharacters(session.accountId)
|
|
if (!chars.find((c) => c.name === character)) {
|
|
return Response.json({ success: false, error: 'invalidCharacter' })
|
|
}
|
|
|
|
const price = await cfg.getPrice()
|
|
const site = process.env.SITE_URL || ''
|
|
const ip = (request.headers.get('x-forwarded-for') || '').split(',')[0].trim() || '0.0.0.0'
|
|
|
|
const r = await createCheckoutSession({
|
|
accountId: session.accountId,
|
|
username: session.username || '',
|
|
email: session.bnetEmail || '',
|
|
acoreIp: ip,
|
|
amount: price,
|
|
characterName: character,
|
|
productName: cfg.productName(character),
|
|
successUrl: `${site}/service-success?service=${service}`,
|
|
cancelUrl: `${site}/${service}`,
|
|
})
|
|
if (!r.success || !r.url) return Response.json({ success: false, error: 'stripeError' })
|
|
return Response.json({ success: true, url: r.url })
|
|
}
|