Stripe - PaymentIntent 需要 Node.js 中的付款方式问题
P粉441076405
2023-09-03 13:55:13
<p>我正在尝试将 stripe 集成到我的项目中,但收到“<strong>PaymentIntent 需要付款方式</strong>”消息。日志中的付款状态代码是200。但在付款仪表板中却显示“未完成”,原因是“<strong>客户尚未输入他们的付款方式。</strong>”</p>
<p><strong>下面是我的条纹后端代码</strong></p>
<pre class="brush:php;toolbar:false;">exports.StripePayment = (req, res) => {
const { amount, token } = req.body;
const idempotencyKey = uuid();
return stripe.customers
.create({
email: token.email,
source: token.id,
})
.then((customer) => {
stripe.paymentIntents
.create(
{
amount: amount,
currency: "INR",
payment_method_types: ["card"],
customer: customer.id,
receipt_email: token.email,
shipping: {
name: token.card.name,
address: {
line_1: token.card.address_1,
line_2: token.card.address_2,
city: token.card.address_city,
country: token.card.address_country,
postal_code: token.card.address_zip,
},
},
},
{ idempotencyKey }
)
.then((result) => {
console.log("Result", result);
return res.status(200).json(result);
})
.catch((err) => console.log(err));
});
};</pre>
<p>需要帮助来修复。提前致谢</p>
这是预期的行为。您共享的代码仅创建一个付款意图,它不会在其生命周期中推进该意图一个>.
目前您没有提供已创建的付款方式,也没有提供客户提供其付款方式详细信息的方式。需要添加该信息才能让 Stripe 处理付款。
创建付款意图只是 Stripe 集成的第一步。 Stripe 提供的本指南介绍了使用其服务处理付款所需的所有内容,是构建集成的一个很好的起点:
https://stripe.com/docs/ payments/accept- a- payment?platform=web&ui=elements
该指南将引导您完成需要构建的其余部分,包括为您的客户提供 UI 以提供其付款方式详细信息,并确认付款意图。