Android应用集成Stripe Google Pay无法正常启动问题
解决Stripe Android集成Google Pay闪屏关闭问题
针对你遇到的Google Pay点击后闪屏关闭、无法正常启动的问题,可按以下步骤排查修复:
1. 先完善错误日志捕获(最关键的第一步)
你的onGooglePayResult方法为空实现,无法获取具体错误原因,先补充日志输出,直接定位问题根源:
private void onGooglePayResult(@NotNull GooglePayLauncher.Result result) { if (result instanceof GooglePayLauncher.Result.Failed) { GooglePayLauncher.Result.Failed failedResult = (GooglePayLauncher.Result.Failed) result; // 打印错误信息到Logcat Log.e("GooglePayError", "错误码: " + failedResult.getError().getCode() + ", 错误信息: " + failedResult.getError().getMessage()); } }
运行后查看Logcat的错误日志,能快速区分是Payment Intent问题、配置问题还是设备端问题。
2. 检查Payment Intent的有效性
确保后端生成的clientSecret对应的Payment Intent满足以下要求:
- 货币类型必须与配置的
countryCode="IN"匹配,即使用INR(印度卢比),不能混用其他货币; - Payment Intent的状态为
requires_payment_method(未被处理过的初始状态); - 测试环境下金额需大于0(例如设置为100 INR,对应1印度卢比);
- 后端需使用正确的Stripe密钥(测试模式用测试密钥,生产模式用生产密钥)。
3. 修正GooglePayLauncher.Config的配置问题
你的Config参数存在核心问题:同时禁用了信用卡和借记卡,导致Google Pay无可用支付选项,直接关闭。修改配置允许至少一种支付方式:
final GooglePayLauncher googlePayLauncher = new GooglePayLauncher( this, new GooglePayLauncher.Config( GooglePayEnvironment.Test, "IN", "My Store", true, // 允许信用卡 new GooglePayLauncher.BillingAddressConfig(), true, // 允许借记卡 false ), this::onGooglePayReady, this::onGooglePayResult );
若问题仍存在,可临时将countryCode改为US、货币改为USD测试,排除地区兼容性问题。
4. 设备端Google Pay测试配置
- 确保设备上的Google Pay应用已添加Stripe测试卡片(例如
4242 4242 4242 4242,有效期选未来年份,CVV随便填3位); - 检查Google Play服务是否为最新版本,旧版本可能导致兼容性问题;
- 若使用模拟器,需确保模拟器支持Google Play服务且已登录Google账号。
5. 补充必要的权限
确认AndroidManifest.xml中添加了互联网权限:
<uses-permission android:name="android.permission.INTERNET" />
Stripe和Google Pay都需要网络通信,缺少该权限会导致请求失败。
内容的提问来源于stack exchange,提问作者Prajwal Waingankar
相关产品推荐
相关产品推荐

