Payment Optimization
...
Front-end Integration for 3DS
3DS iOS SDK
14 min
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 in xcode, navigate to file > swift packages > add package dependency enter the forter3ds sdk repository url swift package manager https //bitbucket org/forter mobile/forter ios git set 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 ensure that your podfile includes the use frameworks! flag in your podfile add forter3ds dependency to your target podfile platform \ ios, '11 0' use frameworks! target 'yourprojectname' do 	pod 'forter3ds', \ git => 'https //bitbucket org/forter mobile/forter ios git' end run pod install dependencies forter3ds sdk uses external libraries that are already embedded in the sdk asn1decoder certificate parsing in asn1 structure mit license https //github com/filom/asn1decoder/blob/master/license swcrypt crypto library for jws validation (used only in ios 10 devices) mit license https //github com/soyersoyer/swcrypt/blob/master/license md gmellipticcurvecrypto security framework used for elliptic curve keys crypto library license https //github com/ricmoo/gmellipticcurvecrypto/blob/master/license txt 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 forter3ds#import \<forter3ds/forter3ds h> 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 forter site id> with the site id from the credentials https //portal forter com/app/integration/credentials/ section of forter portal in development mode, in order to present a native challenge 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>") } (bool)application (uiapplication )application didfinishlaunchingwithoptions (nsdictionary )launchoptions { \#if debug \[forter3ds loadtestservers]; \#endif \[forter3ds setupwithsiteid @"\<your forter site id>"]; } do challenge if needed this method should be called after the managed order token is obtained from the backend (see order api https //docs forter com/reference/order v3 ) 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)\[forter3ds dochallengeifneededwithtoken @"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) }