अपने AI वेब ऐप में Stripe सब्सक्रिप्शन जोड़ें
Stripe सब्सक्रिप्शन (मासिक और वार्षिक) जोड़कर अपने AI वेब ऐप को मोनेटाइज़ करें।
रोडमैप और संसाधन
आवश्यकताएँ (शुरू करने से पहले)
पूर्व-आवश्यकता चेकलिस्ट
सुनिश्चित करें कि शुरू करने से पहले आपके पास ये तैयार हैं।
इस Stripe ट्यूटोरियल का पालन करने से पहले, सुनिश्चित करें कि आपके वेब ऐप में पहले से निम्न तैयार हैं:
1. आपका ऐप पहले से डिप्लॉय है (लाइव URL आवश्यक)
Stripe Checkout केवल एक वास्तविक डिप्लॉय की गई वेबसाइट पर काम करता है — यह Google AI Studio प्रीव्यू एनवायरनमेंट के अंदर काम नहीं करता।
डिप्लॉयमेंट वीडियो
डिप्लॉयमेंट ट्यूटोरियल देखें
https://youtu.be/HGs-4QjyjHQ?si=EBUOpPx38n9vVROR
---
2. Firebase पूरी तरह से सेट अप है (एक वीडियो सब कुछ कवर करता है)
आपका Firebase सेटअप पहले से पूरा होना चाहिए, जिसमें शामिल हैं: - Firebase Authentication सक्षम - Firestore Database बनाया गया - आपका वेब ऐप Firebase से जुड़ा (आपके Firebase कॉन्फ़िग का उपयोग करके)
Firebase सेटअप वीडियो
Firebase ट्यूटोरियल देखें
https://youtu.be/juEfJERgBE8?si=je5VF4gKMUJXl8kX
---
✔ एक बार ये आवश्यकताएँ तैयार हो जाएँ, आप बिना किसी समस्या के Step 1 → Step 5 के साथ जारी रख सकते हैं।
मासिक और वार्षिक सब्सक्रिप्शन प्लान बनाएँ
Stripe खोलें और Test Mode पर स्विच करें
एक मासिक आवर्ती सब्सक्रिप्शन प्लान बनाएँ
एक वार्षिक आवर्ती सब्सक्रिप्शन प्लान बनाएँ
बाद में उपयोग के लिए आवश्यक Stripe मान सहेजें
अपने ऐप से Stripe Payments कनेक्ट करें
Firebase → Extensions खोलें
"Run Payments with Stripe" इंस्टॉल करें (Invertase द्वारा बनाया गया)
अपना Stripe Secret Key एक्सटेंशन सेटिंग्स में पेस्ट करें
Stripe में एक Webhook बनाएँ (आवश्यक ईवेंट्स चुनें)
- checkout.session.completed
- customer.subscription.created
- invoice.paid
- invoice.payment_failed
- customer.subscription.updated
- customer.subscription.deleted
- invoice.upcoming
- payment_intent.succeeded
- payment_intent.payment_failed
- customer.subscription.paused
- charge.refunded
- charge.dispute.created
Firebase Functions से Webhook Endpoint URL कॉपी करें और इसे Stripe में पेस्ट करें
Stripe का Signing Secret कॉपी करें और इसे Firebase में पेस्ट करें (Webhook Secret)
सहेजें और पुष्टि करें कि सब कुछ जुड़ा है
भुगतान सफलता और रद्द पृष्ठ सेट अप करें
Google AI Studio में अपना प्रोजेक्ट खोलें
Prompt #1 चलाएँ: Billing कॉन्फ़िग बनाएँ (डिप्लॉय URL + Price IDs)
Prompt: Billing कॉन्फ़िग बनाएँ
एक billing config फ़ाइल बनाएँ और इसे मेरे वास्तविक मानों से भरें…
Create a billing config file and fill it with my real values (no placeholders). Use EXACTLY: DEPLOYED_URL = "https://deployment-url.com" MONTHLY_PRICE_ID = "price_MONTHLY_HERE" YEARLY_PRICE_ID = "price_YEARLY_HERE" Create: src/billingConfig.js (or .ts if the project is TypeScript) and export: - DEPLOYED_URL - MONTHLY_PRICE_ID - YEARLY_PRICE_ID - A function successUrl() that returns the correct URL for /success - A function cancelUrl() that returns the correct URL for /failure Important: - Detect if the app uses hash routing automatically: If existing routes contain "/#/" then use DEPLOYED_URL + "/#/success" and "/#/failure" Otherwise use DEPLOYED_URL + "/success" and "/failure" Do not change any existing UI or app logic. Return only the new file content.
Prompt #2 चलाएँ: सफलता + रद्द पृष्ठ बनाएँ
Prompt: सफलता और रद्द पृष्ठ बनाएँ
Stripe रीडायरेक्ट्स के लिए दो सरल रूट्स/पेज जोड़ें…
Add two simple routes/pages for Stripe redirects: success and failure. Success page: - Text: "Payment successful" - Redirect to dashboard after 1.5 seconds Failure page: - Text: "Payment cancelled" - Redirect to dashboard after 1.5 seconds Use the same routing style already used in the project (hash or normal). Do not redesign UI. Return exact files changed.
प्रॉम्प्ट्स चलाएँ और पुष्टि करें कि फ़ाइलें/पेज जोड़े गए हैं
Upgrade बटन को Stripe Checkout खोलने दें
(वैकल्पिक) एक Upgrade बटन बनाएँ
Prompt #3 चलाएँ: मासिक/वार्षिक विकल्प मोडल जोड़ें
Prompt: Upgrade Choice UI जोड़ें
ऐप को फिर से डिज़ाइन किए बिना एक सरल upgrade choice UI जोड़ें…
Add a simple upgrade choice UI without redesigning the app. When the user clicks the existing Upgrade button: - Show a small modal (or dropdown) with 2 options: 1) Monthly 2) Yearly - Add a close button. Keep current styling. Do not change any other UI. Return exact files changed.
Prompt #4 चलाएँ: विकल्प को Stripe Checkout से जोड़ें
Prompt: Stripe Checkout कनेक्ट करें
Firebase Stripe Extension का उपयोग करके Stripe सब्सक्रिप्शन चेकआउट लागू करें…
Implement Stripe subscription checkout using Firebase Stripe Extension. On Monthly selection: - Create a Firestore doc at: customers/{uid}/checkout_sessions/{autoId} - Fields: price: MONTHLY_PRICE_ID (import from billingConfig) mode: "subscription" success_url: successUrl() (import from billingConfig) cancel_url: cancelUrl() (import from billingConfig) On Yearly selection: - Same but price: YEARLY_PRICE_ID After creating the doc: - Listen to that same checkout session document until it contains a field "url" - Redirect the browser to that url Do not add Stripe secret keys to frontend. Do not touch existing CRUD features. Return exact files changed. Test payments using your deployed live URL (not the preview)
अपनी डिप्लॉय की गई लाइव URL का उपयोग करके भुगतान का परीक्षण करें
Prompt #5 चलाएँ: खाते को स्वचालित रूप से Free → Pro में अपडेट करें
Prompt: Pro Plan डिटेक्शन
Firestore से Pro प्लान डिटेक्शन (केवल पढ़ने) जोड़ें…
Add Pro plan detection (read-only) from Firestore. - Listen in real-time (onSnapshot) to: customers/{uid}/subscriptions - Set isPro = true if any subscription status is "active" or "trialing" - If isPro true: - Show a "Pro" badge - Hide the Upgrade button - If isPro false: - Show a "Free" badge - Show the Upgrade button Important: Do NOT block Free users from using the app features. Do not redesign UI. Return exact files changed.
Prompt #6 चलाएँ: Manage Subscription जोड़ें और इसे Stripe Billing Portal से जोड़ें
Prompt: Manage Subscription बटन
कार्य: PRO उपयोगकर्ताओं के लिए एक काम करने वाला "Manage Subscription" बटन जोड़ें…
Task: Add a working "Manage Subscription" button for PRO users using Stripe Customer Portal (Firebase Stripe Extension). Context: - The app already uses the Firebase Stripe Extension (customers/{uid} and checkout_sessions work). - The app uses hash routing (/#/dashboard). - Do NOT change the UI design. Only add logic. - The button must work in production (no CORS errors). Requirements: 1) Show "Manage Subscription" button ONLY when the current user is PRO (isPro === true). 2) On click, DO NOT call any cloudfunctions.net URL directly and DO NOT use fetch to Cloud Functions. 3) Instead, create a Firestore document at: customers/{uid}/portal_sessions/{autoId} with fields: - return_url: "https://vloma.com/#/dashboard" 4) After creating the doc, listen in real-time to that same document until the extension writes a field: - url Then redirect the browser to that url (window.location.href = url). 5) Add basic UX: - disable the button while loading - show a friendly alert if no url appears after 20 seconds - log the real error to console Implementation notes: - Use the existing Firebase client (auth + firestore). - Keep existing files structure. Modify only the minimal files needed. - Return the exact files changed and the exact code changes. Deliverable: - A working Manage Subscription button that opens Stripe Customer Portal and returns to /#/dashboard.
Free vs Pro सीमाएँ जोड़ें (वास्तविक SaaS सेटअप)
Prompt #7 चलाएँ: Free vs Pro सीमाएँ जोड़ें
Prompt: उपयोग सीमाएँ जोड़ें
कार्य: मौजूदा billing/upgrade सिस्टम को छुए या बदले बिना Free/Pro उपयोग सीमाएँ जोड़ें…
Task: Add Free/Pro usage limits WITHOUT touching or changing the existing billing/upgrade system. CRITICAL RULES (must follow): - DO NOT modify the existing Stripe checkout / upgrade code. - DO NOT modify how "isPro" is determined in the project. - DO NOT create or use users/{uid}.plan field (do not add plan to Firestore at all). - DO NOT change Firestore rules or Storage rules. - Keep UI the same (only small toast/alert/modal allowed). Limits: - FREE: max 5 files, max 5 folders, max 100MB total stored - PRO: max 50 files, max 50 folders, max 5GB total stored How to implement (safe approach): 1) Use the CURRENT existing "isPro" boolean/state already working in the app. - Whatever source it currently uses (Stripe Extension subscriptions / custom claims / existing code), keep it exactly as-is. - Only READ isPro, do not re-implement it. 2) Track usage from the existing Firestore structure (do not rename collections): - Files count = number of docs in users/{uid}/files - Folders count = number of docs in users/{uid}/folders - Total storage used = sum of file sizes from the file docs (field: size bytes). If old docs don’t have size, treat missing size as 0, and ensure new uploads always write size. 3) Enforce limits ONLY in the UI/Client for now: - Before creating a new file doc or uploading: check limits using current isPro. - Before creating a new folder doc: check limits using current isPro. - If Free exceeds limit: block action and show: “Free plan limit reached. Upgrade to Pro to continue.” Add an “Upgrade” button that triggers the EXISTING checkout flow (call the same function already used in the app). 4) IMPORTANT: After checkout completes, the app MUST refresh/reflect Pro automatically: - Do not add new plan logic. - Just ensure the same existing listener/state updates isPro and the UI re-checks limits. - Add a small debug log (console.log) showing current isPro value after returning from checkout. Deliverable: - Limits work and show upgrade prompt. - Paying and upgrading still changes the app to Pro exactly like before. - Return exact files changed.
Firestore नियम जोड़ें (उपयोगकर्ता केवल अपने स्वयं के डेटा तक पहुँच सकते हैं)
महत्वपूर्ण: ये Firestore सुरक्षा नियम एक उदाहरण हैं। आपको इनकी समीक्षा करनी होगी और अपने स्वयं के वेब ऐप की डेटा संरचना से मेल खाने के लिए इन्हें अनुकूलित करना होगा। हर ऐप को अपने विशिष्ट कलेक्शन और डेटा मॉडल के अनुकूल नियमों की आवश्यकता होती है।
firestore.rules
rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { function signedIn() { return request.auth != null; } function isOwner(uid) { return signedIn() && request.auth.uid == uid; } // ------------------------- // Users data (your app data) // ------------------------- match /users/{uid} { allow read, write: if isOwner(uid); // Everything under this user is also only for the owner match /{allPaths=**} { allow read, write: if isOwner(uid); } } // ------------------------- // Stripe Extension // customers/{uid}/... // ------------------------- match /customers/{uid} { // user can read their stripe docs allow read: if isOwner(uid); // user must NOT write to stripe docs directly allow write: if false; // user can create a checkout session doc match /checkout_sessions/{id} { allow create, read: if isOwner(uid); allow update, delete: if false; } // user can create a portal session doc match /portal_sessions/{id} { allow create, read: if isOwner(uid); allow update, delete: if false; } // subscriptions/payments are server-controlled (read only) match /subscriptions/{id} { allow read: if isOwner(uid); allow write: if false; } match /payments/{id} { allow read: if isOwner(uid); allow write: if false; } } } }
Storage नियम जोड़ें (उपयोगकर्ता केवल अपनी स्वयं की फ़ाइलों तक पहुँच सकते हैं)
महत्वपूर्ण: ये Storage सुरक्षा नियम एक उदाहरण हैं। आपको इनकी समीक्षा करनी होगी और अपने स्वयं के प्रोजेक्ट पथ (उदाहरण के लिए, uploads फ़ोल्डर नाम) और सीमाओं से मेल खाने के लिए इन्हें अनुकूलित करना होगा। हर ऐप को अपनी संरचना के अनुकूल storage नियमों की आवश्यकता होती है।
storage.rules
rules_version = '2'; service firebase.storage { match /b/{bucket}/o { function signedIn() { return request.auth != null; } function isOwner(uid) { return signedIn() && request.auth.uid == uid; } match /user_uploads/{uid}/{allPaths=**} { allow read: if isOwner(uid); // write create/update/delete // request.resource null delete، allow write: if isOwner(uid) && (request.resource == null || request.resource.size <= 200 * 1024 * 1024); } } }
(वैकल्पिक) छोटे UI सुधारों के लिए एक त्वरित प्रॉम्प्ट चलाएँ (उदाहरण के लिए, मोडल में कीमतें अपडेट करना)
आप UI विवरण को पॉलिश करने के लिए बाद में एक अतिरिक्त प्रॉम्प्ट चला सकते हैं (जैसे मोडल में कीमतें अपडेट करना), लेकिन हम यहाँ एक विशिष्ट प्रॉम्प्ट प्रदान नहीं करेंगे क्योंकि यह आपके विशिष्ट UI अनुकूलन पर बहुत निर्भर करता है।