19d3c43a76
Extrae la lógica de concepto traducible a lib/tx-concept.ts (buildConcept + purchasedPD + SERVICE_CONCEPT) y la reutilizan points-history y trans-history. La columna Concepto de trans-history ahora se traduce (reusa History.points.concept.*) en vez de mostrar el product_name en español. Corrige también la sombra de variable en PlatformBox (map t -> tx). Verificado con la cuenta 15. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import type { RowDataPacket } from 'mysql2'
|
|
import { db, DB } from './db'
|
|
import { buildConcept } from './tx-concept'
|
|
|
|
/** Una transacción de pago (Stripe o SumUp) registrada en home_stripelog. */
|
|
export interface PaymentTx {
|
|
id: string // referencia de la pasarela (session_id / checkout_reference)
|
|
platform: 'Stripe' | 'SumUp'
|
|
status: 'PAID' | 'PENDING'
|
|
createdAt: Date
|
|
amount: number // importe en €
|
|
// Concepto traducible (clave + args) con reserva de texto libre.
|
|
conceptKey: string | null
|
|
conceptArgs: Record<string, string | number>
|
|
conceptRaw: string
|
|
}
|
|
|
|
/**
|
|
* Transacciones de pago de una cuenta desde `home_stripelog`, limitadas a las
|
|
* dos pasarelas activas: **Stripe** (mode test/live) y **SumUp** (mode sumup).
|
|
* `fulfilled` 1 -> PAID (pagado y entregado), 0 -> PENDING. Orden por fecha desc.
|
|
*/
|
|
export async function getPaymentTransactions(accountId: number, limit = 200): Promise<PaymentTx[]> {
|
|
if (!accountId) return []
|
|
try {
|
|
const [rows] = await db(DB.default).query<RowDataPacket[]>(
|
|
'SELECT session_id, product_name, character_name, amount, mode, service, metadata, fulfilled, timestamp FROM home_stripelog ' +
|
|
"WHERE account_id = ? AND mode IN ('sumup', 'test', 'live') ORDER BY timestamp DESC LIMIT ?",
|
|
[accountId, limit],
|
|
)
|
|
return rows.map((r) => {
|
|
const c = buildConcept(
|
|
String(r.product_name || '—'),
|
|
r.service ? String(r.service) : null,
|
|
String(r.character_name || ''),
|
|
r.metadata ? String(r.metadata) : null,
|
|
)
|
|
return {
|
|
id: String(r.session_id || ''),
|
|
platform: r.mode === 'sumup' ? 'SumUp' : 'Stripe',
|
|
status: r.fulfilled ? 'PAID' : 'PENDING',
|
|
createdAt: new Date(r.timestamp),
|
|
amount: Number(r.amount),
|
|
conceptKey: c.conceptKey,
|
|
conceptArgs: c.conceptArgs,
|
|
conceptRaw: c.conceptRaw,
|
|
}
|
|
})
|
|
} catch {
|
|
return []
|
|
}
|
|
}
|