mKane
mKane

Reputation: 982

iOS Firebase Stripe Integration w/ Cloud Functions, equivalent of push() and pushId in iOS

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

Upvotes: 1

Views: 495

Answers (1)

AshvinGudaliya
AshvinGudaliya

Reputation: 3314

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

Upvotes: 2

Related Questions