Flutter Stripe v9.1.0无法显示Google Pay按钮问题求助
Google Pay按钮未在Stripe PaymentSheet中显示的排查方案
检查配置细节问题
- 货币代码格式:代码里
currencyCode: "gbp"用的小写,Stripe要求货币代码为大写格式(如"GBP"),这可能导致Google Pay无法正确识别配置,修改为大写后重试。 - 测试环境验证:虽设置了
testEnv: true,但需确保测试设备满足条件:- Android设备需安装Google Pay应用,且添加了Stripe测试卡片(如
4242 4242 4242 4242) - 测试设备地区需设置为英国(UK),与
merchantCountryCode保持一致
- Android设备需安装Google Pay应用,且添加了Stripe测试卡片(如
确认PaymentIntent创建参数
创建PaymentIntent时需保证:
- 货币参数传递大写的"GBP",与PaymentSheet配置一致
amount使用最小货币单位(如1英镑对应100),避免金额格式错误导致支付方式加载失败
代码调整示例
修正后的initPaymentSheet代码:
paymentIntentData = await createPaymentIntent(value, 'GBP'); await Stripe.instance.initPaymentSheet( paymentSheetParameters: SetupPaymentSheetParameters( paymentIntentClientSecret: paymentIntentData!['client_secret'], applePay: PaymentSheetApplePay(merchantCountryCode:'UK'), googlePay: PaymentSheetGooglePay( merchantCountryCode: 'UK', testEnv: true, currencyCode: "GBP", // 修改为大写格式 ), style: ThemeMode.light, merchantDisplayName: '你的商家名称', // 建议使用真实商家名称,避免"off"这类非常规值 ), );
额外检查项
- 确认Android端已正确集成Google Pay配置:在
android/app/src/main/AndroidManifest.xml中添加Stripe要求的meta-data和权限 - 优先使用真实Android设备测试(部分模拟器未配置Google Play服务,无法加载Google Pay)
内容的提问来源于stack exchange,提问作者Tanveer Ahmad
相关产品推荐
相关产品推荐

