A modern subscription management platform built with Next.js 15, featuring secure payment processing with Razorpay and Google OAuth authentication.
-
Authentication System
- Google OAuth integration with NextAuth.js
- Google One Tap login support
- Secure session management with MongoDB adapter
-
Payment Integration
- Razorpay payment gateway integration
- Secure payment verification with HMAC signature validation
- Multiple subscription plans (Basic, Professional, Business)
- Real-time payment status updates
- Payment history with invoice generation
- PDF invoice downloads for completed transactions
- Advanced rate limiting protection for payment endpoints
-
Dashboard & UI
- Modern, responsive dashboard with Framer Motion animations
- Dark/Light theme support
- Real-time subscription status display
- Account management interface
- Custom error pages (404, 500)
- Interactive plan comparison table
-
User Management
- Account settings page with profile updates
- Subscription management and billing history
- Account deletion with GDPR compliance
- User preferences management
-
Support System
- Beautiful contact form with glass morphism design
- Email notifications via Resend
- User information auto-populated in support requests
- Direct email communication channel
-
Database Integration
- MongoDB for user and subscription data
- Optimized database queries with proper ObjectId handling
- Session-based user plan updates
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS 4
- Animation: Framer Motion
- Authentication: NextAuth.js with Google OAuth
- Database: MongoDB with official Node.js driver
- Payments: Razorpay
- Email: Resend for transactional emails
- PDF Generation: jsPDF with jsPDF-AutoTable
- UI Components: Shadcn/ui, Lucide React icons
- Styling: Tailwind CSS with custom theme support
- Notifications: Sonner for toast notifications
- Rate Limiting: Upstash Redis with @upstash/ratelimit for production-grade API protection
src/
├── app/
│ ├── api/
│ │ ├── auth/[...nextauth]/ # NextAuth configuration
│ │ ├── payments/ # Payment API routes
│ │ │ ├── create-order/ # Order creation
│ │ │ ├── verify-payment/ # Payment verification
│ │ │ ├── history/ # Payment history
│ │ │ └── invoice/ # PDF invoice generation
│ │ ├── user/ # User management APIs
│ │ │ ├── update-profile/ # Profile updates
│ │ │ └── delete-account/ # Account deletion
│ │ └── support/ # Support system
│ │ └── send-message/ # Email support requests
│ ├── dashboard/ # User dashboard
│ │ ├── billing/ # Payment history & invoices
│ │ ├── settings/ # Account settings
│ │ └── support/ # Support contact page
│ ├── login/ # Login page
│ ├── error.tsx # Global error handler
│ └── not-found.tsx # 404 page
├── components/
│ ├── auth/ # Authentication components
│ ├── dashboard/ # Dashboard comparison table
│ ├── providers/ # React providers
│ ├── theme/ # Theme toggle components
│ └── ui/ # Reusable UI components
└── lib/ # Utility functions and configurations
├── mongodb.ts # MongoDB client configuration
├── razorpay.ts # Razorpay client setup
└── rate-limit.ts # Rate limiting configuration
-
Clone the repository
git clone https://github.com/yourusername/next-pay-flow.git cd next-pay-flow -
Install dependencies
npm install
-
Environment Variables Create a
.envfile in the root directory with the following variables:# MongoDB Configuration MONGODB_URI=your-mongodb-connection-string # Google OAuth (Server-side) GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret # Google OAuth (Client-side - Only Client ID is safe to expose) NEXT_PUBLIC_GOOGLE_CLIENT_ID=your-google-client-id # NextAuth Configuration NEXTAUTH_SECRET=your-nextauth-secret-key # Razorpay Configuration RAZORPAY_KEY_ID=your-razorpay-key-id RAZORPAY_KEY_SECRET=your-razorpay-secret-key NEXT_PUBLIC_RAZORPAY_KEY_ID=your-razorpay-key-id RAZORPAY_WEBHOOK_SECRET=your-webhook-secret (optional) # Email Configuration (Resend) RESEND_API_KEY=your-resend-api-key # Upstash Redis Configuration (for Rate Limiting) UPSTASH_REDIS_REST_URL=your-upstash-redis-url UPSTASH_REDIS_REST_TOKEN=your-upstash-redis-token # Application Environment NODE_ENV=development
Important Notes:
- Get Resend API key from: https://resend.com (Free tier: 3,000 emails/month)
- Get Google OAuth credentials from: https://console.cloud.google.com
- Get Razorpay keys from: https://dashboard.razorpay.com
- Get Upstash Redis credentials from: https://upstash.com (Free tier: 10,000 requests/day)
- Never expose
GOOGLE_CLIENT_SECRETorRAZORPAY_KEY_SECRETto the client - Generate
NEXTAUTH_SECRETusing:openssl rand -base64 32
Setting up Upstash Redis:
- Go to https://upstash.com and create a free account
- Create a new Redis database (select any region close to you)
- Copy the
UPSTASH_REDIS_REST_URLandUPSTASH_REDIS_REST_TOKENfrom the database details - Add them to your
.envfile
-
Run the development server
npm run dev
-
Open your browser Navigate to
http://localhost:3000
- Integrated NextAuth.js with MongoDB adapter for persistent sessions
- Custom session callbacks to include user subscription data
- Google OAuth and Google One Tap for seamless login experience
- Secure order creation with Razorpay API
- Client-side payment modal integration
- Server-side payment verification using HMAC signatures
- Automatic user plan updates upon successful payment
- User documents with embedded subscription objects
- Proper ObjectId handling for MongoDB queries
- Session-based real-time data updates
- CSRF protection with NextAuth
- Payment signature verification
- Environment variable protection for sensitive data
- Secure API route implementations
- Production-grade rate limiting with Upstash Redis
- Serverless-compatible - Works perfectly in Vercel/Netlify/AWS Lambda
- User-based rate limiting for authenticated endpoints (prevents per-user abuse)
- IP-based rate limiting for public endpoints (webhook protection)
- Sliding window algorithm - More accurate than fixed windows
- Configurable limits per endpoint:
- Create Order: 5 requests/minute per user
- Verify Payment: 10 requests/minute per user
- Webhook: 100 requests/minute per IP
- Advanced headers:
Retry-After,X-RateLimit-Limit,X-RateLimit-Reset - Built-in analytics for monitoring rate limit hits
/api/auth/*- NextAuth endpoints (sign in, sign out, session)
POST /api/payments/create-order- Create Razorpay order (Rate limited: 5 req/min per user)POST /api/payments/verify-payment- Verify and process payment (Rate limited: 10 req/min per user)GET /api/payments/history- Get user payment historyPOST /api/payments/invoice- Generate and download PDF invoicePOST /api/payments/webhook- Handle Razorpay webhooks (Rate limited: 100 req/min per IP)
POST /api/user/update-profile- Update user profile informationDELETE /api/user/delete-account- Delete user account (GDPR compliant)
POST /api/support/send-message- Send support request via email
The application is ready for deployment on platforms like Vercel, with proper environment variable configuration for production MongoDB and Razorpay credentials.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
MIT License - see LICENSE file for details