Files
LynkedUpPro_CRM/api/payments/transactions.js
T

28 lines
1013 B
JavaScript

/**
* Stripe — Transaction history
* ----------------------------
* Returns the payment records written by the webhook (the server-side source of
* truth). Reads from Vercel KV when connected; returns an empty list otherwise
* so the frontend degrades gracefully and falls back to its local record.
*
* GET /api/payments/transactions -> { transactions: [...] }
*/
export default async function handler(req, res) {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' });
}
try {
const { kv } = await import('@vercel/kv');
const raw = await kv.lrange('payments:transactions', 0, 199);
const transactions = (raw || []).map((item) =>
typeof item === 'string' ? JSON.parse(item) : item
);
return res.status(200).json({ transactions });
} catch {
// KV not configured — the frontend will use its local record instead.
return res.status(200).json({ transactions: [] });
}
}