How to set up firebase as server and execute stripe payment

三世轮回 提交于 2021-01-07 03:57:28

问题


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?


回答1:


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])

}



回答2:


You will find in the list of official Cloud Function samples, a sample on how to integrate Firestore and Stripe:

"Create Stripe customers and charge them on Cloud Firestore write", https://github.com/firebase/functions-samples/tree/master/stripe



来源:https://stackoverflow.com/questions/57250314/how-to-set-up-firebase-as-server-and-execute-stripe-payment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!