Hellgate iOS SDK 通过 Cocoapods、Carthage 和 SPM 分发。
将以下行添加到您的 Podfile
pod 'Hellgate-iOS-SDK'
- 将以下行添加到您的
Cartfile
github "starfish-codes/hgate2-ios-headless-sdk"
- 在
Cartfile
相同的目录下运行
$ carthage update --use-xcframeworks
- 将构建的 XCFrameworks 添加到您的项目中的“框架和库”下
通过 Xcode 从 https://github.com/starfish-codes/hgate2-ios-headless-sdk.git
添加包
import Hellgate-iOS-SDK
使用以下视图来创建卡片表单
// Card number field, validation state and which side should the card images appear
CardNumberView(viewState: $viewModel.cardNumberViewState, image: .leading)
.border()
// Expiry date field, validation state
ExpiryDateView(viewState: $viewModel.expiryViewState)
.border()
// CVC and CVV view with view state and max length either .cvc or .cvv
CvcView(viewState: $viewModel.cvcViewState, length: .cvc)
.border()
每个字段都有一个 ViewState
,它看起来像这样
public enum ComponentState: String {
case complete
case incomplete
case blank
case invalid
}
public struct ViewState {
public let state: ComponentState
}
ViewStates
有助于确定用户填写字段的进度。
首先,我们需要使用从您后端发送的 sessionId
初始化一个 Hellgate 会话。
let hellgate = await initHellgate(baseUrl: hellgateURL, sessionId: sessionId)
接下来,我们需要从 Hellgate 会话中获取一个卡处理器,然后我们可以尝试根据在 UI 中之前定义的视图状态对卡片详情进行标记化。
// First try to get a valid card handler
let cardHandlerResult = await hellgate.cardHandler()
if case let .success(handler) = cardHandlerResult {
// Using the card handler and the previously defined view states
// try and tokenize the card
let tokenizeCardResult = await handler.tokenizeCard(
cardNumberViewState,
cvcViewState,
expiryViewState,
[:]
)
switch tokenizeCardResult {
case let .success(data):
// Results in a token id
print(data.id)
case let .failure(err):
print(err.localizedDescription)
}
}
如果安装了 swiftlint
,则将在构建过程中运行。
- 最小代码覆盖率是 60%
如果您将 Hellgate iOS SDK 集成到项目(们)中遇到困难,请发送电子邮件至 [email protected]。
请随时提交任何请求、问题或错误。
如果您修复了任何问题,请随时提出拉取请求。我们将对此进行研究。请遵循本文件和任何 GitHub 工作流程中提到的任何开发实践/流程。
感谢您的贡献。