1

I am using Firebase cloud functions to process my stripe payments. I have some of it set up correctly. When a user authenticates it automatically creates a stripe user. That works great.

Inside of the sample provided by Firebase under 'Adding a payment source' it shows

exports.addPaymentSource = functions.database.ref('/stripe_customers/{userId}/sources/{pushId}/token').onWrite((event) =>

which should take a payment token provided by stripe and write to the realtime database and update stripe with that token for a user.

However it is very unclear what 'pushID' stands for. I have created numerous attempts such as this one

let payment: NSMutableDictionary = ["sources":"stripeCustomerID" ]
self.root.child("stripe_customers").child("FIREBASE USER ID").updateChildValues(payment as! [AnyHashable : Any])

but that does not seem to trigger anything in stripe.

Does anyone have an idea of how to structure this call or what the push id is?

The comments in the firebase sample say

Add a payment source (card) for a user by writing a stripe payment source token to Realtime database

AshvinGudaliya
  • 3,234
  • 19
  • 37
mKane
  • 932
  • 13
  • 30

1 Answers1

2

In Firebase pushId means your database any key name. you can set unique key using childByAutoId()

Set path your child, you want to be set auto push id like.

let sourcesRef = root.child("stripe_customers").child("FIREBASE USER ID").child("sources")

sourcesRef.child(sourcesRef.childByAutoId().key).child("token").setValue("tokenValue")

read more

AshvinGudaliya
  • 3,234
  • 19
  • 37
  • Thank you so much! – mKane Mar 31 '18 at 13:18
  • What about this call? // Charge the Stripe customer whenever an amount is written to the Realtime database exports.createStripeCharge = functions.database.ref('/stripe_customers/{userId}/charges/{id}') what would be id? Sorry this is so ambiguous to me. – mKane Mar 31 '18 at 13:31
  • this is your live database filed key name. you can set a unique key, you can set childByAutoId key as id in your database. – AshvinGudaliya Mar 31 '18 at 13:38
  • you have set a id key in your database, function auto get this id value and execute a func. – AshvinGudaliya Mar 31 '18 at 13:40
  • ah yes same as the other which is autoID. I guess whoever wrote the sample just did not stay consistent. Not very clear what to pass back to Stripe, but the errors are giving some indications such as amount missing etc. – mKane Mar 31 '18 at 13:42
  • for anyone following just add the "amount": YOURAMOUNTHERE – mKane Mar 31 '18 at 13:52
  • @mKane I too am using Firebase Realtime Database and the examples of the Firebase Functions provided are for Cloud Firestore, are you able to please share your final code of the functions provided but for Realtime Database use? I would really appreciate it. I'm learning Swift and not ready to learn JavaScript yet :) – Roggie Oct 22 '18 at 22:12
  • Do you mean all of my functions for this to work? @Roggie – mKane Oct 22 '18 at 23:33
  • hey @mKane if you wouldn't mind sharing the basic functions as per the Stripe examples, and where do you configure your Stripe key for it to work? – Roggie Oct 22 '18 at 23:39
  • @Roggie I am actually going to make a youtube video explaining step by step how to do this. You can subscribe if you'd like to get an alert when it's live https://www.youtube.com/channel/UClPBd3Y-iuHtWCbSnnMcfcA?view_as=subscriber – mKane Oct 23 '18 at 12:10
  • That’s awesome...I will definitely subscribe. Approximately when will it be published? – Roggie Oct 23 '18 at 21:08