The Hellgate iOS SDK is distributed via Cocoapods, Carthage and SPM.
Add the following line to your Podfile
:
pod 'Hellgate-iOS-SDK'
- 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"
Add the package via Xcode from https://github.com/starfish-codes/hgate2-ios-headless-sdk.git
import Hellgate-iOS-SDK
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.
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)
}
}
If swiftlint
is installed then it will run during the build process.
- Minmimum code coverage is 60%
If you are having trouble integrating the Hellgate iOS SDK into your project(s), please email [email protected].
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.