MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / handler

Function handler

apps/web/pages/api/webhook/stripe.ts:43–79  ·  view source on GitHub ↗
(
  request: NextApiRequest,
  response: NextApiResponse
)

Source from the content-addressed store, hash-verified

41}
42
43export default async function handler(
44 request: NextApiRequest,
45 response: NextApiResponse
46) {
47 const signature = request.headers['stripe-signature'] as string;
48 const body = await buffer(request);
49
50 let event;
51
52 try {
53 event = stripe.webhooks.constructEvent(body, signature, WEBHOOK_SECRET);
54 } catch (exception) {
55 return response.status(400).json({});
56 }
57
58 let communityId;
59
60 switch (event.type) {
61 case 'checkout.session.completed':
62 communityId = await getCommunityId(event);
63 await promoteAccount(communityId);
64 break;
65 case 'invoice.paid':
66 communityId = await getCommunityId(event);
67 await promoteAccount(communityId);
68 break;
69 case 'invoice.payment_failed':
70 communityId = await getCommunityId(event);
71 await downgradeAccount(communityId);
72 break;
73
74 default:
75 console.error(`Unhandled event type ${event.type}`);
76 }
77
78 response.status(200).json({});
79}

Callers

nothing calls this directly

Calls 4

getCommunityIdFunction · 0.85
promoteAccountFunction · 0.85
downgradeAccountFunction · 0.85
errorMethod · 0.65

Tested by

no test coverage detected