89f6e5689f
Elimina las pestañas de PayPal/dLocal/Crypto/Skrill y por país; deja Información + Stripe + SumUp (las dos únicas pasarelas que se usarán). - Stripe: totalmente funcional reutilizando createCheckoutSession + webhook + página de éxito. Nueva ruta /api/dpoints/checkout crea la sesión con importe elegido por el usuario (1 unidad = 100 PD). - SumUp: integración real (lib/sumup.ts) mediante checkout hospedado, habilitada al definir SUMUP_API_KEY/SUMUP_MERCHANT_CODE; si no, avisa. - Nuevo servicio de entrega `dpoints` (lib/paid-services.ts) que acredita PD en home_api_points; entrega idempotente vía reclamo atómico. - Página /d-points-success entrega ambos proveedores (session_id/ref). - Iconos SVG generados para cada pasarela (stripe/sumup, marca + wordmark). - Moneda configurable con DP_CURRENCY (por defecto EUR). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
95 lines
3.0 KiB
TypeScript
95 lines
3.0 KiB
TypeScript
import { executeSoapCommand } from './soap'
|
|
import { db, DB } from './db'
|
|
import { creditDPoints } from './dpoints'
|
|
import {
|
|
getRenamePrice,
|
|
getCustomizePrice,
|
|
getChangeRacePrice,
|
|
getChangeFactionPrice,
|
|
getLevelUpPrice,
|
|
getTransferPrice,
|
|
goldPriceFor,
|
|
} from './prices'
|
|
|
|
type Meta = Record<string, string>
|
|
|
|
export interface PaidServiceConfig {
|
|
price: (meta: Meta) => Promise<number>
|
|
productName: (character: string, meta: Meta) => string
|
|
fulfill: (character: string, meta: Meta) => Promise<boolean>
|
|
extraFields: string[] // campos (además de character) que el form envía y se guardan en metadata
|
|
}
|
|
|
|
async function soapFulfill(command: string): Promise<boolean> {
|
|
return (await executeSoapCommand(command)) !== null
|
|
}
|
|
|
|
async function addGold(character: string, goldAmount: number): Promise<boolean> {
|
|
try {
|
|
await db(DB.characters).query('UPDATE characters SET money = money + ? WHERE name = ?', [
|
|
goldAmount * 10000,
|
|
character,
|
|
])
|
|
return true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
|
|
export const PAID_SERVICES: Record<string, PaidServiceConfig> = {
|
|
rename: {
|
|
price: () => getRenamePrice(),
|
|
productName: (c) => `Renombrar personaje: ${c}`,
|
|
fulfill: (c) => soapFulfill(`.char rename ${c}`),
|
|
extraFields: [],
|
|
},
|
|
customize: {
|
|
price: () => getCustomizePrice(),
|
|
productName: (c) => `Personalizar personaje: ${c}`,
|
|
fulfill: (c) => soapFulfill(`.char customi ${c}`),
|
|
extraFields: [],
|
|
},
|
|
'change-race': {
|
|
price: () => getChangeRacePrice(),
|
|
productName: (c) => `Cambiar raza: ${c}`,
|
|
fulfill: (c) => soapFulfill(`.char changerace ${c}`),
|
|
extraFields: [],
|
|
},
|
|
'change-faction': {
|
|
price: () => getChangeFactionPrice(),
|
|
productName: (c) => `Cambiar facción: ${c}`,
|
|
fulfill: (c) => soapFulfill(`.char changef ${c}`),
|
|
extraFields: [],
|
|
},
|
|
'level-up': {
|
|
price: () => getLevelUpPrice(),
|
|
productName: (c) => `Subir a nivel 80: ${c}`,
|
|
fulfill: (c) => soapFulfill(`.char level ${c} 80`),
|
|
extraFields: [],
|
|
},
|
|
gold: {
|
|
price: (m) => goldPriceFor(Number(m.gold_amount)),
|
|
productName: (c, m) => `Aumentar el Oro: ${m.gold_amount} al Personaje: ${c}`,
|
|
fulfill: (c, m) => addGold(c, Number(m.gold_amount)),
|
|
extraFields: ['gold_amount'],
|
|
},
|
|
transfer: {
|
|
price: () => getTransferPrice(),
|
|
productName: (c, m) => `Transferir ${c} a la cuenta ${m.destination_account}`,
|
|
fulfill: (c, m) => soapFulfill(`.char changeaccount ${m.destination_account} ${c}`),
|
|
extraFields: ['destination_account'],
|
|
},
|
|
// Compra de PD (Adquirir PD): acredita puntos a la cuenta que hizo el pago.
|
|
// El importe lo elige el usuario, por eso `price` lee metadata.amount.
|
|
dpoints: {
|
|
price: (m) => Promise.resolve(Number(m.amount)),
|
|
productName: (_c, m) => `${Number(m.points)} PD`,
|
|
fulfill: (_c, m) => creditDPoints(Number(m.accountId), Number(m.points)),
|
|
extraFields: [],
|
|
},
|
|
}
|
|
|
|
export function getPaidService(slug: string): PaidServiceConfig | null {
|
|
return PAID_SERVICES[slug] ?? null
|
|
}
|