【发布时间】:2019-06-11 15:22:52
【问题描述】:
这是 JS 中的 Google Cloud 函数,我收到以下错误,该函数成功创建了 Stripe 客户,但无法写回数据库。
我猜它与snap.uid 有关,对吗?以及如何获取为触发该功能而创建的User节点的uid?
错误:Reference.update 失败:第一个参数包含未定义的 属性
exports.createStripeCustomerFromUser = functions.database.ref('/users/{userId}').onCreate((snap, context) => {
const userSnap = snap.val();
const first = userSnap.firstName;
const last = userSnap.lastName;
const email = userSnap.email;
const description = first + ' ' + last;
return stripe.customers.create({
email: email,
description: description,
name: description,
}).then((customer) => {
var updatedUserData = {};
updatedUserData[`/stripe_ids/${customer.id}`] = snap.uid;
updatedUserData[`/stripe_customers/${snap.uid}/customer_id`] = customer.id;
return admin.database().ref().update(updatedUserData);
});
});
【问题讨论】:
标签: javascript firebase-realtime-database google-cloud-functions