This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
@stripe/stripe-react-native
一个提供访问原生 API 以集成 Stripe 支付的库。
Expo 支持 @stripe/stripe-react-native,它允许你使用 React Native 和 Expo 在原生 Android 和 iOS 应用中构建令人愉悦的支付体验。这个库提供了功能强大且可自定义的 UI 界面和元素,可直接开箱即用,用于收集用户的支付信息。
正在从 Expo 的
expo-payments-stripe模块迁移?了解更多如何迁移到新的@stripe/stripe-react-native库。

完整演示如何在一个通用的 Expo 应用中集成 Stripe 支付,覆盖 Android、iOS 和 Web。
安装
每个 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 商家 ID。否则,Apple Pay 将无法按预期工作。如果你有多个 merchantIdentifiers,可以将它们设置在数组中。
- enableGooglePay:仅适用于 Android。表示是否启用 Google Pay 的布尔值。默认值为
false。
示例
试用 Stripe 只需几秒钟。在你的设备上连接到 这个 Snack。
在底层,该示例连接到一个用于支付处理的 Glitch 服务器。
用法
有关用法信息和详细文档,请参阅以下资源:
常见问题
浏览器弹出窗口无法重定向回我的应用
如果你依赖重定向,你需要将 urlScheme 传递给 initStripe。为了确保始终使用正确的 urlScheme,请传入:
import * as Linking from 'expo-linking'; import Constants from 'expo-constants'; urlScheme: Constants.appOwnership === 'expo' ? Linking.createURL('/--/') : Linking.createURL(''),
Linking.createURL() 将确保你使用的是正确的 scheme,无论你是在 Expo Go 中运行还是在生产应用中运行。'/--/' 在 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
Google Pay 不支持 Expo Go。要使用 Google Pay,必须创建一个开发构建。可以使用 EAS Build 完成,也可以在本地运行 npx expo run:android。
Apple Pay
Apple Pay 不支持 Expo Go。要使用 Apple Pay,必须创建一个开发构建。可以使用 EAS Build 完成,也可以在本地运行 npx expo run:ios。