Webhooks
Handle Lumn webhook events in a Next.js route. This page shows code only (no run button). After configuring the webhook endpoint, Lumn will send signed requests to that URL.
typescript
import { Webhooks } from '@lumnsh/nextjs';
export const POST = Webhooks({ onCheckoutCompleted: async (payload) => { // Checkout completed: provision access, send email, etc. await provisionAccess(payload.customer_id); }, onPaymentSucceeded: async (payload) => { // Payment succeeded: confirm order, update quota await confirmPayment(payload.payment_id); }, onSubscriptionCreated: async (payload) => { // Subscription created: activate plan await activatePlan(payload.subscription_id); }, onSubscriptionCanceled: async (payload) => { // Subscription canceled: downgrade or grace period await handleCancellation(payload.subscription_id); },});Put the code above in app/api/webhooks/route.ts, and set the Webhook URL in the Lumn dashboard to https://your-domain.com/api/webhooks.