Risk iOS package
The package helps collect device data for merchants with direct integration (standalone) with the package and those using Checkout's Frames iOS package.
Table of contents
Requirements
- iOS 12.0+
- Xcode 12.4+
- Swift 5.3+
Documentation
Usage guide
- Add
Risk
as a package dependency - see Installation guide on how to add our SDK in your iOS app via SPM or Cocoapods. - Obtain a public API key from Checkout Dashboard.
- Initialise the package with the
getInstance
method passing in the required configuration (public API key and environment), then publish the device data with thepublishData
method, see example below.
// Example usage of package
let yourConfig = RiskConfig(publicKey: "pk_qa_xxx", environment: RiskEnvironment.qa)
Risk.getInstance(config: yourConfig) { riskInstance in
riskInstance?.publishData() { response in
print(response.deviceSessionID)
}
}
Public API
The package exposes two methods:
-
getInstance
- This is a method that returns a singleton instance of Risk. When the method is called, preliminary checks are made to Checkout's internal API(s) that retrieves the public keys used to initialise the package used in collecting device data, if the checks fail or the merchant is disabled, nil will be returned, else, if the checks are successful, theRisk
instance is returned to the consumer of the package which can now be used to publish the data with thepublishData
method.Arguments
public struct RiskConfig { public let publicKey: String public let environment: RiskEnvironment public let framesMode: Bool public init(publicKey: String, environment: RiskEnvironment, framesMode: Bool = false) { self.publicKey = publicKey self.environment = environment self.framesMode = framesMode } } public enum RiskEnvironment { case qa case sandbox case prod }
Responses
public class Risk { ... public func publishData(...) ... { ... } }
-
publishData
- This is used to publish and persist the device data.Arguments
public func publishData(cardToken: String? = nil, completion: @escaping (Result<PublishRiskData, RiskError>) -> Void) { ... }
Responses
public struct PublishRiskData { public let deviceSessionID: String } public enum RiskError: Error, Equatable { case description(String) var localizedDescription: String { switch self { case .description(let errorMessage): return errorMessage } } }
Additional Resources
Demo projects
Our sample application showcases our prebuilt UIs and how our SDK works. You can run this locally once you clone the repository (whether directly via git or with suggested integration methods).
Our demo apps also test the supported integration methods (SPM, Cocoapods), so if you're having any problems there, they should offer a working example. You will find them in the root of the repository, inside respective folders:
- iOSExampleRiskCocoapods - (Cocoapods distribution)
- iOSExampleRiskSPM - (SPM distribution)
Changelog
Find our CHANGELOG.md here.
Contributing
Find our guide to start contributing here.
License
Risk iOS is released under the MIT license. See LICENSE for details.