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

Flutter ApplePayButton报错:failed to present payment controller 求助

Flutter ApplePayButton 真机报错排查方案

问题复现

通过flutter create .创建全新Flutter项目,仅在默认页面添加pay依赖的ApplePayButton组件,配置如下:

ApplePayButton(
  onPaymentResult: (result) => greenToast(result.toString()),
  paymentItems: [
    PaymentItem(
      amount: "111.01",
      label: "test",
    ),
  ],
  onError: (error) => redToast(error.toString()),
  paymentConfiguration: PaymentConfiguration.fromJsonString('''
    {
    "provider": "apple_pay",
    "data": {
      "merchantIdentifier": "merchant.xxx.xxx",
      "displayName": "app_name",
      "merchantCapabilities": ["3DS", "debit", "credit"],
      "supportedNetworks": ["amex", "visa", "mada", "masterCard"],
      "countryCode": "SA",
      "currencyCode": "SAR"
      }
    }
    '''),
),

iOS模拟器可正常工作,但两台曾使用Apple Pay的真机均触发错误:PlatformException(paymenterror, failed to present payment controller, null, null)

已尝试的操作

  • 原应用主语言为阿拉伯语,已将含阿拉伯字符和|的应用名改为纯英文
  • 重启MacOS和Xcode排查缓存问题
  • 使用flutter ios --release --no-tree-shake-icons命令编译Runner
  • 更新Flutter后用flutter ios --release编译
  • Merchant ID已配置有效的Apple Pay Payment Processing Certificate

排查与解决建议

1. 检查Merchant ID与App ID的关联

登录Apple开发者后台,进入Certificates, Identifiers & Profiles:

  • 找到对应App ID进入编辑页面,确认Apple Pay Payment Processing已勾选,并关联了你的merchant.xxx.xxx Merchant ID
  • 若刚修改配置,需重新生成对应的Provisioning Profile并在Xcode中更新

2. 验证真机的Apple Pay环境

  • 确认真机已绑定支持沙特(SA)地区、SAR货币的有效银行卡,且卡种属于配置中的supportedNetworks(amex/visa/mada/masterCard)
  • 进入iPhone系统设置→Wallet与Apple Pay,尝试移除并重新添加银行卡,测试基础Apple Pay功能是否正常

3. 检查Xcode项目的签名与权限

在Xcode中打开Runner项目:

  • 进入Signing & Capabilities标签,确认已添加Apple Pay capability,且列表中包含你的Merchant ID
  • 检查Info.plist是否添加了Apple Pay使用描述:
    <key>NSApplePayUsageDescription</key>
    <string>使用Apple Pay完成支付</string>
    

4. 简化配置项测试

暂时简化paymentConfiguration中的配置,缩小排查范围:

{
  "provider": "apple_pay",
  "data": {
    "merchantIdentifier": "merchant.xxx.xxx",
    "displayName": "app_name",
    "merchantCapabilities": ["3DS"],
    "supportedNetworks": ["visa", "masterCard"],
    "countryCode": "SA",
    "currencyCode": "SAR"
  }
}

移除mada网络和debit/credit能力,先确认核心配置是否正常

5. 查看iOS原生日志获取详细错误

Flutter的PlatformException信息有限,通过Xcode连接真机查看原生日志:

  • 用数据线连接真机到Mac,打开Xcode并选择该设备
  • 运行项目后触发Apple Pay按钮,在Xcode的Console面板中搜索PaymentError、PKPaymentAuthorizationViewController关键词,获取更具体的错误原因(如证书无效、地区不匹配等)

6. 确认pay依赖版本

检查pubspec.yaml中pay依赖是否为最新稳定版,更新后重新编译:

dependencies:
  pay: ^1.1.0 # 替换为当前最新稳定版本

执行flutter pub get后重新打包测试

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 21:47:07