Stripe & Razorpay Webhook Handler — Next.js App Router
Production-ready payment webhook handlers with cryptographic verification and atomic database rollback.
Key Capabilities & Architecture
Dual-Provider Unified Architecture
Seamless Next.js App Router route handlers for both Stripe and Razorpay in a single typed package.
Timing-Safe Cryptography
Eliminates timing attack vectors with crypto.timingSafeEqual and defends against replay attacks with configurable tolerance windows.
Automatic Transaction Rollback
Database state rolls back automatically if your fulfillment handler throws an error, preventing partial writes and phantom orders.
Pluggable ORM Adapter
Includes drop-in transaction adapters for Prisma ORM, Drizzle, Kysely, Knex, or raw SQL connection pools.
Quick Setup & Installation Instructions
- npm install stripe (or razorpay)
- Add STRIPE_WEBHOOK_SECRET and RAZORPAY_WEBHOOK_SECRET to your .env.local
- Import createStripeRouteHandler / createRazorpayRouteHandler into app/api/webhooks
- Supply your database transaction adapter callback to fulfill customer orders atomically
Verified Compatibility & Requirements
One-time purchase • Unlimited commercial use • Instant download
Included in Your Download ZIP
- └─src/webhooks/stripe-handler.ts
- └─src/webhooks/razorpay-handler.ts
- └─src/adapters/prisma-adapter.ts
- └─src/lib/verify-signature.ts
- └─src/lib/transaction-wrapper.ts
- └─src/types/index.ts
- └─src/index.ts
- └─README.md
- └─.env.example
import { createStripeRouteHandler, createPrismaTransactionAdapter } from 'stripe-razorpay-webhooks-handler';
import { prisma } from '@/lib/db';
export const POST = createStripeRouteHandler({
transactionAdapter: createPrismaTransactionAdapter(prisma),
callbacks: {
'checkout.session.completed': async (event, ctx) => {
const session = event.data.object;
// Atomic DB update within managed transaction
await ctx.client.order.update({
where: { stripeSessionId: session.id },
data: { status: 'PAID', paidAt: new Date() }
});
}
}
});Frequently Asked Questions
Technical specifics and licensing details for this product.
How does it prevent duplicate webhook executions?
The handler verifies idempotency and includes callback hooks to check existing order states, returning HTTP 200 immediately if an event has already been fulfilled.
Does it work with Razorpay Subscriptions and UPI?
Yes. It handles subscription.activated, subscription.charged, order.paid, payment.authorized, and payment.captured events.
What happens if our database is temporarily unreachable?
The transaction wrapper triggers rollback and returns HTTP 500, instructing Stripe and Razorpay to retry the webhook delivery automatically.