0
votes

Currently the open sourced cloud function provided by Firebase/Stripe uses onwrite to Firebase database to trigger the charge to Stripe:

https://github.com/firebase/functions-samples/tree/master/stripe

It seems that it would be more direct and faster to just call Stripe using https trigger instead of writing to Firebase local database which syncs/writes to Firebase server database, which then triggers the cloud function call to Stripe.

Will there be any problems using Https call to trigger Stripe call? What advantages are there for using onwrite trigger instead of https?

1
You can use whatever strategy you like. You're not bound to the sample code.Doug Stevenson
yeah thats correct, but Firebase open sources version has provided the onWrite() code/functions for some reason, otherwise they could have just provided https.onRequest() code/functions for use. Its just a curious thought.Nasir

1 Answers

0
votes

Beginner to beginner, this is my understanding:

Let's say you have an app where a you need to
(1) sign users up for a subscription using Stripe, and then
(2) when users use the app, check to make sure their subscription is still valid.

For (1), you'd only do this once(ish) per user, and you need to tell Stripe "make a new subscription for this user," so it makes sense to use an https.onRequest or https.onCall function.

For (2), you'd be checking to see whether the user is subscribed many times, and you're not telling Stripe something, you're asking it about stored information: "is this user's subscription still valid?"

If you're asking about stored information, it's a lot faster to check your own database rather than to wait for a response from Stripe. You just need to make sure the information in your database (e.g. Firestore) is up to date with Stripe.

So what you can do is create a Stripe webhook that will trigger an https.onRequest function whenever there is a change to a user's subscription status. Then, your function writes the change to your database.

So, rather than ask Stripe over and over, "is this user subscribed," and wait for a slow response, you just check your own database, knowing that it's kept up to date by the Stripe webhook.