使用Stripe Setup Intent完成3DS验证后创建订阅时重复触发3DS并报错的问题排查求助
使用Stripe Setup Intent完成3DS验证后创建订阅时重复触发3DS并报错的问题排查求助
我目前在基于Stripe的Elements组件(@stripe/react-stripe-js)实现用户订阅的流程,采用Setup Intent来处理支付方式的预验证,但在最后创建订阅时遇到了奇怪的问题,想请大家帮忙排查下:
我的完整实现流程
1. 后端创建Setup Intent
用户提交支付表单后,我先在后端初始化Setup Intent:
const setupIntent = await stripe.setupIntents.create({ usage: 'off_session', customer: req.user.stripeCustomerId, payment_method_types: ['card'] }); return { statusCode: 200, body: JSON.stringify({ clientSecret: setupIntent.client_secret, setupIntentId: setupIntent.id }) };
2. 前端通过Elements生成支付方式
用Stripe Elements收集卡信息后,创建对应的Payment Method:
const cardElement = elements.getElement(CardNumberElement)!; const { paymentMethod, error: pmError } = await stripe.createPaymentMethod({ type: "card", card: cardElement, billing_details: { address: { postal_code: postalCode, }, name: fullName, }, });
3. 后端更新Setup Intent关联支付方式
拿到前端传来的Payment Method ID后,在后端更新Setup Intent的关联支付方式:
const { paymentMethodId, setupIntentId } = req.body; const setupIntent = await stripe.setupIntents.update(setupIntentId, { payment_method: paymentMethodId }); return { statusCode: 200, body: JSON.stringify({ clientSecret: setupIntent.client_secret, setupIntentId: setupIntent.id }) };
4. 前端完成3DS验证
调用confirmCardSetup触发3DS验证流程,并且我已经成功通过了3DS的门户验证:
const { setupIntent, error: confirmError } = await stripe.confirmCardSetup(updatedSetupIntentData.clientSecret);
5. 后端创建订阅
最后一步创建订阅时出现了问题:
const subscription = await stripe.subscriptions.create({ customer: req.user.stripeCustomerId, items: [ { price: PRICE_ID } ], expand: ['latest_invoice.payment_intent'] // 用于前端后续处理支付状态 });
遇到的具体问题
在Stripe仪表盘中看到明确报错:The cardholder began 3D Secure authentication but has not completed it.
我完全搞不懂——明明已经在Setup Intent的环节完成了3DS验证,为什么创建订阅时还会触发3DS,并且提示我未完成验证?有没有朋友遇到过类似的情况,或者能帮我指出流程中可能存在的疏漏?
内容来源于stack exchange
相关产品推荐
相关产品推荐

