This contains everything you need to run your app locally.
Prerequisites: Node.js
- Install dependencies:
npm install - Set the
GEMINI_API_KEYin .env.local to your Gemini API key
Make sure your .env file contains valid Razorpay credentials:
RAZORPAY_KEY_ID=rzp_live_XXXXXXXXXXXXX
RAZORPAY_KEY_SECRET=your_actual_secret_key_here
VITE_RAZORPAY_KEY_ID=rzp_live_XXXXXXXXXXXXX- Start the development server:
npm run dev - Visit
http://localhost:3000/api/test-razorpayto test the connection - Add items to cart and try checkout
- 401 Authentication Error: Check your API keys in
.env - Payment Popup Not Opening: Ensure Razorpay script loads (check browser console)
- Signature Verification Failed: Backend secret key mismatch
- Go to Razorpay Dashboard
- Navigate to Settings → API Keys
- Copy your Live/Test keys (use Test keys for development)
After a successful payment, the system automatically handles receipt generation, database storage, and email notifications via Firebase Cloud Functions.
Ensure your firebase-config.js is initialized and the following logic is implemented in your checkout handler:
import { db } from './firebase';
import { collection, addDoc, serverTimestamp } from 'firebase/firestore';
const handlePaymentSuccess = async (response) => {
try {
// 1. Generate Receipt & Save to Firestore
const receiptData = {
orderId: response.razorpay_order_id,
paymentId: response.razorpay_payment_id,
amount: cartTotal,
currency: "INR",
status: "paid",
customerEmail: user.email,
createdAt: serverTimestamp(),
};
const docRef = await addDoc(collection(db, "receipts"), receiptData);
console.log("Receipt generated with ID: ", docRef.id);
// 2. Trigger Email Notification
// This is handled via Firebase Extensions or a Cloud Function
await triggerConfirmationEmail(receiptData);
} catch (error) {
console.error("Error processing post-payment:", error);
}
};To send emails, use the "Trigger Email from Firestore" extension or a Cloud Function:
Cloud Function (index.js):