Installation

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.

🚧

Ensure to select only one integration method and refrain from using both, as combining them may result in build conflicts

Swift Package Manager

  1. In your Xcode menu, go to File > Swift Packages > Add Package dependency
  2. Add the Forter3DS repository, the press Next
    https://bitbucket.org/forter-mobile/forter3ds-ios
    
  3. Click Next to keep the default setting to use the latest version
  4. Following the dependency resolution , choose Forter3DS and press Finish:

CocoaPods

Ensure that your Podfile includes the use_frameworks! flag

  1. In your Podfile add Forter3DS dependency to your target
platform :ios, '10.0'
use_frameworks!

target 'YourProjectName' do
	pod 'Forter3DS', :git => 'https://bitbucket.org/forter-mobile/forter3ds-ios.git'
end
  1. Run pod install

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

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.

Step 1: Import the SDK

import Forter3DS
#import <Forter3DS/Forter3DS.h>

Step 2: 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 <your-site-id> with the unique site ID assigned to you by Forter.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Forter3DS.setup(siteID: "<your-site-id>")
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     [Forter3DS setupWithSiteID:@"<your-site-id>"];
}

Do Challenge if Needed

Using the managedOrderToken that was received from the backend (see Order API, the doChallengeIfNeeded(token:vc:delegate:)should be called. This method will display the challenge if required, otherwise, it will continue with the transaction.

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_here", 
    vc: YourPresentingViewController,
    delegate: self)

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

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)
}

// MARK: Forter3DS dev logs notification

@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

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)
}