Google Pay
了解如何用 Google Pay 收款。
借助 Google Pay,客户可以用他们在 Google 账户中存储的信用卡或借记卡在您的应用或网站上进行支付,包括 Google Play、YouTube、Chrome 或 Andriod 设备中绑定的银行卡。用 Google Pay API 请求您的客户在 Google 账户中存储的任何信用卡或借记卡。
Google Pay 与 Stripe 的产品和功能(例如,经常性付款)完全兼容,您可以随时在需要时用它替换传统的支付表单。用它来接收实物商品、捐赠、订阅等的付款。
Google Pay 条款
集成 Google Pay,表示您同意 Google 的服务条款。
注意
要在 Checkout 中提供 Google Pay 作为支付方式以及收货地址,您必须提供运费。
使用 Stripe 和 Google Pay 与 Google Play 计费系统
对于实物商品和服务的销售,您的应用程序可以接受 Google Pay 或任何其他 Stripe 支持的支付方式。这些付款是通过 Stripe 处理的,只需支付 Stripe 的手续费。但是,应用内购买数字产品和内容必须使用 Google Play 计费系统。这些付款由 Google 处理,会收取交易费。
有关哪些购买必须使用 Google Play 计费系统的更多信息,请参见 Google Play 的开发人员条款。
Stripe 的 React Native SDK 是在您的 React Native 应用中开始接受 Google Pay 的最快最便捷的方式。PlatformPayButton 组件包着 Google 要求的 UI,您可以通过最少的设置,用 confirmPlatformPayPayment
和 createPlatformPayPaymentMethod
方式在您的应用中无缝收取或创建付款。
注意
设置 Stripe服务器端客户端
服务器端
该集成要求您的服务器上的端点与 Stripe API 通讯。请用我们的官方库从您的服务器访问 Stripe API:
客户端
React Native SDK 是开源的,有完整的文档。在内部,它利用的是原生 iOS 和 Android SDK。要安装 Stripe 的 React Native SDK,在您的项目目录中运行以下某个指令(取决于您使用的软件包管理器)。
然后,安装一些其他必要的依赖项:
- 对于 iOS,前往 ios 目录并运行
pod install
,确保您也安装了所需的本地依赖项。 - 对于 Android,无需安装其他依赖项。
注意
建议按照官方 TypeScript 指南添加 TypeScript 支持。
Stripe 初始化
要在您的 React Native 应用中初始化 Stripe,使用 StripeProvider
组件包裹您的支付界面,或者使用 initStripe
初始化方法。只需要 publishableKey
中的 API 公钥。下例显示的是用 StripeProvider
组件初始化 Stripe 的方式。
import { useState, useEffect } from 'react'; import { StripeProvider } from '@stripe/stripe-react-native'; function App() { const [publishableKey, setPublishableKey] = useState(''); const fetchPublishableKey = async () => { const key = await fetchKey(); // fetch key from your server here setPublishableKey(key); }; useEffect(() => { fetchPublishableKey(); }, []); return ( <StripeProvider publishableKey={publishableKey} merchantIdentifier="merchant.identifier" // required for Apple Pay urlScheme="your-url-scheme" // required for 3D Secure and bank redirects > {/* Your app code here */} </StripeProvider> ); }
启用 Google Pay
要使用 Google Pay,先将以下内容添加到您的 AndroidManifest.xml 的 <application>
标签,来启用 Google Pay API:
<application> ... <meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true" /> </application>
更多详情,请参见 Google Pay 针对 Android 设备编写的设置 Google Pay API 指南。
创建 PaymentIntent服务器端
首先,在您的服务器上创建一个 PaymentIntent
,并指定要收取的金额和币种。如果您已经有使用 Payment Intents API 的集成,则为您的 PaymentIntent
向 支付方式类型列表中添加 card
(在未提供支付方式的情况下,这也是默认支付方式)。
PaymentIntent 包含一个客户端私钥。您可以在您的 React Native 应用中用客户端私钥安全地完成付款流程,而非传回整个 PaymentIntent 对象。在您的应用中,从您的服务器请求 PaymentIntent 并保存它的客户端私钥。
初始化 Google Pay客户端
首先,通过调用 isPlatformPaySupported
查看设备是否支持 Google Pay。
import { usePlatformPay } from '@stripe/stripe-react-native'; function PaymentScreen() { const { isPlatformPaySupported } = usePlatformPay(); React.useEffect(() => { (async function () { if (!(await isPlatformPaySupported({ googlePay: {testEnv: true} }))) { Alert.alert('Google Pay is not supported.'); return; } })(); }, []); ... return ( <View > ... </View> ); }
展示 Google Pay 表单客户端
开通 Google Pay 并且您的应用程序获得了 PaymentIntent
或 SetupIntent
客户端私钥后,调用 confirmPlatformPayPayment
。确认 SetupIntent
时,改为使用 confirmPlatformPaySetupIntent
。
import {PlatformPayButton, usePlatformPay} from '@stripe/stripe-react-native'; function PaymentScreen() { const { isPlatformPaySupported, confirmPlatformPayPayment, } = usePlatformPay(); React.useEffect(() => { ... // see above }, []); const fetchPaymentIntentClientSecret = async () => { // Fetch payment intent created on the server, see above const response = await fetch(`${API_URL}/create-payment-intent`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ currency: 'usd', }), }); const { clientSecret } = await response.json(); return clientSecret; }; const pay = async () => { const clientSecret = await fetchPaymentIntentClientSecret(); const { error } = await confirmPlatformPayPayment( clientSecret, { googlePay: { testEnv: true, merchantName: 'My merchant name', merchantCountryCode: 'US', currencyCode: 'USD', billingAddressConfig: { format: PlatformPay.BillingAddressFormat.Full, isPhoneNumberRequired: true, isRequired: true, }, }, } ); if (error) { Alert.alert(error.code, error.message); // Update UI to prompt user to retry payment (and possibly another payment method) return; } Alert.alert('Success', 'The payment was confirmed successfully.'); }; return ( <View > <PlatformPayButton type={PlatformPay.ButtonType.Pay} onPress={pay} style={{ width: '100%', height: 50, }} /> </View> ); }
推出 Google Pay
按照 Google 的说明,请求访问您的应用程序的生产环境。收到提示时,选择集成类型 Gateway,并提供您的应用的截图供审核。
您的应用程序得到批准后,用 testEnv: false
在生产模式下测试您的集成,然后从一个签署的已发布版本启动 Google Pay。请记得使用您的真实模式下的 API 密钥。您可以用包含 capture_
= manual
的 PaymentIntent
来在不捕获付款的情况下处理交易。
测试 Google Pay
Google 允许您通过其测试卡套件进行测试支付。该测试套件支持使用 Stripe 测试卡。
您可以使用实体 Android 设备测试 Google Pay。确保您的设备位于支持 Google Pay 的国家/地区,并在测试设备上登录到 Google 账户,且 Google Wallet 中保存有真实银行卡数据。
争议
用户必须验证用他们的 Google Pay 账户进行的付款,以降低发生欺诈或付款无法识别的风险。但是,用户仍然可以在完成付款后对交易提出争议。您可以直接提交证据,对争议提出质疑。争议流程与银行卡付款相同。了解如何管理争议。
Google Pay 收款的责任转移
Google Pay 支持全球范围内的责任转移。使用 Stripe 托管产品和 Stripe.js 的用户可自动启用。对于 Stripe 托管产品之外的 Visa 交易,必须在 Google Pay 和 Wallet Console 中启用责任转移。为此,请导航到您的 Google Pay & Wallet Console,选择左侧导航栏中的_Google Pay API_,然后为责任转移保护启用 Fraud Liability Protection for Visa Device Tokens。
Google Pay 交易可在三种场景中使用:
- 如果用户用其移动设备向 Google Pay 应用添加银行卡,则该卡会作为一个设备主账号 (DPAN) 进行保存,并且默认支持责任转移。
- 如果用户向 Chrome 或 Google 的一个属性(例如,YouTube 或 Play)添加银行卡,那么该银行卡会作为充值主账号 (FPAN) 进行保存。当您使用 3DS 验证时,我们全球支持所有主要卡组织的责任转移,包括 Visa。您可以自定义 Stripe Radar 规则来请求激活 3DS 验证。
- 如果用户在用 Google Pay 支付的电商网站或应用中选择 Google Pay 作为支付方式,则这些卡将以电商令牌的形式保存,在文件中表示这些卡。目前电商令牌不支持责任转移和 3DS 验证。
对于 Sigma 用户,charges
表包含一个指示 Google Pay 交易类型的 card_
字段。FPAN 交易将 card_
设置为 fpan
。DPAN 和电商令牌交易将 card_
设置为 dpan_
。
退款
您可以部分或全额退还任何成功的 Google Pay 付款。退款流程与银行卡付款相同。有关发起或管理退款的说明,请参阅退款和取消付款。