Next Adapter
Mount Paymesh webhooks in Next.js App Router with a native route handler that stays tiny while still exposing the full normalized hook surface.
Installation
npm install @paymesh/nextBasic usage
import { Webhooks } from "@paymesh/next";
import { paymesh } from "@/lib/paymesh";
export const POST = Webhooks({
client: paymesh,
async onPaymentSucceeded(event) {
console.log("payment.succeeded", event.data.id);
},
});What the adapter does
The Next adapter:
- accepts a configured
client - forwards the incoming
Requestintoclient.webhooks.handle() - returns
Response.json(result.body, { status: result.status }) - lets you declare the same hook map you would pass directly to the core webhook handler
That means the adapter is intentionally thin. All normalization, verification, persistence, and hook dispatch stay inside the core client.
Including raw payloads
If your route logic needs provider payloads directly, enable includeRaw.
export const POST = Webhooks({
client: paymesh,
includeRaw: true,
async onEvent(event) {
console.log(event.raw);
},
});Use that only when you need it. Most application logic should stay on normalized fields.
When to choose this adapter
Use @paymesh/next when:
- your app uses the App Router
- you want one-file webhook routes
- you want route handlers that stay boring and defer all billing behavior into Paymesh