我正在尝试在 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/