3DS iOS SDK - Overviews
3DS iOS SDK
Install Install
The Forter3DS SDK offers flexible integration options, supporting both Swift Package Manager and CocoaPods. Choose the integration method that aligns with your project preferences and workflows add follow the steps below.
Select only one integration method and refrain from using both, as combining them may result in build conflicts.
Swift Package Manager Swift Package Manager
In Xcode, navigate to File > Swift Packages > Add Package Dependency...
Enter the Forter3DS SDK repository URL
https://bitbucket.org/forter-mobile/forter-ios.gitSet the Dependency Rule to be Up to Next Major Version then press Add Package
On the "Choose Package" screen, verify that Forter3DS is selected and press Add Package
CocoaPods CocoaPods
Ensure that your Podfile includes the use_frameworks! flag
In your Podfile add Forter3DS dependency to your target
platform :ios,'11.0' use_frameworks! target 'YourProjectName' do pod 'Forter3DS', :git => 'https://bitbucket.org/forter-mobile/forter-ios.git' endRun pod install
Dependencies Dependencies
Forter3DS SDK uses external libraries that are already embedded in the SDK
- ASN1Decoder - Certificate parsing in ASN1 structure. MIT License
- SwCrypt - Crypto library for JWS validation (used only in iOS 10 devices) MIT license
- GMEllipticCurveCrypto - Security framework used for Elliptic-Curve keys Crypto library. License
Initialization Initialization
The Forter3DS SDK should be initialized from the Application Delegate during application launch. This ensures that it is loaded correctly as soon as the app becomes active.
Import the SDK Import the SDK
import Forter3DSSetup Setup
To initialize the Forter3DS SDK, you need to add the following line to your application delegate's didFinishLaunchingWithOptions method. This is a critical step to ensure the proper functioning of the Forter 3DS SDK within your iOS application. Make sure to replace
In development mode, in order to present a native challenge, the Forter3DS SDK should load the test servers before calling the setup method and use a dedicated test card. This is only for testing purposes and should NOT be used in production.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
#if DEBUG
Forter3DS.loadTestServers() // Only for testing
#endif
Forter3DS.setup(siteID: "<your-forter-site-id>")
}
Do Challenge if Needed Do Challenge if Needed
This method should be called after the managed order token is obtained from the backend (see Order API). It will display an authorization challenge if required, otherwise it will continue with the transaction.
Method
doChallengeIfNeeded(token:vc:delegate:): Perform a managed order challenge if needed.
Parameters
- token (String) : The managed order token obtained from the backend.
- vc (UIViewController) : The view controller responsible for presenting the challenge UI.
- delegate (FTR3DSManagedOrderDelegate) : The delegate that will receive the challenge result.
Example
Forter3DS.doChallengeIfNeeded(
token: "your_managed_order_token",
vc: YourPresentingViewController,
delegate: self
)
Callback Callback
The FTR3DSManagedOrderDelegate protocol provides a structured way to handle the completion of managed order flows. By adopting this protocol, developers can respond to the completion of managed order challenges and handle any potential errors that may arise during the process.
Method
challengeCompleted(error:): This method is called when the managed order flow is completed, either successfully or with an error. It provides information about the status of the managed order challenge.
Parameter
- error: An optional parameter of type Error that indicates whether an error occurred during the managed order flow. If no error occurred, this parameter will be nil.
Example
class PaymentViewController: UIViewController, FTR3DSManagedOrderDelegate {
func performManagedOrderFlow() {
// Initiating the managed order flow
}
// FTR3DSManagedOrderDelegate method
func challengeCompleted(error: Error?) {
if let error = error {
// Handle error scenario
print("Managed order flow completed with error: \(error.localizedDescription)")
} else {
// Handle success scenario
}
}
}
Optional Methods Optional Methods
Observe Logs Observe Logs
This function sets up an observer of Forter3DS logs. It utilizes the given NotificationCenter, observer, and selector to handle log notifications. If the service has not been initialized yet, it creates a new instance and configures it for Managed Orders. Otherwise, if the service is already initialized, it posts a log message indicating that dev logs are already initialized.
Method
observeLogs(observer:selector:notificationCenter:): Start observing Forter3DS logs with Managed Orders context.
Parameters
- notificationCenter: The NotificationCenter to use for observing log notifications.
- observer: The observer object that will handle log notifications.
- selector: The selector method to be called on log notifications.
Example
func startObservingLogs() {
Forter3DS.observeLogs(
observer: self,
selector: #selector(handleForter3DSNotification(_:)),
notificationCenter: NotificationCenter.default
)
}
@objc func handleForter3DSNotification(_ notification: Notification) {
guard let userInfo = notification.userInfo,
let message = userInfo["message"] as? String else {
return
}
print("[Forter dev logs]: \(message)")
}
Remove Observer Remove Observer
This function allows you to remove the Forter3DS observer for Forter3DS logs. It takes the provided observer and unregisters it from the NotificationCenter associated with Forter3DS logs. The observer will no longer receive log notifications after being removed.
Method
removeLogsObserver(observer:): Remove the Notification Observer for Forter3DS Logs.
Parameter
- observer: The observer object to be removed from log notifications.
Example
deinit {
Forter3DS.removeLogsObserver(observer: self)
}