Añadir /trans-history (Historial de transacciones): solo Stripe y SumUp
Dos cajas por pasarela (Stripe mode test/live, SumUp mode sumup) desde home_stripelog, con logo, nota y tabla ID/Estado/Concepto/Fecha/Cantidad. Estado PAID (fulfilled=1) / PENDING. Se omiten dLocal, Crypto y PayPal del diseño original. lib/trans-history.ts (getPaymentTransactions). Django era stub. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import type { RowDataPacket } from 'mysql2'
|
||||
import { db, DB } from './db'
|
||||
|
||||
/** 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 €
|
||||
concept: 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, amount, mode, 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) => ({
|
||||
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),
|
||||
concept: String(r.product_name || '—'),
|
||||
}))
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user