Hellgate iOS SDK

安装

Hellgate iOS SDK 通过 Cocoapods、Carthage 和 SPM 分发。

Cocoapods

将以下行添加到你的 Podfile 文件中

pod 'Hellgate-iOS-SDK'

Carthage

  1. 将以下行添加到你的 Cartfile 文件中
github "starfish-codes/hgate2-ios-headless-sdk"
  1. 在与你的 Cartfile 文件相同的目录下运行
$ carthage update --use-xcframeworks
  1. 将构建的 XCFrameworks 添加到你项目的 “Frameworks and Libraries” 下

Swift Package Manager

通过 Xcode 从 https://github.com/starfish-codes/hgate2-ios-headless-sdk.git 添加软件包

用法

导入

import Hellgate-iOS-SDK

UI 字段

使用以下视图来创建一个卡片表单

// 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 可以帮助确定用户在填写字段时的进度。

Hellgate

首先,我们必须使用从你的后端传递的 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 工作流程中提到的任何开发实践/流程。

感谢你的贡献。