DapiConnect iOS SDK
概述
简介
DapiConnect for iOS 是一个预构建的 SDK,可缩短与 Dapi API 集成的时间和获取用户财务数据的时间。
该 SDK 提供对 Dapi 端点的直接访问,并提供了可选的 UI 来管理用户的账户、子账户、余额和转账。
需求
- iOS v10.3 或更高版本
- App密钥(从 Dapi Dashboard 获取)
- DapiConnect 框架的最新版本(从 DapiConnect.framework 获取)
- SDK 服务器(见下文)iOS v10.3 或更高版本
开始前
目前,SDK 仅通过 CocoaPods 提供。要开始集成 DapiConnect.framework
-
更新你的 Podfile 以包含
pod 'DapiConnect'
-
在你的项目目录中运行以下命令
pod install
如何工作
DapiConnect SDK 通过与 API 端点通信来发送网络请求。请求不会直接发送到 Dapi 服务器。相反,请求首先发送到您的服务器,然后发送到 Dapi 服务器。
原因?
这是一个安全功能,可以保持控制权在您手中。您的服务器负责通过创建、存储和刷新访问令牌来维护访问令牌。请看下面的示例 Gif:
集成
DapiConnect SDK 可以通过以下步骤进行集成
-
在您的应用程序代理中导入 DapiConnect
import DapiConnect
-
使用您的配置创建 Dapi 客户端
private lazy var client: DapiClient = { let appKey = "8900eff4837592670c08558c7a6467337b5155145856d693f1e8275455889f7f" var urlComponents = URLComponents() urlComponents.scheme = "http" urlComponents.host = <#YourServerURL#> urlComponents.port = 4561 let configs = DapiConfigurations(appKey: appKey, baseUrl: urlComponents, countries: ["AE"], clientUserID: "MohammedEnnabah") configs.environment = .sandbox configs.isExperimental = false let client = DapiClient(configurations: configs) client.connect.delegate = self client.autoFlow.connectDelegate = self client.autoFlow.autoflowDelegate = self return client }()
您可以从此处获得您的应用程序令牌
-
如果您没有使用 SDK-Server
我们提供了一个服务器 SDK,以便 DapiConnect-iOS 可以与之通信。默认情况下,DapiConnect-iOS 与 Dapi 文档中指定的端点通信。
如果您的服务器上自定义实现公开的端点命名与Dapi 文档中提到的不同,您需要将端点传递给
DPCConfigurations
的endpoint
属性。var endpoints: [DPCEndPoint: String]
组件
DapiConnect 由 3 个核心类组成:DPCConnect
、DPPayment
和 DPAutoFlow
。
DPCConnect
负责显示银行列表、凭据输入、授权和认证。您可以通过将您的类分配给其 connectDelegate
属性来接收回调。
override func viewDidLoad() {
super.viewDidLoad()
client.connect.present() // or DapiClient.instance.connect.present()
}
// MARK: - Connect delegate methods.
func connectDidSuccessfullyConnect(toBankID bankID: String, userID: String) {
print("✅")
}
func connectDidFailConnecting(toBankID bankID: String, withError error: String) {
print("🚩")
}
API
您可以使用 client
对象调用身份验证、数据、元数据和支付端点。
override func viewDidLoad() {
super.viewDidLoad()
client.data.getAccounts { (accounts, error, jobID) in
print(accounts)
}
}
DPAutoFlow
该组件是自动导航,为您减轻所有繁重的工作。它将会显示已连接的账户列表,并允许用户连接更多账户、删除现有账户、查看余额和发起支付。
它有一个必需的委托方法,用于请求进行转账所需的收款人信息。
override func viewDidLoad() {
super.viewDidLoad()
client.autoFlow.present()
}
func autoFlow(_ autoFlow: DapiAutoFlow, beneficiaryInfoForBankID bankID: String, supportsCreateBeneficiary: Bool) -> DapiBeneficiaryInfo {
let info = DapiBeneficiaryInfo()
let lineAddress = DapiLinesAddress()
lineAddress.line1 = ""
lineAddress.line2 = ""
lineAddress.line3 = ""
info.linesAddress = lineAddress
info.accountNumber = ""
info.bankName = ""
info.swiftCode = ""
info.iban = ""
info.country = "UNITED ARAB EMIRATES"
info.branchAddress = "branchAddress"
info.branchName = "branchName"
info.phoneNumber = "123213123123123"
info.name = ""
return info
}
func autoFlow(_ autoFlow: DapiAutoFlow, didSuccessfullyTransferAmount amount: Double, fromAccount senderAccountID: String, toAccuntID recipientAccountID: String) {
}
func autoFlow(_ autoFlow: DapiAutoFlow, didFailToTransferFromAccount senderAccountID: String, toAccuntID recipientAccountID: String?, withError error: Error) {
}