invertase / stripe-firebase-extensions

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

Checkout Session object & Customer object not updated after completed session #377

Open pd-leukert opened 2 years ago

pd-leukert commented 2 years ago

Bug report

Describe the bug

I enabled phone_number_collection on my checkout sessions. As jsteele-stripe mentioned here - https://github.com/stripe/stripe-firebase-extensions/issues/365#issuecomment-1075347924 - the phone number should be set on both the Checkout Session and the Customer object. However, this does not seem to happen.

To Reproduce

Create a Checkout session with phone_number_collection enabled with an authenticated user. Then, open the checkout website and enter a phone number. Finish the transaction. Then, in Firestore, there is no "phone" field on the user and none on the Checkout Session object.

Expected behavior

As described here - https://github.com/stripe/stripe-firebase-extensions/issues/365#issuecomment-1075347924 - the phone number should be set on both these objects

Additional context

I analysed the webhook events at dashboard.stripe.com/test/webhooks/we_xxx.. and realised, that the checkout.session_completed event object seems to be the one which should replace the Checkout Session object in my Firestore database. It also includes the phone number. However, the Checkout Session object in Firestore is still the same as the user client created it, only with the additional client, created and url fields. Thus I guess, the checkout.session_completed event object is not applied when the webhook is fired. The response of my application seems to be 200 - OK.

pd-leukert commented 2 years ago

The user object seems to be updated with the email, name, stripeId and stripeLink fields, but not phone.

jsteele-stripe commented 2 years ago

@LeQuadratico Which version of firestore-stripe-payments are you using? Support for that parameter was just released in 0.2.5 (released last week).

pd-leukert commented 2 years ago

Hey @jsteele-stripe , I am using the latest version (0.2.5). With this update, the parameter is successfully passed on to stripe, and the collection of the phone number works. However, the webhook reply from stripe (checkout.session_completed) does not seem to be processed correctly. Thus, the phone number is saved nowhere in the firestore and is not accessible.

jsteele-stripe commented 2 years ago

Yep, that PR didn't add support to persist the relevant field(s) from the checkout.session.completed event. On which documents would you expect the phone number to be written to?

pd-leukert commented 2 years ago

@jsteele-stripe I would expect the phone number to be written to the user object (in the users collection, same as the mail address and name) and the checkout session, as written here. For most devs it would probably be enough to save the number to the user object, but maybe it would be nice to follow the documentation of stripe.