Stripe payment_intent为空,但订阅成功



我使用nodejs和reactjs与stripe进行支付。用户填写姓名、地址等字段。当然还有信用卡详细信息的字段。React做一些调用:

const createdCustomer = await createCustomer("someUserInfoObject");
if(!createdCustomer.success){
alert("createdCustomer failed");
}
const createdSubscription = await createSubscription("somePriceId", createdCustomer.newlyCreatedId);
if(!createdSubscription.success){
alert("createdSubscription failed");
}
...more code to finalize payment
在后台,nodejs执行对stripe API的调用:
const createCustomer = async function(req, res) {
const customer = await stripe.customers.create(someUserInfo);
return res.json({message: "createCustomer",customer: customer,success: true});
}
const createSubscription = async function(req, res) {
const options = {
customer: req.body.newlyCreatedId,
items: [{price: req.body.price_id}],
payment_behavior: 'default_incomplete',
expand: ['latest_invoice.payment_intent'],
}
const subscription = await stripe.subscriptions.create(options);
if(
!subscription || !subscription.latest_invoice || !subscription.latest_invoice.payment_intent || !subscription.latest_invoice.payment_intent.client_secret){
return res.json({error: "no_payment_intent",success: false});
}
}

这段代码总是在订阅中添加一个新条目,当我检查条纹仪表板时。所以基本上是可行的。但是在上面的nodejs代码中,当调用:

stripe.subscriptions.create

通常最后一个if语句失败。原因是

subscription.latest_invoice.payment_intent

变成零。为什么?我在控制台中打印的所有其他字段看起来都没问题。但支付意图有时是无效的。由于某种原因,我需要"subscription.latest_invoice.payment_intent.client_secret"并将其存储在我的数据库中。但是当payment_intent为null时,我不能得到它,我被迫显示错误,如支付失败。但根据stripe dashboard中创建的新订阅,它并没有失败。

好的,问题与最小金额有关。我的计划是1瑞典克朗。最低金额为1瑞典克朗(相当于美元)。

最新更新