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

Jetpack Compose中Stripe支付界面不显示Google Pay按钮问题

问题排查与修复建议
  • 检查Google Pay服务基础可用性
    Google Pay按钮仅在设备满足以下条件时才会显示:安装了Google Pay应用、所在地区支持该服务、设备绑定了符合要求的支付方式。测试环境下必须使用Stripe提供的测试卡片(如4242 4242 4242 4242),同时要在Google Pay应用中开启测试模式(路径:设置 -> 支付方式 -> 测试环境)。

  • 确认PaymentSheet配置细节
    你的代码中已配置核心参数,但需注意:

    • environment设为Test时,必须配合测试卡片和设备测试模式,否则Google Pay会被判定为不可用;
    • merchantDisplayName需为有效非空字符串,避免特殊字符或空值。
  • 避免重复触发支付流程
    代码中同时监听confirmPaymentParams和clientSecret两个状态,会导致PaymentSheet被重复调用,干扰界面渲染。建议只保留一种启动方式,优先使用最新的PaymentLauncher API,调整示例如下:

    val paymentLauncher = rememberPaymentLauncher(
        publishableKey = "你的公钥",
        stripeAccountId = null // 无需多账户时设为null
    ) { result ->
        viewModel.handlePaymentResult(result)
    }
    
    val confirmPaymentParams by viewModel.confirmPaymentParams.collectAsState()
    LaunchedEffect(confirmPaymentParams) {
        confirmPaymentParams?.let { params ->
            paymentLauncher.confirm(params)
            viewModel.onPaymentLaunched()
        }
    }
    

    构建ConfirmPaymentParams时需完整包含Google Pay配置:

    val confirmParams = ConfirmPaymentParams.createWithPaymentIntent(
        clientSecret = "你的clientSecret",
        configuration = PaymentSheet.Configuration(
            googlePay = PaymentSheet.GooglePayConfiguration(
                countryCode = "US",
                environment = PaymentSheet.GooglePayConfiguration.Environment.Test,
                currencyCode = "USD"
            ),
            merchantDisplayName = "yyyy"
        )
    )
    
  • 升级Stripe SDK版本
    旧版本Stripe Android SDK可能存在Google Pay配置解析bug,确保依赖使用最新稳定版:

    implementation "com.stripe:stripe-android:20.+"
    
  • 查看Stripe日志定位原因
    运行应用时,在Logcat中过滤关键词Stripe或GooglePay,SDK会输出按钮不显示的具体原因,比如区域不支持、无可用支付方式等。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 00:03:16