正确使用Firebase云端功能和条纹 [英] Properly Using Firebase Cloud Functions and Stripe

查看:149
本文介绍了正确使用Firebase云端功能和条纹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Firebase Cloud功能和Stripe,以及iOS(Swift)。我想使用Firebase Cloud功能来按照Stripe的要求执行卡收费。我正在尝试使用此示例:在Payments节点是用户ID后。



我知道函数基本上查找数据库更新到特定节点,但我不知道如何确保它从子节点抓取正确的值。我希望我以一种可以理解的方式来描述这一点。如果我没有让我知道,我会尽我所能来重写。谢谢!

解决方案

好的伙计我自己弄明白了,我会在这里写一个迷你教程。
$ b

因为这个问题专门处理stripe,所以我只会介绍这个特定的用例。首先阅读Stripe文档很重要。它指定了期望你给它的参数。以下是您使用Stripe为卡充值时所期望的链接:分条费用文档



其次,您需要在Firebase Realtime数据库的这些预期参数之后进行建模,至少对于用户在您的应用中进行的购买交易。大多数情况下,您可以使用包含Key:值对的字典。请确保您将金额参数乘以100,因为Stripe只采用整数。这意味着,如果你是收取22.48例如,那么你乘以100得到2248.当你检查你的仪表板条纹它将显示为22.48。



第三条纹需要与后端交谈,以便您可以对卡进行充电。 Firebase云端功能对此非常完美。记住你的实时数据库?那么你可以在你指定的节点上写入时触发一个云功能。幸运的是Firebase已经在GitHub上提供了一个示例: Firebase Stripe Example

您可以修改侦听写入数据库的代码行。只要您至少返回令牌和要收取的金额,您就可以将其更改为您的结构。如果您打算让用户每次输入他们的信息,那么您需要删除customer参数(在index.js文件中),因为它会预期具有不同前缀的不同令牌。 (这在文档中有所说明)其余的例子都有很好的文档记录,可以遵循。收费的结果将被写回到您的数据库中。以下视频向您展示了如何在写入工作中触发功能以及使用的一些术语。 : Youtube Video for Cloud功能在写入时触发。



我希望这可以帮助你们中的一些人,因为我知道关于stripe和firebase的问题相当普遍。


I am trying to use Firebase Cloud functions and Stripe, and iOS (Swift). I want to use Firebase Cloud functions to perform the card charge as is required by Stripe. I am trying to use this example: Firebase Stripe Example

I uploaded the example they gave, but I need to modify the charge function slightly. I tried setting it to the file path I have in my real time data base, but I am not sure how to modify the entire thing so that It will work off of my realtime database structure. Such as grabbing the parameters it needs. Here is what my structure looks like: after the Payments node is the userID.

I know that the function basically looks for database updates to the specific node, but I am not sure how to make sure it grabs the correct values from the child nodes. I hope I have described this in an understandable way. If I haven't let me know and I will do my best to reword. Thank you!

解决方案

Alright guys I figured it out myself and I will write a mini tutorial here.

Because this question specifically deals with stripe I will only cover this specific use case. First it is important to read the Stripe documentation. It specifies the parameters it is expecting you to give to it's api. Here is the link for what is expected when you charge a card with Stripe: Stripe Charges Documentation

Second you need to model your Firebase Realtime database after those expected parameters, at least in regards to the purchases a user will make in your app. Most of the time you can use a dictionary with Key:value pairs. Make sure you multiply your amount parameter by 100 as Stripe only takes integers. This means if you you are charging 22.48 for example then you multiply it by 100 to get 2248. When you check your dashboard in stripe it will show up as 22.48.

Third Stripe needs to talk to a back end so that you can charge the card. Firebase Cloud functions are perfect for this. Remember your real time database? Well you can trigger a Cloud function when a write occurs on a node that you specify. Luckily Firebase has provided a sample on GitHub: Firebase Stripe Example

You can modify the line of code where it listens for a write to the data base. You can change it to your structure specifically as long as you return at least the token and the amount to be charged. If you are going to make the user enter their information every time, then you need to delete the customer parameter (in the index.js file) as it will expect a different token with a different prefix. (This is noted in the documentation) The rest of the example is well documented and can be followed. The outcome of the charge will be written back into your database. The following video shows you how Functions triggered on write work and some of the nomenclature used. : Youtube Video for Cloud Functions triggered on write.

I hope this helps a few of you as I know questions about stripe and firebase are fairly common.

这篇关于正确使用Firebase云端功能和条纹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆