这是 JS 中的 Google Cloud 函数,我收到以下错误,该函数成功创建 Stripe 客户,但无法写回数据库。
我猜它与 snap.uid
有关,我是对的吗?如何获取已创建的用于触发该函数的 User
节点的 uid
?
Error: Reference.update failed: First argument contains undefined in property
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);
});
});
最佳答案
根据您的情况,请使用
context.params.userId
userId
来自
ref('/users/{userId}')
关于javascript - JS Google Cloud 函数错误 : Reference. 更新失败:第一个参数包含属性中的未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56538089/