Ad

How To Set Up Firebase As Server And Execute Stripe Payment

I would like to use firebase as a server and send request to payment request to stripe. I have zero experience server side so I am looking for a simple way to achieve this. This post Is it possible to integrate Stripe With Firebase and with iOS? is close to what I want to achieve and it also list some interesting link. Does anyone know where I can find a good but simple tutorial to set up firebase as a server for stripe?

Ad

Answer

I resolved this with the following 2 steps

  1. follow step 1, 2 and 3 of the the get started article (https://firebase.google.com/docs/functions/get-started). This has allowed me to install all the software which was needed (note I had several issue with firebase tool install and node/npm but eventually I managed to install)
  2. Follow this youtube guide (https://www.youtube.com/watch?v=NsPGRIVOg0U). It is a nice video, simple to understand, on what to do to set up the function to request the execution of the payment.
  3. create some logic in my swift app to save the stripe token in a realtime database as below

func saveTokenInRealtimeDatabase(token: STPToken) {

    let ref = Database.database().reference(withPath: "payments")     
    ref.child(Auth.auth().currentUser!.uid).childByAutoId().setValue(["amount": valueToCharge,  "token": token.allResponseFields])

}
Ad
source: stackoverflow.com
Ad