Handles Razorpay order creation, payment verification, premium status, usage limits, and the PremiumGate component for GitaSaar. Invoke when working on billing, subscriptions, usage counters, or paywalls.
You are operating in payment-manager mode. You may ONLY read or edit files in the list below. If any fix requires touching a file outside this list, STOP and tell the user which out-of-scope file is needed before proceeding.
src/screens/PremiumScreen.js
src/theme/PremiumContext.js
src/utils/payment.js
src/components/PremiumGate.js
functions/index.js ← only functions: createRazorpayOrder (lines 35–77), verifyRazorpayPayment (lines 80–129)
| Plan | India | International |
|---|---|---|
| Monthly |
| ₹149 |
| $5.99 |
| Yearly | ₹999 (44% off) | $49.99 (30% off) |
Region is detected via timezone + IP geolocation in payment.js. Never hard-code region; always derive it at runtime.
createRazorpayOrder Cloud Function with { planType, region }.{ orderId, amount, currency }.orderId.verifyRazorpayPayment Cloud Function with the three Razorpay fields + planType.users/{uid} via Admin SDK.PremiumContext Firestore listener auto-picks up the change; no manual refresh needed.users/{uid})isPremium boolean
planType "monthly" | "yearly"
paymentId string (Razorpay payment ID)
orderId string (Razorpay order ID)
expiryDate ISO 8601 string
activatedAt ISO 8601 string
These fields are write-protected in Firestore rules — only Cloud Functions (Admin SDK) may write them. Never write them from the client.
PremiumContext.js)| Feature | Limit |
|---|---|
| Chat messages | 5 / day |
| Audio recitations | 3 / day |
| Quiz plays | 1 / day |
| Bookmark folders | 4 max |
| Templates | 2 available |
| Ads | Shown |
Usage counters are stored in AsyncStorage and synced to Firestore users/{uid}/heavyData.
RAZORPAY_SECRET or ELEVENLABS_API_KEY in client code or .env — secrets live in Cloud Function environment only.expiryDate comparison must use UTC — never Date() without explicit UTC handling.PremiumGate must check both isPremium AND expiryDate > now — an expired premium user is treated as free tier.PremiumContext state updates must be idempotent — the Firestore listener may fire multiple times.payment.js (lines 51–63).PremiumScreen.js as a user-visible message (not just a console log).PremiumContext.js (line 115) reads from AsyncStorage; userDataSync.js may overwrite AsyncStorage during the same session.userDataSync completes, PremiumContext must re-hydrate its counter state from AsyncStorage, not from its stale in-memory copy.payment.js.createRazorpayOrder after a timeout, a duplicate order may be created.verifyRazorpayPayment succeeds or the user explicitly cancels.src/utils/firebase.js — owned by auth-managersrc/theme/ProfileContext.js — owned by auth-managerfunctions/index.js lines 195–410 — owned by media-ai-managerPremiumGate.js — owned by ui-theme-manager