Skip to content

Unable to call createCheckoutSession: FirebaseError: Expected first argument to collection() to be a CollectionReference #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
logesh2496 opened this issue Oct 2, 2023 · 8 comments

Comments

@logesh2496
Copy link

Bug report

  • Extension name: firestore-stripe-payments

Describe the bug

Tried to call the function await createCheckoutSession(payments, { price: priceId, // One-time price created in Stripe }); after setting up the firebase extension. Customer and Product collections are properly set and working as expected except the createCheckSession.
Encountered the error:
Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore

To Reproduce

Simply call the createCheckoutSession by following the "How this extension works" documentation from firebase extensions

Expected behavior

I should be able to get the session url from the method

Screenshots

image
@antopolskiy
Copy link

What is your version of firebase? I get this error when I try to update my firebase package to >v10.0.0

Btw, are there plans to update the firebase dependency so that it works with the newest version?

@logesh2496
Copy link
Author

Yes, My version is v10.0.0.
What version should I downgrade to get it fixed temporarily?

@antopolskiy
Copy link

Yes, using v9 seems to do the trick for me. However, if I use v9, there is another issue that appears which is #509

I describe the workaround I've found that works at the moment. Though I hope the extension SDK will soon be updated to firebase v10.

@antopolskiy
Copy link

antopolskiy commented Oct 2, 2023

@logesh2496 Actually, I was just able to solve the issue in a better way using this thread #304

Here are the relevant parts of my package.json:

  "dependencies": {
    "@invertase/firestore-stripe-payments": "^0.0.7",
    "firebase": "^9.18.0",
  },
  "resolutions": {
    "@firebase/firestore": "3.13.0",
    "@firebase/auth": "0.23.2",
    "@firebase/app": "0.9.13"
  },

Then yarn install worked like a charm.

@logesh2496
Copy link
Author

gotcha, thanks @antopolskiy your issue explains it better, so closing this one.

@logesh2496
Copy link
Author

logesh2496 commented Oct 2, 2023

BTW, this is another workaround I was using:

const col = collection(db, DB_NAME, uid, SUB_DB_NAME);
  const docRef = await addDoc(col, {
    mode: "payment",
    price: import.meta.env.VITE_STRIPE_PRICE, // One-time price created in Stripe
    success_url: ...,
    cancel_url: ...,
  });

  const url = await new Promise((res) => {
    const unsub = onSnapshot(
      doc(db, DB_NAME, uid, SUB_DB_NAME, docRef.id),
      (doc) => {
        const data = doc.data();
        if (data.url) {
          unsub();
          res(data.url);
        }
      }
    );
  });

@agoransson
Copy link

This PR helped me #645

@maztak
Copy link

maztak commented Apr 25, 2025

In my case, dependencies version may affect this.
It seems Firebase JavaScript SDK v10 is not compatible with this package v0.0.7.

  • I downgraded firbase to v9, and use overrides.
  • I use modern @firebase/firestore, not firebase/firestore.

And it worked.

  "dependencies": {
    "@invertase/firestore-stripe-payments": "^0.0.7",
    "firebase": "^9.23.0",   
  },
  "overrides": {
    "@firebase/app": "^0.11.4",
    "@firebase/auth": "^1.10.0",
    "@firebase/firestore": "^4.7.10"
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants