【发布时间】:2021-03-29 10:45:08
【问题描述】:
我对如何组织代码有疑问,并且在过去 48 小时内无法弄清楚如何解决此问题。我的大脑基本上被卡住了,我想帮助我找出解决方案。我在服务器上使用 expressjs,在前台使用 Svelte。
问题: 我能够创建客户、paymentMethods、paymentIntents 并将 paymentMethod 附加到客户,将所述 paymentMethod 设置为其客户的默认 paymentMethod...等等
要显示客户的付款方式,我必须使用 Stripe.paymentMethods.list 来返回一组卡片。卡对象不包含任何表明该卡是客户默认付款方式的字段。
存储默认付款方式的 default_payment_method 位于客户对象中。所以我需要获取客户对象,这就是我需要帮助的地方。我该如何解决这个问题,如何访问 Stripe.paymentMethods.list() 以获取卡片列表和 stripe.customer.retrieve() 以便我可以访问我的服务器句柄中的 defaultpaymentmethod,以便我可以返回所有这些信息往前走?
// get cards
stripe.paymentMethods.list({
customer: customer,
type: 'card'
}).then(cards => {
//I can return cards but not customer
return res.end(JSON.stringify({ cards: cards}));
}).catch(err => { console.log("err message :", err.message)});
});
// now get customer
stripe.customers.retrieve(
'cus_Ib01d7QtMdz2ez'
).then(customer=>{
// I can return customer but not cards
return res.end(JSON.stringify({customer : customer}));
});
// next step, send customer and cards to the frontst
return res.end(JSON.Stringfy({cards : cards; customer : customer}))
?????
如何返回“卡片和客户”对象,以便我可以向客户展示他/她的卡片以及默认付款方式。如何使用 res.end(JSON.stringfy({})) 有两个单独的函数,我可以将它们结合起来并返回一个返回吗?
【问题讨论】:
标签: javascript express stripe-payments