3DS 反应原生 SDK
这个 基础理论 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换句话说. - 博览会( E)
只允许 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/) (中文(简体) ).
文档
关于终点和例子的完整清单,请参见我们 正式文件。 。 。 .
捐款
见 贡献指南 学习如何为储存库和发展工作流程作出贡献.