React Native集成Stripe时Google Pay选项不显示问题排查
React Native Stripe支付中Google Pay不显示的排查问题
我正遵循Stripe移动元素指南在React Native应用中搭建Stripe支付功能。点击“结算”时,仅显示银行卡详情选项,未出现Google Pay选项。以下是相关配置:
代码片段:
const { error, paymentOption } = await initPaymentSheet({ merchantDisplayName: "Example, Inc", customerId: customer, customerEphemeralKeySecret: ephemeralKey, paymentIntentClientSecret: paymentIntent, // Set `allowsDelayedPaymentMethods` to true if your business can handle payment //methods that complete payment after a delay, like SEPA Debit and Sofort. allowsDelayedPaymentMethods: true, defaultBillingDetails: { name: 'Jane Doe', }, googlePay: { merchantCountryCode: 'US', testEnv: true, // use test environment currencyCode: 'USD', }, });
AndroidManifest.xml配置:
<meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true" />
app/build.gradle依赖:
dependencies { implementation("com.stripe:stripe-android:20.36.1") implementation("com.google.android.gms:play-services-wallet:19.3.0-beta01") }
build.gradle仓库配置:
allprojects { repositories { google() mavenCentral() } }
我已开启测试模式,且安装并配置了Google Pay,但结算时仍仅显示银行卡选项,请问我遗漏了什么配置?
可能的遗漏配置及解决方案
- 校验Payment Intent与Google Pay的货币一致性:确保你的
paymentIntent使用的货币为USD,和Google Pay配置的currencyCode: 'USD'完全匹配,Stripe会自动过滤掉货币不匹配的支付方式。 - 修复SDK版本兼容性问题:你使用的
play-services-wallet:19.3.0-beta01是测试版,可能与stripe-android:20.36.1存在兼容问题,建议替换为稳定版(如19.2.0),避免beta版本的潜在bug。 - 验证设备对Google Pay的支持状态:在测试设备上,确认Google Pay已登录测试账号,且设备满足基础支持条件(系统版本≥Android 4.4 KitKat、支持NFC)。可调用Stripe提供的方法提前检查:
import { isGooglePaySupported } from '@stripe/stripe-react-native'; const checkGooglePaySupport = async () => { const { supported } = await isGooglePaySupported({ merchantCountryCode: 'US', currencyCode: 'USD', }); console.log('Google Pay 支持状态:', supported); }; - 补充测试商户ID:测试环境下可添加官方测试商户ID(
BCR2DN7TP45274X7)完善Google Pay配置,确保识别逻辑正常:googlePay: { merchantCountryCode: 'US', testEnv: true, currencyCode: 'USD', merchantId: 'BCR2DN7TP45274X7', }, - 清理缓存并重新构建项目:执行Android端的
./gradlew clean命令清理构建缓存,再重新运行React Native项目,避免旧配置残留导致的不生效问题。 - 检查Payment Sheet展示逻辑:确认初始化Payment Sheet后,正确调用了
presentPaymentSheet(),且没有额外的业务逻辑隐藏Google Pay选项。
内容的提问来源于stack exchange,提问作者Wanderer
相关产品推荐
相关产品推荐

