POST (webhook/route.js)

awesome-generative-ai-apps · image_generation/ai-meme-generator/src/app/api/stripe/webhook/route.js · javascript · MIT
payments

Stripe webhook handler for Next.js API route, delegating to BillingService and returning JSON.

// Source: https://github.com/Anil-matcha/awesome-generative-ai-apps | License: MIT | Copyright 2023 Anil Chandra Naidu Matcha
// Provided via justclaw.it.com; keep this notice with the code.
import { NextResponse } from "next/server";
import { headers } from "next/headers";
import { BillingService } from "@/lib/services/billing";

export async function POST(req) {
  const body = await req.text();
  const signature = (await headers()).get("Stripe-Signature");

  try {
    const result = await BillingService.handleWebhook(body, signature);
    return NextResponse.json(result);
  } catch (error) {
    console.error("[STRIPE_WEBHOOK]", error);
    return new NextResponse(`Webhook Error: ${error.message}`, { status: 400 });
  }
}

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key