javascript - 使用 firebase-cloud-functions 将付款来源添加到 Stripe?
问题描述
我正在尝试将条带支付与我的 firestore firebase 数据库集成。我无法弄清楚 firebase 文档示例中给出的添加支付源功能。我在这里想念什么?
exports.addPaymentSource = functions.firestore
.document('Customers/{userId}/paymentSources/{paymentId}')
.onWrite((change, context) => {
let newPaymentSource = change.after.data();
if (newPaymentSource === null){
return null;
}
return admin.firestore().collection("Customers").doc(`${context.params.userId}`).get('customer_id')
.then((snapshot) => {
return snapshot.val();
}).then((customer) => {
return stripe.customers.createSource(customer, {newPaymentSource});
}).then((response) => {
return change.after.ref.parent.set(response);
}, (error) => {
return change.after.ref.parent.child('error').set(userFacingMessage(error));
}).then(() => {
return reportError(error, {user: context.params.userId});
});
});
我试过了
console.log(snapshot.val())
它给了我一个类型错误。
解决方案
您正在从 Cloud Firestore 读取数据,但正在使用用于实时数据库的变量名称和方法调用。虽然这两个数据库都是 Firebase 的一部分,但它们是完全独立的,并且具有不同的 API。
Firestore 的等效代码是:
return admin.firestore().collection("Customers").doc(`${context.params.userId}`).get()
.then((doc) => {
return doc.data();
}).then((customer) => {
...
另见:
- 阅读文档的文档
推荐阅读
- react-native - 反应导航错误 this.props.navigation.navigat
- android - 等待并单击按钮以在 Playstore 中安装和打开
- node.js - 使用 pg-promise 在事务中插入另一个插入
- css - 防止响应列出现双边框
- php - 本地和服务器上的动态 PHP 对象访问不同
- sql-server - 将多个文本文件导入单个 2 列 SQL 表(文件名、文本内容)
- c# - 我想在窗口内截屏
- scala - 试图让惰性评估适用于无限流
- android - 以编程方式更新应用程序时解析错误
- java - 使用 Spring data JPA 获取单列,无需查询