invertase / stripe-firebase-extensions

Repository of Firebase Extensions built by Stripe.
https://firebase.google.com/products/extensions
Apache License 2.0
437 stars 171 forks source link

Customers are not being created in Firestore after checkouts/subscription: User not found! Error #574

Open EmilioNicolas opened 1 year ago

EmilioNicolas commented 1 year ago

Bug report

firestore-stripe-payments

Describe the bug

After configuring the extension and products and price are sync in my Firebase local emulator, customers are not being created when checking out a subscription or a payment link. They are created if I configure the sync between Authentication and Customers. However that's not what I want to achive, I want customers only be created when checking out if they don't exist yet.

Here you can see my functions log register.

i  functions: Beginning execution of "europe-west1-ext-firestore-stripe-payments-handleWebhookEvents"
>  {"severity":"INFO","message":"⚙️ Handling Stripe event [evt_1O3FiwGfuP2yQq5x3yNPBNvb] of type [customer.subscription.created]."}
i  functions: Beginning execution of "europe-west1-ext-firestore-stripe-payments-handleWebhookEvents"
>  {"severity":"INFO","message":"⚙️ Handling Stripe event [evt_1O3FiwGfuP2yQq5xyf1yLhQN] of type [customer.subscription.updated]."}
>  {"severity":"ERROR","message":"❗️[Error]: Webhook handler for  Stripe event [evt_1O3FiwGfuP2yQq5x3yNPBNvb] of type [customer.subscription.created] failed: User not found! cus_Oqxejw0kR6IH2E"}
>  {"severity":"ERROR","message":"❗️[Error]: Webhook handler for  Stripe event [evt_1O3FiwGfuP2yQq5xyf1yLhQN] of type [customer.subscription.updated] failed: User not found! cus_Oqxejw0kR6IH2E"}
i  functions: Finished "europe-west1-ext-firestore-stripe-payments-handleWebhookEvents" in 82.479916ms
i  functions: Finished "europe-west1-ext-firestore-stripe-payments-handleWebhookEvents" in 40.650417ms

To Reproduce

Configure the extension in localhost with stripe test mode, no async Auth-Customers. Create products and payment link. Checkout and see errors in functions "User not found!"

Expected behavior

I expect a customer is created in my Firebase if it doesn't exist yet each time a checkout or a subscription is procceed. I am sure I am missing something obvious but I cannot see it. 😔

System information

EmilioNicolas commented 1 year ago

I am not sure if this notices may have something to do with the problem:


⚠  Function 'createPortalLink is missing a trigger in extension.yaml. Please add one, as triggers defined in code are ignored.
⚠  Function 'handleWebhookEvents is missing a trigger in extension.yaml. Please add one, as triggers defined in code are ignored.```
EmilioNicolas commented 1 year ago

I have still the problem, I don't know why createCheckoutSession is not being called 🤷‍♂️ https://github.com/invertase/stripe-firebase-extensions/blob/504145e63fe928123ce7d87f36bf9a6d1de091e4/firestore-stripe-payments/functions/src/index.ts#L109

Is it possible this extension doesn't work properly with stripe buttons/links or pricing tables and I must use Firebase JS Stripe extension SDK https://github.com/invertase/stripe-firebase-extensions/blob/next/firestore-stripe-web-sdk/README.md to create checkout sessions programmatically?

dackers86 commented 1 year ago

Hi @EmilioNicolas

This extension does not automatically sync users, have you updated the extension configuration to automatically sync users with Stripe?

https://github.com/invertase/stripe-firebase-extensions/blob/3b555618a8086b9553364f5b8f6b12593bbcb52c/firestore-stripe-payments/extension.yaml#L200

spookyuser commented 1 year ago

I've also been seeing this happen a lot recently, thought not 100% of the time, image and do have SYNC_USERS_ON_CREATE set to Sync

Is it possible this is to do with out of order stripe events, like User subscription update coming after User create?

Andre1992 commented 8 months ago

I have the exact same issue. When a user registeres in my app, a stripeID and stripe customerID and metadata firebase ID is created in Stripe dashboard. But when later the user subscribes through my stripe product, a completly new customer is created with a new customerID and no firebaseUID, and my Firestore does not update the subscribers collection. I cant find help anywhere. I think my heckout integration is not connected with the Firestore. But customer cus_Phmg0DMe36adb6 was created via API integration with Firestore at start, this is so confusing...

spookyuser commented 8 months ago

@Andre1992 have you checked whether your SYNC_USERS_ON_CREATE is on? For me this was causing a race condition and when i disabled it started working again.

Andre1992 commented 8 months ago

@spookyuser That is actually a good suggestion, I had it on sync. I changed to Do not sync, let me try.

Andre1992 commented 8 months ago

Did not work... I made a new issue: https://github.com/firebase/extensions/issues/1984