[英]Firebase Functions error when calling Stripe
I'm an iOS developer with very little experience in both Javascript and server code so I'm a little lost here.我是一名 iOS 开发人员,在 Javascript 和服务器代码方面经验都很少,所以我在这里有点迷茫。
I'm getting an error when I create a new user in firebase and trigger a function to create a new user in stripe.当我在 firebase 中创建新用户并触发 function 以在条带中创建新用户时出现错误。 Here is my firebase function straight from Stripe's docs.
这是我的 firebase function 直接来自 Stripe 的文档。
exports.createStripeCustomer = functions.auth.user().onCreate(async (user) => {
const customer = await stripe.customers.create({email: user.email});
return admin.firestore().collection('stripe_customers').doc(user.uid).set({customer_id: customerId});
});
I successfully create a new user in Stripe with a customer ID.我使用客户 ID 在 Stripe 中成功创建了一个新用户。
I get is this error in my firebase logs and don't capture the customer ID so I can save it in firestore.
我在我的 firebase 日志中得到这个错误并且没有捕获客户 ID,所以我可以将它保存在 firestore 中。 I'm not sure what I'm doing wrong or how to interpret this message.
我不确定我做错了什么或如何解释此消息。 Any pointers would be greatly appreciated.
任何指针将不胜感激。
createStripeCustomer
ReferenceError: customerId is not defined at exports.createStripeCustomer.functions.auth.user.onCreate (/srv/index.js:120:93) at <anonymous> at process._tickDomainCallback (internal/process/next_tick.js:229:7)
I have also tried this return changing customerId to ID我也尝试过将 customerId 更改为 ID
return admin.firestore().collection('stripe_customers').doc(user.uid).set({customer_id: ID});
It looks like, from the documentation , that the response object contains an id property.从文档中看来,响应 object 包含一个 id 属性。 Perhaps you meant to write this line instead:
也许您打算改写这一行:
return admin.firestore()
.collection('stripe_customers')
.doc(user.uid)
.set({customer_id: customer.id}); // use the ID property here
Here is where I finally ended up.这是我最终结束的地方。 I used a promise instead of await.
我使用了 promise 而不是等待。
exports.createStripeCustomer = functions.auth.user().onCreate(async (user) => { const stripePromise = new Promise((resolve, reject) => { stripe.customers.create({ email: user.email }, (err, customer) => { if (err) { reject(err) } else { resolve(customer); stripePromise.then(customer => { return admin.firestore().collection('stripe_customers').doc(user.uid).set({customer_id: customer.id}); }).catch(error => { console.log(`error resolving promise ${error}`) }) } }); }) });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.