【发布时间】:2020-02-08 08:52:07
【问题描述】:
我正在尝试util.promisify 以下条带调用确实成功:
stripe.customers.create(
{
description: 'My First Test Customer (created for API docs)',
},
function(err, customer) {
console.log(customer)
}
)
IIUC 这应该可以工作:
const util = require('util')
const createCustomerPromise = util.promisify(stripe.customers.create)
createCustomerPromise(
{
description: 'My First Test Customer (created for API docs)'
}
).then(customer=>console.log(customer))
但是,当我运行上述内容时,我得到:
(node:28136) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'createResourcePathWithSymbols' of undefined
at /home/ole/Temp/stripetest/node_modules/stripe/lib/StripeMethod.js:27:12
at internal/util.js:286:30
【问题讨论】:
-
Stripe SDK 已经返回 Promise。只需省略回调,即
stripe.customers.create().then().catch() -
@NikKyriakides - 鉴于问题的标题是“Promisifying the Stripe API”(特别是),我想说这符合答案。我会把它作为一个发布(带有相关的文档链接)。
标签: javascript node.js promise stripe-payments es6-promise