在Firebase的云功能上处理IPN [英] Handle IPN on Cloud Functions of Firebase
问题描述
在我的客户上,我有一个订单,其中包含我要购买的物品.当我结帐"订单时,我向Firebase云功能发送请求,该功能以指向在线支付交易的链接进行响应.客户完成交易后,来自公司(为其提供在线支付服务)的请求将分派给我的一个云部门,该部门将处理付款.
On my client, I have an order which has the items I want to buy. When I "checkout" the order, I send a request to my firebase cloud function and the function responds with a link to the online payment transaction. After the customer completes the transaction, a request from the company (who serves the online payment service) is being dispatched to one of my cloud functions who shall process the payment.
验证付款后,我想将付款的新数据存储到订单中(例如状态,完成日期等).
After I validate the payment, I want to store the new data of my payment to the order (e.g. status, completion date etc...).
如何存储我的新数据?我知道在Firestore中,我可以简单地使用.set(..)
方法.
How can I store my new data? I know that with firestore I can simply use the .set(..)
method.
推荐答案
我从评论中得到了答案(感谢Oleskii Miroshnyk).由于Oleskii并未将其发布为答案,所以我会的.
I've got my answer from the comments (Thanks to Oleskii Miroshnyk). Since Oleskii didn't post it as an Answer, then I will.
首先,我们需要导入firebase-admin
:
import * as admin from 'firebase-admin';
或使用Javascript
or in Javascript:
const admin = require('firebase-admin');
在那之后,我们需要像这样初始化我们的应用程序:
After that, we need to initialize our application like so:
const serviceAccount = require('../service-account-key.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://{PROJECT-ID}.firebaseio.com'
});
service-account-key.json
可以在您的Firebase设置中找到.
The service-account-key.json
can be found in your firebase settings.
完成配置后,就可以像这样访问firestore
方法:
Once I finish with the configuration, I have access to the firestore
method like so:
const firestore = admin.firestore();
firestore.collection(...).doc(...).set(...)
就是这样.其实很简单.
That's it. Quite simple actually.
这篇关于在Firebase的云功能上处理IPN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!