From the extension code,
let invoicesInFirestore = await admin
.firestore()
.collection(config.invoicesCollectionPath)
.where('stripeInvoiceId', '==', invoice.id)
.get();
it appears that, at the time of writing, it is not foreseen to handle multi subcollections.
I can see two solutions:
1. Adapt the extension code to create your own Cloud Functions
You copy the extension code and modify it in such a way it handles multi subcollections, in order to create your own Cloud Functions.
Note that the extension code declares the Cloud Function with export const sendInvoice = functions.handler.firestore.document.onCreate(...)
. As explained in the doc "The HandlerBuilder
class facilitates the writing of functions by developers building Firebase Extensions... Do not use HandlerBuilder
when writing normal functions for deployment via the Firebase CLI."
So you should adapt it as follows:
export const sendInvoice = functions.firestore
.document('users/{uid}/invoices')
.onCreate((snap, context) => {...}
However, note that by writing your own Cloud Function, you will loose potential future improvements to the extension.
2. Create a Cloud Function that copies/pastes the invoices from the subcollections
The idea is to have a Cloud Function listening to all the users/{uid}/invoices
subcollections (see above) that copies the new doc and creates a copy in the "central" Extension collection. Nothing prevent you to add some extra fields in the copied doc, like the user's uid.
Note that, if you want to get the feedback from Stripe, you may need another Cloud Function (which listens to the "central" Extension collection) to copy/paste the results of the Stripe webhook calls to the original documents in the users/{uid}/invoices
subcollection.
Personally I would go for this second approach.