feat: integrate Stripe payment module with API + UI components

This commit is contained in:
2026-06-09 21:10:57 +05:30
parent 944a745892
commit 5eb06b2809
25 changed files with 1434 additions and 1 deletions
+20
View File
@@ -22,6 +22,11 @@ const DEV_API_HANDLERS = {
'hail-proxy': () => import('./api/hail-proxy.js'),
'storm-events': () => import('./api/storm-events.js'),
'storm-polygons': () => import('./api/storm-polygons.js'),
// Payments module (needs real Stripe test keys in .env to function locally).
// The webhook is intentionally excluded — it needs the raw body + Stripe CLI.
'payments/create-checkout-session': () => import('./api/payments/create-checkout-session.js'),
'payments/session-status': () => import('./api/payments/session-status.js'),
'payments/transactions': () => import('./api/payments/transactions.js'),
}
// Server-side env vars the handlers read (mirrors what you'd set in Vercel).
@@ -30,6 +35,8 @@ const SERVER_ENV_KEYS = [
'HAIL_RECON_ACCESS_KEY',
'HAIL_RECON_ACCESS_SECRET',
'HAIL_RECON_WEBHOOK_SECRET',
'STRIPE_SECRET_KEY',
'STRIPE_WEBHOOK_SECRET',
]
function devApi(env) {
@@ -62,6 +69,19 @@ function devApi(env) {
res.end(JSON.stringify(obj))
return res
}
res.send = (body) => { res.end(typeof body === 'string' ? body : JSON.stringify(body)); return res }
// Parse a JSON body for POST/PUT/PATCH (Vercel does this automatically).
if (['POST', 'PUT', 'PATCH'].includes(req.method)) {
req.body = await new Promise((resolve) => {
let data = ''
req.on('data', (c) => { data += c })
req.on('end', () => {
try { resolve(data ? JSON.parse(data) : {}) } catch { resolve({}) }
})
req.on('error', () => resolve({}))
})
}
try {
const mod = await load()