(request: NextRequest)
| 2 | import { type NextRequest, NextResponse } from "next/server"; |
| 3 | |
| 4 | export async function POST(request: NextRequest) { |
| 5 | try { |
| 6 | const url = new URL(request.url); |
| 7 | const workflowId = url.searchParams.get("workflowId"); |
| 8 | |
| 9 | if (!workflowId) { |
| 10 | return NextResponse.json( |
| 11 | { success: false, error: "Missing required query parameter: workflowId" }, |
| 12 | { status: 400 }, |
| 13 | ); |
| 14 | }; |
| 15 | |
| 16 | const body = await request.json(); |
| 17 | |
| 18 | const stripeData = { |
| 19 | // Event metadata |
| 20 | eventId: body.id, |
| 21 | eventType: body.type, |
| 22 | timestamp: body.created, |
| 23 | livemode: body.livemode, |
| 24 | raw: body.data?.object, |
| 25 | }; |
| 26 | |
| 27 | // Trigger an Inngest job |
| 28 | await sendWorkflowExecution({ |
| 29 | workflowId, |
| 30 | initialData: { |
| 31 | stripe: stripeData, |
| 32 | }, |
| 33 | }); |
| 34 | |
| 35 | return NextResponse.json( |
| 36 | { success: true }, |
| 37 | { status: 200 }, |
| 38 | ); |
| 39 | } catch (error) { |
| 40 | console.error("Stripe webhook error:" , error); |
| 41 | return NextResponse.json( |
| 42 | { success: false, error: "Failed to process Stripe event" }, |
| 43 | { status: 500 }, |
| 44 | ); |
| 45 | } |
| 46 | }; |
nothing calls this directly
no test coverage detected