Project 1 - Admin Panel
Admin Panel - Payments & Razorpay
The Admin Panel includes Razorpay for payments, plus orders, invoices, and a simple accounting view.
Overview
- Razorpay: Checkout and payment verification (with a dummy mode when credentials are not set).
- Orders: Created at checkout; linked to payments.
- Invoices: Manual creation and auto-generation after payment; PDF download.
- Accounting: List of transactions from Razorpay and manual invoices.
Setup
1. Dependencies
Already included in the project (e.g. razorpay, jspdf). If not:
npm install razorpay jspdf
2. Environment variables
Add to .env.local (optional for development):
RAZORPAY_KEY_ID=your_razorpay_key_id
RAZORPAY_KEY_SECRET=your_razorpay_key_secret
RAZORPAY_WEBHOOK_SECRET=your_webhook_secret
NEXT_PUBLIC_RAZORPAY_KEY_ID=your_razorpay_key_id
Without these, the app runs in dummy mode: checkout succeeds without real payment.
3. Database
Run the payments/invoices/accounting migration:
psql -d your_database -f supabase/migrations/add-payments-invoices-accounting.sql
This creates (or extends) tables such as: orders, order_items, payments, invoices, invoice_items, accounting_transactions.
Features
Checkout
- Route:
/checkout. - User adds items/amount and proceeds to payment.
- Dummy mode: Payment is auto-verified; no Razorpay dialog.
- Production: Razorpay checkout opens; after payment, webhook or verify API confirms and order/invoice are updated.
Orders
- List:
/orders(admins: all; users: own). - Detail:
/orders/[id](view, refund if supported).
Invoices
- List:
/invoices(filter by status: draft, sent, paid, overdue, cancelled). - Create:
/invoices/create– manual invoice with line items. - PDF: Download from invoice detail or list (e.g.
/invoices/[id]).
Accounting
- Route:
/accounting– view transactions (payments + manual invoice entries).
APIs (typical)
- Create order:
POST /api/payments/create-order. - Verify payment:
POST /api/payments/verify. - Webhook:
POST /api/payments/webhook(Razorpay webhook URL). - Invoices: e.g.
POST /api/invoices/create,GET /api/invoices/..., PDF generation via/api/invoices/generate-pdfor similar. - User orders:
GET /api/user/orders; user invoices:GET /api/user/invoices.
Production
- Set all Razorpay env vars and configure the webhook URL in the Razorpay dashboard.
- Use HTTPS and validate webhook signature using
RAZORPAY_WEBHOOK_SECRET. - Restrict create-order and verify to authenticated users and validate amounts/items.
For full details and field descriptions, see the project’s RAZORPAY_INTEGRATION.md in the admin-panel repo.