@basis-theory/react-native-threeds

中文文档
1.3.0发布于 2026/10/03Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 1.6万

基础理论 3DS 反应原生 SDK

中文使用文档
文档目录8 节
  1. 安装
  2. 使用量
  3. 网络视频
  4. 启用本地 3DS
  5. 土著
  6. 选择本土战略
  7. 文档
  8. 捐款

3DS 反应原生 SDK

Version

这个 基础理论 3DS 反应原生 SDK.

安装

使用 节点软件包管理器

npm install @basis-theory/react-native-threeds

使用 雅伦

yarn add @basis-theory/react-native-threeds

使用量

SDK提供三种策略. 他们共享相同的流:对卡进行标记,创建3DS会话,并让后端用您私人的 API 密钥认证.

战略iOS系统机器人博览去
网络视频✅✅✅
桥✅✅❌
涡轮模块✅❌❌

本土战略(Bridge和TurboModule)需要发展(expo prebuild 或赤裸裸的回放原生应用程序。 博览会 Go 只能使用 WebView.

以下例子如下: tokenId 用于您已经创建的纸牌符号, 例如 反应原生元素。 。 。 .

网络视频

包装您的应用程序 BasisTheory3dsProvider 和使用情况 useBasisTheory3ds 在其下方的任何组件中。 提供商将挑战 作为其孩子的顶部, 所以挂在您的应用程序的根部.

import { Button } from 'react-native';
import {
  BasisTheory3dsProvider,
  useBasisTheory3ds,
} from '@basis-theory/react-native-threeds';

const App = () => (
  <BasisTheory3dsProvider apiKey="<PUBLIC_API_KEY>">
    <Checkout tokenId="<TOKEN_ID>" />
  </BasisTheory3dsProvider>
);

const Checkout = ({ tokenId }: { tokenId: string }) => {
  const { createSession, startChallenge } = useBasisTheory3ds();

  const pay = async () => {
    const session = await createSession({ tokenId });

    // Your backend authenticates the session with your private API key.
    const authentication = await yourBackend.authenticate(session.id);

    if (authentication.authentication_status_code === 'C') {
      await startChallenge({
        sessionId: session.id,
        acsChallengeUrl: authentication.acs_challenge_url,
        acsTransactionId: authentication.acs_transaction_id,
        threeDSVersion: authentication.threeds_version,
      });
    }
  };

  return <Button title="Pay" onPress={pay} />;
};

启用本地 3DS

原生地3DS默认关闭,因此WebView-Only apps的构建完全如前:没有原生地代码,没有额外的SDK,没有额外的设置. 要启用它,请将此添加到您的应用程序中 package.json数字 :

{
  "@basis-theory/react-native-threeds": {
    "native": true
  }
}

然后重建应用程序.

  • iOS: (英语) 运行 pod install. 它下载了Ravelin的3DS SDK,本地融合使用. 需要iOS 15 或 后期.

  • 机器人: Ravelin的 3DS SDK 需要在您的应用模块中进行两个更改,一个库无法为您做: 核心图书馆,并排除 META-INF 报告拉维林的OKhttp依赖和AndroidX两艘船.

    • 博览会( E)expo prebuild: 将配置插件添加到 app.json 它在每一个建设前都增加了:
      { "expo": { "plugins": ["@basis-theory/react-native-threeds"] } }
      
    • 浅显反射原生,或有承诺的博览会 android/数字 : 将这些行添加到 android/app/build.gradle数字 :
      android {
          compileOptions {
              coreLibraryDesugaringEnabled true
          }
          packagingOptions {
              resources {
                  excludes += "META-INF/versions/9/OSGI-INF/MANIFEST.MF"
              }
          }
      }
      
      dependencies {
          coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'
      }
      

    图书馆自动将拉弗林的马文寄存器添加到您的构建中. 狦 settings.gradle 套装 repositoriesMode 改为 PREFER_SETTINGS 或者说 FAIL_ON_PROJECT_REPOS,Gradle忽略或拒绝存储器,所以添加 https://maven.ravelin.com/public/repositories/threeds2service/ 改为 dependencyResolutionManagement.repositories 内 settings.gradle 换句话说.

只允许 native 如果使用的话 BasisTheoryThreeDS 或者说 BasisTheoryThreeDSStrategies。 仅用WebView的应用程序 desugar_jdk_libs 与构造连接,而不连接任何本地 3DS 代码.

土著

BasisTheoryThreeDS 使用iOS上的涡轮Module 当你的建筑编译它, 和桥 其他任何地方。 不需要供应商。 本地SDK打电话给你 authenticationEndpoint 与会话ID,如果银行需要挑战,在您的应用程序上展示.

import { useEffect, useState } from 'react';
import { Button } from 'react-native';
import { BasisTheoryThreeDS } from '@basis-theory/react-native-threeds';

const Checkout = ({ tokenId }: { tokenId: string }) => {
  const [ready, setReady] = useState(false);

  useEffect(() => {
    BasisTheoryThreeDS.configure({
      apiKey: '<PUBLIC_API_KEY>',
      // Your backend: receives the session ID and authenticates it with your private API key.
      authenticationEndpoint: 'https://your-backend.example.com/3ds/authenticate',
    }).then(() => setReady(true));
  }, []);

  const pay = async () => {
    const session = await BasisTheoryThreeDS.createSession({ tokenId });
    const result = await BasisTheoryThreeDS.startAuthentication(session.id);
    // result.status: 'successful' | 'attempted' | 'failed' | 'unavailable' | 'rejected'
    //   | 'decoupled_challenge' | 'informational'
  };

  return <Button title="Pay" disabled={!ready} onPress={pay} />;
};

失败或取消的挑战解决方式 status: 'failed' 和原因在内 result.details。 。 。 . decoupled_challenge 表示您的应用程序外的发行人认证: 订阅 3ds.session.decoupled-challenge-notification 网络浏览以学习完成后, 然后从您的后端获取结果 获取挑战结果· ; informational 表示没有请求认证. 承诺只在配置,运输,或SDK出错时拒绝.

要强制一个策略,使用 BasisTheoryThreeDSStrategies.ios.bridge, (中文(简体) ), BasisTheoryThreeDSStrategies.ios.turboModule,或 BasisTheoryThreeDSStrategies.android.bridge他们暴露了同样的方法. ios.turboModule 需要新建新架构; 请检查 isThreeDSTurboModuleAvailable()。 。 。 .

选择本土战略

大桥总被编译. TurboModule在iOS上加上了新架构:

  • iOS: (英语) 在React Industrial 0.82和后期,涡轮摩多仪总是被编译. 在0.81时, newArchEnabled 选择: 在 app.json 用于博览会,或 ios/Podfile.properties.json (或 RCT_NEW_ARCH_ENABLED=1 pod install) (中文(简体) ). true 将涡轮摩多尔与大桥并列 false 只编译"桥". 运行 pod install 改变它之后,它再次.
  • 机器人: 没有配置。 只有"桥"被编译;Android TurboModule在此包中没有支持.

已测试使用反应原生0.81.5(见 example/) (中文(简体) ).

文档

关于终点和例子的完整清单,请参见我们 正式文件。 。 。 .

捐款

见 贡献指南 学习如何为储存库和发展工作流程作出贡献.

版本与发布记录

@basis-theory/react-native-threeds 共发布 6 个版本,首次发布于 2025/01/25;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.3.0latest2026/10/031 个月前
1.2.12026/09/121 个月前
1.1.22025/11/1111 个月前
1.1.12025/10/271 年前
1.1.02025/05/071.5 年前
1.0.02025/01/251.8 年前

关于 @basis-theory/react-native-threeds 的常见问题

@basis-theory/react-native-threeds 是什么?

基础理论 3DS 反应原生 SDK

如何安装 @basis-theory/react-native-threeds?

在项目目录运行 npm install @basis-theory/react-native-threeds,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(>=0.74.0)、react-native-webview(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@basis-theory/react-native-threeds 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@basis-theory/react-native-threeds 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@basis-theory/react-native-threeds 可以商用吗?

@basis-theory/react-native-threeds 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@basis-theory/react-native-threeds 的下载量有多少?

根据 npm 官方下载统计,@basis-theory/react-native-threeds 在 2026/10/08 – 2026/11/06 这 30 天内被下载 16,313 次,日均约 544 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@basis-theory/react-native-threeds 还在维护吗?

最新版本 1.3.0 发布于 2026/10/03(1 个月前);至今共发布 6 个版本,其中过去 12 个月发布了 3 个;首次发布于 2025/01/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。