QorelySofts
Store/Stripe & Razorpay Webhook Handler — Next.js App Router
🔥 Hero Flagship
Stripe & Razorpay Webhook Handler — Next.js App Router
v1.0.0🔥 Hero Flagship

Stripe & Razorpay Webhook Handler — Next.js App Router

Production-ready payment webhook handlers with cryptographic verification and atomic database rollback.

Drop-in Next.js App Router Route Handlers for both Stripe and Razorpay payment webhooks. Includes constant-time HMAC signature verification, replay-attack prevention, typed event handling for checkouts, subscriptions, and invoices, plus a generic transactional database wrapper with automatic commit and rollback. Includes drop-in Prisma ORM transaction adapter.

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

  1. npm install stripe (or razorpay)
  2. Add STRIPE_WEBHOOK_SECRET and RAZORPAY_WEBHOOK_SECRET to your .env.local
  3. Import createStripeRouteHandler / createRazorpayRouteHandler into app/api/webhooks
  4. Supply your database transaction adapter callback to fulfill customer orders atomically

Verified Compatibility & Requirements

✓ Next.js 14+ / 15 (App Router)✓ Node.js 18+ LTS✓ TypeScript 5+✓ Stripe SDK v14+✓ Razorpay API / Node SDK✓ Prisma ORM / Drizzle / Raw SQL
₹10

One-time purchase • Unlimited commercial use • Instant download

Instant ZIP package delivery after checkout
Encrypted token download link (active 48h)
Verified secure checkout via Razorpay
Full source code with zero obfuscation
Secured by Razorpay Payment Gateway
Supports UPI (GPay, PhonePe, Paytm), Cards & NetBanking
🔒 256-bit encrypted transaction • Official QorelySofts digital license

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
app/api/webhooks/stripe/route.ts
typescript
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.