Payment Optimization
...
Front-end Integration for 3DS
3DS Android SDK
13 min
install forter3ds sdk supports installation via maven https //developer android com/build/dependencies#google maven requirements minimum version android 5 1 (api level 22) add to maven if the gradle version is 7 0 and above inside your app's settings gradle , append the following repository, provided below, to your dependencyresolutionmanagement block dependencyresolutionmanagement { repositoriesmode set(repositoriesmode fail on project repos) repositories { google() mavencentral() maven { url "https //mobile sdks forter com/android" credentials { username "\<username provided by forter>" password "\<password provided by forter>" } } } } if the gradle version is earlier than 7 0 inside your app's build gradle , append the following repository, provided below, to your repositories block repositories { maven { url 'https //maven google com' } maven { url "https //mobile sdks forter com/android" credentials { username "\<username provided by forter>" password "\<password provided by forter>" } } } specify and commit the credentials to your git note that these credentials are not sensitive, but we keep them private to prevent bots and search engines from accessing the repository add the forter3ds sdk dependency add the forter3ds sdk as a dependency to your app's build gradle file under the dependencies block use the dependency provided below build gradle implementation 'com forter mobile\ forter3ds 2 0 4' build gradle kts implementation("com forter mobile\ forter3ds 2 0 1") manifest permissions the forter3ds sdk requires the common permission internet this permission is typically required by many applications and components if you have not already included it in your permissions list, please add to your manifest file androidmanifest xml \<! forter3ds sdk permissions > \<uses permission android\ name="android permission internet" /> initializing the sdk the init method is utilized to configure and set up the sdk, ensuring its readiness to handle transactions effectively the sdk must be initialized from the main application context if your app is not currently using an application class, please add one and register it in the manifest signature fun init( context context, config forter3dsconfig, callback iforter3dsinitcallback? ) parameters context an instance of the android context class, typically the application context config an instance of forter3dsconfig containing configuration parameters for the sdk initialization callback an optional callback of type iforter3dsinitcallback to receive initialization status notifications forter3dsconfig class the forter3dsconfig class encapsulates configuration parameters required for initializing the sdk it includes the following parameters merchantid represents the unique identifier assigned to the merchant within the application it typically aligns with the site id unless a psp necessitates distinct ids per merchant siteid the site id associated with the merchant account defaultcustomization customization options for the default theme darkcustomization customization options for the dark theme monochromecustomization customization options for the monochrome theme shouldloadtestservers a boolean flag indicating whether to load test servers during initialization should be enabled only on testing environment iforter3dsinitcallback interface the iforter3dsinitcallback interface defines callback methods to notify the client application of the initialization status it includes the following methods oninitializationsucceeded() invoked when the sdk initialization is successful oninitializationfailed() invoked when the sdk initialization fails usage val context context = applicationcontext val config = forter3dsconfig builder() setmerchantid("your merchant id") setsiteid("your site id") if (buildconfig debug) { config loadtestservers() } forter3ds getinstance() init(context, config build(), object iforter3dsinitcallback { override fun oninitializationsucceeded() { // handle successful initialization } override fun oninitializationfailed() { // handle initialization failure } }) ftr3dscustomization class the ftr3dscustomization class provides customization options for the ui elements in the native challenge screen it allows developers to customize buttons, labels, text boxes, and toolbars to match the design and branding requirements of their application setbuttoncustomization customizes background color, corner radius and text color setlabelcustomization customizes font size, text color and font settextboxcustomization customizes border color, border width and corner radius settoolbarcustomization customizes background color, button text and header text to create an instance of ftr3dscustomization , simply use its default constructor and apply the required customizations val customization = ftr3dscustomization() apply { val button = ftr3dsbuttoncustomization() button setbackgroundcolor("#ff7c72") setbuttoncustomization(button, ftr3dsbuttontype submit) val label = ftr3dslabelcustomization() label setheadingtextfontsize(40) setlabelcustomization(label) } do challenge if needed this method is called by the your app with the managed order token obtained from the backend if a webview challenge is presented, the method also requires a presenting activity for displaying the challenge ui and a activityresultlauncher that will receive the challenge result if a native challenge is presented, the method requires a presenting activity for displaying the challenge ui and a callback that will receive the challenge result to initiate the dochallengeifneeded function, provide the managedordertoken received from the backend (see order api https //docs forter com/reference/order v3 ) fun dochallengeifneeded( activity activity?, launcher activityresultlauncher\<ftr3dschallengeparams>, token string, callback iforter3dschallengecallback ) parameters activity the activity responsible for presenting the challenge ui launcher the launcher that will receive the webview challenge result token the managed order token obtained from your backend callback the callback for the native challenge result iforter3dschallengecallback interface the iforter3dschallengecallback interface provides callback methods for handling challenge results during the 3ds authentication process callback methods onchallengefinished invoked when a challenge is successfully completed receives a jsonobject with an encoded challenge result onchallengefail() invoked when a challenge fails onchallengeskipped() invoked when a challenge is skipped all callback methods are executed on the main thread