简体   繁体   English

Firebase 调用 Stripe 时函数出错

[英]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.

相关问题 Firebase Stripe 创建临时密钥的函数错误 - Firebase Functions Error for Stripe Create Ephemeral Key 从 Angular 调用 Firebase 可调用函数时出现 CORS 错误? - CORS error when calling Firebase Callable Functions from Angular? firebase web app quickstart-js 函数示例项目在调用函数时出错 - firebase web app quickstart-js functions sample project gives error when calling functions 尝试部署 Firebase 功能时出现“意外的令牌条带” - "Unexpected token stripe" when trying to deploy Firebase Functions 从 Firebase 函数调用 API 时出现“套接字挂断”错误 - Getting "Socket hang up" error when calling an API from Firebase functions 部署云时出错 function Firebase/Stripe - Error when I deploy cloud function Firebase/Stripe Firebase 部署错误:将单独的项目与 Stripe“使用 Stripe 运行付款”扩展一起使用时,“不支持更改机密” - Firebase Deploy Error: 'Changing secrets is not supported' when using separate projects with Stripe 'Run Payments with Stripe' extension 使用 Firebase Cloud Functions 创建 Stripe Connect 帐户 - Creating a Stripe Connect account with Firebase Cloud Functions Stripe Checkout:从 Node 转移到 Firebase 函数 - Stripe Checkout: moving from Node to Firebase Functions 错误:内部 firebase 函数,与 nodemailer 一起使用时 - Error:INTERNAL firebase functions ,when using it with nodemailer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM