之前也曾提出过类似的问题,但没有直接回答。使用Stripe的create subscription呼叫:
stripe.subscriptions.create({
customer: "cus_FrggXOPDIf2ldT",
items: [
{
plan: "plan_FrbdKwJE959Ivb",
},
]
}, function(err, subscription) {
// asynchronously called
}
);
有一个返回的订阅对象。该对象是否在异步返回的回调函数中返回?我尝试了以下方法,但未成功:
stripe.subscriptions.create({
customer: "cus_FrggXOPDIf2ldT",
items: [
{
plan: "plan_FrbdKwJE959Ivb",
},
]
}, function(err, subscription) {
console.log(subscription.id);
}
);
如何返回ID,以及如何获取ID?
答案 0 :(得分:0)
嗯,我应该知道create subscription调用返回了promise。因此,在这种情况下:
stripe.subscriptions.create(
{
customer: id,
items: [
{
plan: 'plan_FrbdKwJE959Aws',
},
],
},
).then(subscription => console.log(subscription.id));