mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-21 12:26:43 +02:00
Assorted changes from recent sessions: - .gitignore: add mana-sync binary, Forgejo data - chat/web: add isSidebarMode to navigation store - clock/web: fix alarm page markup - contacts/mukke/presi/questions: add svelte.config.js aliases - context/web: add missing dependency - manacore/landing: update pricing page - manacore/web + todo/web: update mana dashboard pages - planta/web: fix dashboard layout - pnpm-lock.yaml: cleanup after backend removals - docs/APP_GAP_ANALYSIS.md: new gap analysis doc - services/mana-analytics: add Dockerfile - services/mana-subscriptions: new Go subscription service Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { Hono } from 'hono';
|
|
import type { StripeService } from '../services/stripe';
|
|
import type { SubscriptionsService } from '../services/subscriptions';
|
|
|
|
export function createWebhookRoutes(
|
|
stripeService: StripeService,
|
|
subscriptionsService: SubscriptionsService,
|
|
webhookSecret: string
|
|
) {
|
|
return new Hono().post('/stripe', async (c) => {
|
|
const signature = c.req.header('stripe-signature');
|
|
if (!signature) return c.json({ error: 'Missing signature' }, 400);
|
|
|
|
const rawBody = await c.req.text();
|
|
|
|
let event;
|
|
try {
|
|
event = stripeService.verifyWebhookSignature(rawBody, signature, webhookSecret);
|
|
} catch {
|
|
return c.json({ error: 'Invalid signature' }, 400);
|
|
}
|
|
|
|
switch (event.type) {
|
|
case 'customer.subscription.created':
|
|
case 'customer.subscription.updated':
|
|
case 'customer.subscription.deleted':
|
|
await subscriptionsService.handleSubscriptionUpdated(event.data.object as any);
|
|
break;
|
|
|
|
case 'invoice.created':
|
|
case 'invoice.updated':
|
|
case 'invoice.paid':
|
|
case 'invoice.payment_failed':
|
|
await subscriptionsService.handleInvoiceUpdated(event.data.object as any);
|
|
break;
|
|
|
|
default:
|
|
console.log('Unhandled webhook event:', event.type);
|
|
}
|
|
|
|
return c.json({ received: true });
|
|
});
|
|
}
|