This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 55).
@stripe/stripe-react-native
一个提供原生 API 访问的库,用于集成 Stripe 支付。
For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.
Expo 包含对 @stripe/stripe-react-native 的支持,这使你能够使用 React Native 和 Expo 在原生 Android 和 iOS 应用中构建令人愉悦的支付体验。这个库提供了强大且可定制的 UI 界面和元素,可直接开箱即用,用于收集用户的支付详情。
正在从 Expo 的
expo-payments-stripe模块迁移?了解如何迁移到新的@stripe/stripe-react-native库。

在一个通用 Expo 应用中跨 Android、iOS 和 web 集成 Stripe 支付的完整演示。
安装
每个 Expo SDK 版本都需要特定版本的 @stripe/stripe-react-native。请参阅 Stripe CHANGELOG 了解版本对应关系。要自动安装与你的 Expo SDK 版本匹配的正确版本,请运行:
- npx expo install @stripe/stripe-react-nativeIf you are installing this in an existing React Native app, make sure to install expo in your project. Then, follow the installation instructions provided in the library's README or documentation.
配置插件设置(可选)
如果你正在使用 EAS Build,你可以使用 @stripe/stripe-react-native 的 配置插件 来完成大部分 Stripe 设置。要进行设置,只需按照下面所示,将配置插件添加到你的 app.json 或 app.config.js 的 plugins 数组中,然后重新构建应用。
{ "expo": { %%placeholder-start%%... %%placeholder-end%% "plugins": [ [ "@stripe/stripe-react-native", { "merchantIdentifier": string | string [], "enableGooglePay": boolean } ] ], } }
- merchantIdentifier:仅限 iOS。这是 在此处获取的 Apple merchant ID。否则,Apple Pay 将无法按预期工作。如果你有多个 merchantIdentifiers,可以将它们放在数组中。
- enableGooglePay:仅限 Android。布尔值,表示是否启用 Google Pay。默认值为
false。
示例
试用 Stripe 只需几秒钟。在你的设备上连接到 这个 Snack。
在底层,该示例连接到一个 Glitch 服务器进行支付处理。
用法
有关用法信息和详细文档,请参阅以下资源:
常见问题
浏览器弹窗没有重定向回我的应用
如果你依赖重定向,就需要向 initStripe 传入 urlScheme。为了确保始终使用正确的 urlScheme,请传入:
import * as Linking from 'expo-linking'; import Constants from 'expo-constants'; urlScheme: Constants.appOwnership === 'expo' ? Linking.createURL('/--/') : Linking.createURL(''),
Linking.createURL() 将确保无论你是在 Expo Go 中运行还是在生产应用中运行,都能使用正确的 scheme。'/--/' 在 Expo Go 中是必要的,因为它表示其后的子字符串对应于深度链接路径,而不是应用本身路径的一部分。
iOS 上的 PaymentSheet 本地化
在 Android 上,PaymentSheet 的翻译会根据设备的语言设置自动检测。
在 iOS 上,你必须启用 CFBundleAllowMixedLocalizations,并在应用配置中的 ios.infoPlist 下使用 CFBundleLocalizations 添加首选语言:
{ "expo": { "ios": { "infoPlist": { "CFBundleAllowMixedLocalizations": true, "CFBundleLocalizations": ["fr"] %%placeholder-start%%... %%placeholder-end%% } %%placeholder-start%%... %%placeholder-end%% } } }
限制
Google Pay
Expo Go 不支持 Google Pay。要使用 Google Pay,你必须创建一个开发构建。这可以通过 EAS Build 完成,也可以在本地运行 npx expo run:android。
Apple Pay
Expo Go 不支持 Apple Pay。要使用 Apple Pay,你必须创建一个开发构建。这可以通过 EAS Build 完成,也可以在本地运行 npx expo run:ios。