A modern, production-ready payment integration demo built with Next.js 15, Razorpay, and deployed on Cloudflare Workers using OpenNext. This project demonstrates secure payment processing with a clean, responsive UI and seamless user experience.
| Homepage | Payment Initialization | Payment Completed |
![]() |
![]() |
![]() |
- โ Secure Payment Processing - Integration with Razorpay's payment gateway
- โ Modern UI/UX - Clean, responsive design with smooth animations
- โ Real-time Feedback - Loading states and interactive button effects
- โ Edge Deployment - Deployed on Cloudflare Workers for global low-latency
- โ Type-Safe - Built with TypeScript for robust code quality
- โ Server-Side Order Creation - Secure API routes for payment order generation
- โ Responsive Design - Works seamlessly across all device sizes
- Framework: Next.js 15 (App Router)
- Runtime: React 19
- Payment Gateway: Razorpay
- Styling: Tailwind CSS 4
- Deployment: Cloudflare Workers via OpenNext
- Language: TypeScript
- Package Manager: Bun / npm
razorpay-next-app/
โโโ src/
โ โโโ app/
โ โโโ api/
โ โ โโโ create-order/
โ โ โโโ route.ts # API endpoint for order creation
โ โโโ globals.css # Global styles
โ โโโ layout.tsx # Root layout
โ โโโ page.tsx # Homepage with payment button
โโโ public/ # Static assets & screenshots
โโโ package.json
โโโ tsconfig.json
โโโ wrangler.jsonc # Cloudflare configuration
โโโ README.md
- Node.js 18+ or Bun
- Razorpay account (Sign up here)
- Cloudflare account (for deployment)
-
Clone the repository
git clone https://github.com/yourusername/razorpay-next-app.git cd razorpay-next-app -
Install dependencies
npm install # or bun install -
Set up environment variables
Create a
.envfile in the root directory:NEXT_PUBLIC_RAZORPAY_KEY_ID=your_razorpay_key_id
Create a
.dev.varsfile for local Cloudflare development:RAZORPAY_KEY_ID=your_razorpay_key_id RAZORPAY_KEY_SECRET=your_razorpay_key_secret
Note: Get your API keys from Razorpay Dashboard
-
Run the development server
npm run dev # or bun devOpen http://localhost:3000 to view the app.
-
Build and deploy
npm run deploy # or bun run deploy -
Set environment variables in Cloudflare
npx wrangler secret put RAZORPAY_KEY_ID npx wrangler secret put RAZORPAY_KEY_SECRET
npm run preview
# or
bun run preview- โ API keys are stored securely in environment variables
- โ Payment order creation happens server-side
- โ Amount validation on the backend
- โ Unique receipt IDs generated using nanoid
- โ HTTPS-only in production
- User clicks "Pay Now" button
- Frontend sends amount to
/api/create-order - Server creates a Razorpay order with unique receipt ID
- Razorpay checkout modal opens with order details
- User completes payment
- Payment success handler is triggered
// Secure server-side order creation
const order = await razorpay.orders.create({
amount: amount, // in paise
currency: "INR",
receipt: "receipt_" + nanoid(8)
});// Razorpay checkout initialization
const rzp1 = new window.Razorpay({
key: process.env.NEXT_PUBLIC_RAZORPAY_KEY_ID,
amount: order.amount,
currency: "INR",
order_id: orderId,
handler: () => console.log("Payment successful!")
});
rzp1.open();| Command | Description |
|---|---|
npm run dev |
Start development server with Turbopack |
npm run build |
Build for production |
npm run start |
Start production server |
npm run lint |
Run ESLint |
npm run preview |
Preview with Cloudflare runtime locally |
npm run deploy |
Build and deploy to Cloudflare Workers |
npm run cf-typegen |
Generate Cloudflare environment types |
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
This project is open source and available under the MIT License.
Bhaskar G
- Portfolio: bhaskar.guthula.cc
- GitHub: @Shisui-Genjutsu
- LinkedIn: LinkedIn


