Hellgate iOS SDK 通过 Cocoapods、Carthage 和 SPM 分发。
将以下行添加到你的 Podfile
文件中
pod 'Hellgate-iOS-SDK'
Cartfile
文件中github "starfish-codes/hgate2-ios-headless-sdk"
Cartfile
文件相同的目录下运行$ carthage update --use-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
,它将在构建过程中运行。
如果你在将 Hellgate iOS SDK 集成到你的项目时遇到问题,请发送电子邮件至 hellgate.products@starfish.team。
任何请求、问题或错误,请随时提出 issue。
如果你修复了任何 issue,请随时发起 pull request,我们将进行查看。请遵循本文档和任何 Github 工作流程中提到的任何开发实践/流程。
感谢你的贡献。