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

  1. In Xcode, navigate to File > Swift Packages > Add Package Dependency...

  2. Enter the Forter3DS SDK repository URL

    https://bitbucket.org/forter-mobile/forter-ios.git

  3. Set the Dependency Rule to be Up to Next Major Version then press Add Package

  4. 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

  1. 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'
    end
    
  2. Run pod install

Dependencies Dependencies

Forter3DS SDK uses external libraries that are already embedded in the SDK

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.

  1. Import the SDK Import the SDK

    import Forter3DS
    
  2. Setup 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 with the site ID from the Credentials section of Forter Portal.

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

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

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

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

Example

deinit {
    Forter3DS.removeLogsObserver(observer: self)
}