You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Stripe返回requires_confirmation状态的PHP/JS处理方案咨询

处理Stripe PaymentIntent的requires_confirmation状态

当使用测试卡4000008260003178触发requires_confirmation状态时,你需要在后端的generateResponse()函数中新增该状态的处理逻辑:

  • 后端处理逻辑
    在状态判断分支中添加requires_confirmation的处理,调用Stripe API确认支付意向,再根据确认后的状态返回对应响应:

    switch (paymentIntent.status) {
      case 'succeeded':
        return { success: true };
      case 'requires_action':
        return { requiresAction: true, paymentIntent: paymentIntent };
      case 'requires_confirmation':
        // 调用Stripe API确认PaymentIntent
        const confirmedIntent = await stripe.paymentIntents.confirm(paymentIntent.id);
        // 根据确认后的状态返回结果
        if (confirmedIntent.status === 'succeeded') {
          return { success: true };
        } else if (confirmedIntent.status === 'requires_action') {
          return { requiresAction: true, paymentIntent: confirmedIntent };
        } else {
          return { error: 'Payment failed' };
        }
      default:
        return { error: 'Unexpected payment status' };
    }
    
  • 前端配合处理
    若后端返回确认后的requires_action状态,前端需继续使用Stripe Elements完成后续验证流程(如3DS验证);若确认后直接成功,则跳转至成功页面。

  • 状态说明
    requires_confirmation表示PaymentIntent需被确认才能继续处理,常见于测试卡场景或手动确认模式下。调用confirm()方法后,Stripe会继续处理支付并返回新状态供后续逻辑处理。

内容的提问来源于stack exchange,提问作者abe1432181

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 03:54:29