简体   繁体   English

客户不是在条带帐户上创建的

[英]Customer is not created on stripe account

I am running this node.js code to create customer on stripe account function deploy successful but failed to create customer on stripe I am not getting what I am missing.我正在运行此 node.js 代码以在条带帐户功能上创建客户部署成功但未能在条带上创建客户我没有得到我缺少的东西。 Fire base functions folder is also not showing the function there. Fire base functions 文件夹也没有在那里显示该功能。

const functions = require('firebase-functions');
    const admin = require('firebase-admin');
    admin.initializeApp(functions.config().firebase);
    const stripe = require('stripe')("secret key here");
    var customer;

    stripe.customers.create(
      {
        email: 'customer@example.com',
      },
      {
        maxNetworkRetries: 2, 
      }
    );

When you use APIs to services (viz. stripe.com and firebase) outside your complete control, you must check for errors.当您将 API 用于完全控制之外的服务(即 stripe.com 和 firebase)时,您必须检查错误。 If you're using a service incorrectly the error will explain, or at least hint, what you're doing wrong.如果您错误地使用服务,错误将解释或至少提示您做错了什么。

The stripe-node API documentation suggests you invoke stripe.customer.create() as an awaited function, like this: stripe-node API 文档建议您调用 stripe.customer.create() 作为等待的函数,如下所示:

const customer = await stripe.customers.create({
         email: 'customer@example.com',
});

This is easy if you call it from an async function.如果从异步函数调用它,这很容易。 You should use this sort of code in your async function to check for errors back from stripe.com.您应该在异步函数中使用此类代码来检查来自 stripe.com 的错误。

try {
   const customer = await stripe.customers.create({
         email: 'customer@example.com',
    });
    /* here's your customer object */
}
catch (error) {
    console.error ('stripe', error);
}

If you do not call it from an async function, you can wait for results using the Promises scheme.如果不从异步函数调用它,则可以使用 Promises 方案等待结果。

    stripe.customers.create({
         email: 'customer@example.com',
       })
    .then ( function (customer) {
             /* here's your customer object */
       })
    .catch ( function (error) {
        console.error ('stripe', error);
       });

If you haven't yet figured out how async/await or Promises work, the time has come for you do to that.如果您还没有弄清楚 async/await 或 Promises 是如何工作的,那么现在是时候去做了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM