feat: integrate Stripe payment module with API + UI components
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user