starfish-codes/hgate2-ios-headless-sdk
The Hellgate iOS SDK is distributed via Cocoapods, Carthage and SPM.
Installation
The Hellgate iOS SDK is distributed via Cocoapods, Carthage and SPM.
Cocoapods
Add the following line to your Podfile:
pod 'Hellgate-iOS-SDK'Carthage
- Add the following line to your
Cartfile:
github "starfish-codes/hgate2-ios-headless-sdk"- Run in same directory as your
Cartfile:
$ carthage update --use-xcframeworks- Add the built XCFrameworks to your project under "Frameworks and Libraries"
Swift Package Manager
Add the package via Xcode from https://github.com/starfish-codes/hgate2-ios-headless-sdk.git
Usage
Import
import Hellgate-iOS-SDKUI Fields
Use the following views to create a card form:
// 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()Each field has a ViewState which looks somewhat like this:
public enum ComponentState: String {
case complete
case incomplete
case blank
case invalid
}
public struct ViewState {
public let state: ComponentState
}The ViewStates can help to determine how the user is progressing in filling out the fields.
Hellgate
First we have to initialize a Hellgate session using the sessionId delivered from your backend.
let hellgate = await initHellgate(baseUrl: hellgateURL, sessionId: sessionId)Next we need to get a card handler from the Hellgate session and then we can try and tokenize the card details based on the view states previously defined in the 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)
}
}Development
Linting
If swiftlint is installed then it will run during the build process.
Code Coverage
- Minmimum code coverage is 60%
Contributing
If you are having trouble integrating the Hellgate iOS SDK into your project(s), please email hellgate.products@starfish.team.
Any requests, issues or bugs, please feel free to open an issue.
Feel free to open up a pull request if you have fixed any issues and we will look into it. Please follow any development practices/processes mentioned in this document and in any Github workflows.
Thank you for contributing.
Package Metadata
Repository: starfish-codes/hgate2-ios-headless-sdk
Default branch: main
README: README.md