node.js - 在 stripe 中调用函数时, "comma"语法是什么意思?

标签 node.js stripe-payments

我正在尝试在 Stripe 中创建新客户。我很成功,但对他们的文档如何设计函数调用感到困惑。

我似乎无法在他们的官方文档中找到任何信息。 https://stripe.com/docs/api/customers/create?lang=node

例如:

stripe.customers.create({
  description: 'Customer for jenny.rosen@example.com',
  source: "tok_visa" // obtained with Stripe.js
}, function(err, customer) {
  // asynchronously called
});

我假设它类似于“.then((err, customer) =>{}',但似乎无法使用此语法进行函数调用。

任何解释都会有帮助!

最佳答案

您所知道的是 Promise,它们是当今执行异步的首选方式。 Stripe 的 API 使用回调(也称为 errback)风格,它早于 Promises。

类似于

.then(customer => ...).catch(err => ...)

但是,Stripe 的 Node 库也返回 Promise,因此您可以将示例转换为:

stripe.customers.create({
  description: 'Customer for jenny.rosen@example.com',
  source: "tok_visa" // obtained with Stripe.js
})
.then(customer => ...)
.catch(err => ...);

关于node.js - 在 stripe 中调用函数时, "comma"语法是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55334136/

相关文章:

javascript - Nodejs - POST 请求的响应未定义

stripe-payments - Stripe : Is there an element that creates a customer without a charge?

testing - 如何创建用于在 stripe.com 上进行测试的历史数据

node.js - Sequelize.js:如何根据闭包中 where 中的值对查询结果进行排序?

javascript - 维护和组织 ExpressJS 路由

reactjs - 自动付款方式错误(使用付款元素) Stripe

node.js - KeystoneJS - Stripe 集成

javascript - 如何使用 anchor 标签触发 Stripe 信用卡结账?

javascript - 我如何伪造全局上下文来隔离测试?

javascript - Puppeteer:如何拦截跨多个 "pages"的请求?