@ 连接- xyz/ 退出- js
一个JavaScript SDK,可以使前端应用与Connect rescreen产品无缝地相接.
连接退出为终端用户提取资金提供了一个安全的途径. 学多一点 连接撤回文档。 。 。 .
安装
国家预防机制(建议)
npm install @connect-xyz/withdraw-js
import { Withdraw } from '@connect-xyz/withdraw-js';
维娅 CDN
您可以导入索引文件中的脚本并使用其提供的撤销类 .
<script
type="module"
src="https://sdk.connect.xyz/withdraw-web/index.js"
></script>
或者你可以直接导入你的javascript代码.
import { Withdraw } from 'https://sdk.connect.xyz/withdraw-web/index.js';
开始
遵循这些简单的步骤, 将 Connect 撤回整合到您的前端应用程序 :
1. 导入退出模块
import { Withdraw } from '@connect-xyz/withdraw-js';
1.1 通过CDN导入
import { Withdraw } from 'https://sdk.connect.xyz/withdraw-web/index.js';
2. 将退出模块初始化到您的 App
// Create a Withdraw instance with configuration
const withdraw = new Withdraw({
jwt: 'your-jwt-token',
env: 'production', // or 'sandbox'
onError: ({ errorCode, reason }) => {
console.error('Withdraw error:', errorCode, 'Reason:', reason);
},
onClose: () => {
console.log('Withdraw widget closed');
},
onWithdrawal: ({ data }) => {
console.log('Withdrawal completed:', data);
},
onEvent: ({ type, data }) => {
console.log('Event received:', type, data);
},
onLoaded: () => {
console.log('Withdraw widget loaded and ready');
},
});
// Render the widget to a container element
const container = document.getElementById('withdraw-container');
await withdraw.render(container);
// Update configuration dynamically
withdraw.updateConfig({
jwt: 'new-jwt-token',
onError: newErrorHandler,
});
// Check if rendered
if (withdraw.isRendered()) {
console.log('Widget is active');
}
// Clean up when done
withdraw.destroy();
API 参考
撤销部件道具
| Prop | 类型 | 需求 | 默认 | 说明 |
|---|---|---|---|---|
jwt | string | 对 | - 说吧 | 用 Connect 撤回认证的 JWT 令牌 |
env | "production" | "sandbox" | 没有 | "production" | 目标环境 |
theme | "auto" | "light" | "dark" | 没有 | "auto" | 界面的主题模式 |
onError | ({ errorCode, reason }) => void | 没有 | - 说吧 | 调用错误事件 |
onClose | () => void | 没有 | - 说吧 | 部件关闭时召回 |
onWithdrawal | ({ data }) => void | 没有 | - 说吧 | 撤回请求完成 |
onEvent | ({ type, data }) => void | 没有 | - 说吧 | 召回一般活动 |
onLoaded | () => void | 没有 | - 说吧 | 部件装入并准备就绪时召回 |
构造器
new Withdraw(config: WithdrawConfig)
使用提供的配置创建新的撤回实例.
参数
config(退出) Config : 配置对象jwt(字符串,需要):JWT认证标志env(字符串,可选):环境 - “ 生产” (默认) 或“ 散装箱”theme(弦,可选): 主题模式 - “ 自动” (默认)、 “ 光” 或 “ 暗”onError(职能,可选): 回调错误onClose(职能,可选): 关闭回调onWithdrawal(职能,可选): 撤回调用onEvent(职能,可选): 一般事件召回onLoaded(职能,可选): 装入部件并准备就绪时召回
方法
render(container: HTMLElement): Promise<void>
将撤销部件带入指定的容器元素.
await withdraw.render(document.getElementById('withdraw-container'));
updateConfig(config: Partial<WithdrawConfig>): void
更新已渲染部件的配置.
withdraw.updateConfig({
jwt: 'new-token',
onError: newErrorHandler,
});
destroy(): void
从 DOM 中删除部件并清理资源.
withdraw.destroy();
isRendered(): boolean
返回当前部件是否已打开 .
if (withdraw.isRendered()) {
// Widget is active
}
getConfig(): WithdrawConfig
返回当前配置的副本.
const config = withdraw.getConfig();
console.log('Current JWT:', config.jwt);
回调函数
关于召回事件及其有效载荷的详情,见 撤销 SDK 回调文档。 。 。 .
错误
当撤消部件出错时调用 .
onError: ({ errorCode, reason }) => {
// errorCode: Error code
// reason: Human-readable error description
};
关闭
当用户关闭撤回部件时调用 .
onClose: () => {
// Handle close event
};
退出时
退出完成后调用.
onWithdrawal: ({ data }) => {
// data: Object containing withdrawal details
};
活动
从撤消部件中调用一般事件 .
onEvent: ({ type, data }) => {
// type: Event type string
// data: Event-specific data object
};
已登录
当撤回部件已全部装入并准备好用户交互时调用 。 此调用在部件初始化后显示装入状态或执行动作时有用 .
onLoaded: () => {
// Widget is fully loaded and ready
};
浏览器支持
- 克罗梅/第90号+
- Firefox 88+ (英语)
- 萨法里14+
- 所有有 Web 组件支持的现代浏览器
更多信息与支持
关于Connect撤回的全面文件或支持,请访问 页 次。 。 。 .