79776766

Date: 2025-09-27 12:42:30
Score: 3
Natty:
Report link

I tried to follow the same, via firebase but I have the same issue

async subscribe(product, priceId, wid) {
    const uid = auth.currentUser?.uid;
    if (!uid) throw new Error('User must be authenticated to subscribe.');
    if (!product) throw new Error('Product is required for subscription.');
    if (!priceId) throw new Error('Price ID is required for subscription.');
    if (!wid) throw new Error('Workspace ID is required for subscription.');

    const checkoutRef = collection(db, 'customers', uid, 'checkout_sessions');
    const path = window.location.pathname;
    const docRef = await addDoc(checkoutRef, {
      mode: 'subscription',
      price: priceId,
      success_url: `${window.location.origin}${path}?subscription=success&tier=${product.metadata?.tier}&wid=${wid}`,
      cancel_url: `${window.location.origin}${path}?subscription=cancelled`,
      subscription_data: {
        description: `Workspace: ${wid}`,
      },
    });

    // Listen for the checkout session URL to be populated by Firebase Extension
    return new Promise((resolve, reject) => {
      const unsubscribe = onSnapshot(
        docRef,
        snapshot => {
          const data = snapshot.data();

          if (data?.url) {
            // URL is available, redirect to Stripe Checkout
            unsubscribe();
            window.location.assign(data.url);
            resolve({ id: docRef.id, url: data.url });
          } else if (data?.error) {
            // Error occurred in Firebase Extension
            unsubscribe();
            reject(new Error(data.error.message));
          }
        },
        error => {
          unsubscribe();
          reject(new Error(error.message));
        }
      );

      // Set a timeout to prevent infinite waiting
      setTimeout(() => {
        unsubscribe();
        reject(new Error('Subscription creation timed out. Please try again.'));
      }, 30000); // 30 seconds timeout
    });
  }
Reasons:
  • Blacklisted phrase (1): I have the same issue
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): I have the same issue
  • Low reputation (1):
Posted by: YumiBakura