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

使用flutter_stripe时Visa/MasterCard 3D验证失败求助

Flutter Stripe支付:Visa/MasterCard 3D Secure认证失败排查方案

以下是针对你遇到的Visa/MasterCard支付时3D Secure认证失败、Amex正常的问题,常见的排查方向和解决方法:

1. 确认3D Secure流程是否完整处理

confirmPayment调用后,如果支付Intent处于requires_action状态(即需要3DS认证),你需要主动触发后续的认证流程,否则会直接报错。Amex可能因规则豁免3DS,所以无需额外处理即可成功。

修正代码,完整处理3DS流程:

try {
  final paymentResult = await Stripe.instance.confirmPayment(
    paymentIntentClientSecret: 'your_client_secret',
    data: const PaymentMethodParams.card(
      paymentMethodData: PaymentMethodData(),
    ),
  );

  // 处理需要3DS认证的情况
  if (paymentResult.status == PaymentIntentsStatus.RequiresAction) {
    final actionResult = await Stripe.instance.handleNextAction(
      paymentResult.paymentIntentClientSecret!,
    );
    if (actionResult.status == PaymentIntentsStatus.Succeeded) {
      // 3DS认证成功,支付完成
    }
  } else if (paymentResult.status == PaymentIntentsStatus.Succeeded) {
    // 无需3DS,直接支付成功
  }
} catch (e) {
  print('支付错误详情: ${e.toString()}');
}

2. 检查后端Payment Intent配置

后端创建Payment Intent时,需确保3DS相关配置正确:

  • 设置payment_method_options.card.request_three_d_secure为automatic(Stripe会自动判断是否需要3DS)或required(强制触发3DS)
  • 确认confirmation_method设置为automatic(若使用manual,需确保后端完成后续确认步骤)

如果后端未正确配置,Visa/MasterCard的3DS流程无法被正确触发,导致认证失败。

3. 验证测试卡的合规性

确保使用的是Stripe官方提供的、需要3DS认证的测试卡:

  • Visa测试卡:4000 0027 6000 3184(输入任意未来过期日期、CVC,测试3DS流程)
  • MasterCard测试卡:4000 0000 0000 3220(同上)

若使用了不需要3DS的测试卡,但后端强制要求3DS,也会触发认证失败错误。

4. 检查flutter_stripe插件版本

旧版本插件可能存在3DS处理的兼容性问题,更新到最新稳定版:
在pubspec.yaml中指定最新版本(替换^x.x.x为当前最新版):

dependencies:
  flutter_stripe: ^x.x.x

执行flutter pub get完成更新。

5. 平台特定配置检查

iOS端

  • 在Info.plist中添加Stripe的URL Scheme,格式为stripe-你的发布密钥(去掉pk_前缀),例如:
    <key>CFBundleURLSchemes</key>
    <array>
      <string>stripe-your_publishable_key_without_pk</string>
    </array>
    
  • 确保ATS配置允许Stripe相关域名访问(默认配置一般没问题,若有自定义ATS规则需排查)

Android端

  • 在AndroidManifest.xml中添加处理Stripe回调的intent-filter:
    <activity
      android:name=".MainActivity"
      android:launchMode="singleTop">
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="stripe-你的发布密钥(去掉pk_前缀)" />
      </intent-filter>
    </activity>
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 23:30:00