【发布时间】:2019-06-28 10:22:47
【问题描述】:
我正在尝试将条带支付与我的 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())
它给了我一个类型错误。
【问题讨论】:
-
请不要在问题中包含图像和链接 - 链接中断,如果我们想在答案中重新使用您的结构,我们将不得不重新输入它。包括代码和结构作为文本。要获取您的 Firebase 结构,请使用 Firebase 控制台->导出 JSON 并复制粘贴您的结构的 sn-p。见images and links are evil
标签: javascript firebase google-cloud-firestore google-cloud-functions stripe-payments