"use client" import { useState } from "react" import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Check, X, ShieldCheck, Loader2, Minus, CheckCircle2 } from "lucide-react" import { useActiveUser } from "@/hooks/useActiveUser" const WEBHOOK_SECRET = "local_webhook_secret" export default function UpgradePage() { const { userId, loading: userLoading, refreshUser } = useActiveUser() const [loadingTier, setLoadingTier] = useState(null) const [showModal, setShowModal] = useState(false) const [orderData, setOrderData] = useState(null) const [processing, setProcessing] = useState(false) const [success, setSuccess] = useState(false) const handleUpgrade = async (tier: string) => { if (userLoading || !userId) return setLoadingTier(tier) try { const res = await fetch(`/api/billing/create-order?user_id=${userId}&plan_tier=${tier}`, { method: "POST" }) if (!res.ok) throw new Error("Order creation failed") const order = await res.json() setOrderData({ ...order, tier }) setShowModal(true) } catch (err) { console.error(err) alert("Failed to create order") } finally { setLoadingTier(null) } } const generateMockSignature = async (payloadStr: string) => { const encoder = new TextEncoder(); const key = await crypto.subtle.importKey( 'raw', encoder.encode(WEBHOOK_SECRET), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'] ); const signature = await crypto.subtle.sign('HMAC', key, encoder.encode(payloadStr)); return Array.from(new Uint8Array(signature)).map(b => b.toString(16).padStart(2, '0')).join(''); } const simulatePayment = async () => { if (!userId) return setProcessing(true) try { const payloadObj = { event: "payment.captured", payload: { payment: { entity: { id: `pay_mock_${Date.now()}`, amount: orderData.amount, notes: { user_id: userId, tier_requested: orderData.tier } } } } } const payloadStr = JSON.stringify(payloadObj) const signature = await generateMockSignature(payloadStr) const res = await fetch(`/api/billing/webhook/razorpay`, { method: "POST", headers: { "Content-Type": "application/json", "X-Razorpay-Signature": signature }, body: payloadStr }) if (!res.ok) throw new Error("Webhook failed") setSuccess(true) await refreshUser() setTimeout(() => { window.location.href = "/dashboard" }, 2000) } catch (err) { console.error(err) alert("Payment simulation failed") setProcessing(false) } } return (

Upgrade Your Preparation

Unlock the full power of PragatiVeer to master JEE & NEET.

{/* Free Tier

Free

Perfect to get started.

₹0/year
  • 1 Daily Practice Sheet
  • Basic Performance Analytics
  • Community Access
*/} {/* Pro Tier */}

Pro

Perfect for self-paced practice.

₹3,499/year
  • Unlimited Daily Practice Sheets
  • Weekly Test Series & Mock Tests
  • Detailed Performance Analytics
  • Parent Dashboard Access
{/* AI Coach Tier */}

AI Coach

The complete AI-driven system.

₹11,999/year
  • Everything in Pro
  • AI Spaced Repetition (Mistakes)
  • 24/7 Streaming AI Tutor Chat
  • Predictive Rank & College Predictor

* All above prices are inclusive of GST.

{/* ── Tier Comparison Matrix ── */}

Compare All Features

Detailed breakdown of capabilities across Free, Pro, and AI Coach tiers.

{/* */} {[ { name: "Daily Practice Sheets", free: "1/day", pro: "Unlimited", ai: "Unlimited" }, { name: "Answer Keys", free: true, pro: true, ai: true }, { name: "Basic Progress Dashboard", free: true, pro: true, ai: true }, { name: "Streak Tracking", free: true, pro: true, ai: true }, { name: "Leaderboard (City/School)", free: true, pro: true, ai: true }, { name: "Topic-wise Micro-tests", free: "5/day", pro: "Unlimited", ai: "Unlimited" }, { name: "Weekly Test Series", free: false, pro: true, ai: true }, { name: "Full-Length Mock Tests", free: false, pro: "4/month", ai: "Unlimited" }, { name: "Previous Year Papers", free: false, pro: true, ai: true }, { name: "Detailed Performance Analytics", free: false, pro: true, ai: true }, { name: "Chapter-wise Progress", free: false, pro: true, ai: true }, { name: "Doubt Resolution (Community)", free: false, pro: true, ai: true }, { name: "Parent Dashboard", free: false, pro: true, ai: true }, { name: "Offline Mode (Download DPS)", free: false, pro: true, ai: true }, { name: "AI Mistake Tracking", free: false, pro: false, ai: true }, { name: "Spaced Repetition (SM-2)", free: false, pro: false, ai: true }, { name: "Personalized Daily Study Plan", free: false, pro: false, ai: true }, { name: "AI Tutor Chat", free: false, pro: false, ai: true }, { name: "Exam Readiness Score", free: false, pro: false, ai: true }, { name: "Exam Day Strategy", free: false, pro: false, ai: true }, { name: "College Predictor", free: false, pro: false, ai: true }, { name: "Study Time Optimization", free: false, pro: false, ai: true }, ].map((feature, idx) => ( {/* */} ))}
FeatureFreePro AI Coach
{feature.name} {typeof feature.free === 'boolean' ? (feature.free ? : ) : {feature.free}} {typeof feature.pro === 'boolean' ? (feature.pro ? : ) : {feature.pro}} {typeof feature.ai === 'boolean' ? (feature.ai ? : ) : {feature.ai}}
{/* Mock Razorpay Modal */} {showModal && (
RZP
Mock Checkout Window Razorpay Test Sandbox Simulation
Order ID: {orderData?.id}
Amount: ₹{(orderData?.amount / 100).toFixed(2)}
Tier: {orderData?.tier}
{success ? (
Payment Captured! Redirecting...
) : (

Clicking confirm will securely sign and POST a payment.captured webhook to the backend.

)}
)}
) }