Common Implementation Patterns

Initialize the SDK

Before starting any onboarding flow, you need to initialize the SDK by calling IncodeOnboardingSdk.init() method.

Dart

IncodeOnboardingSdk.init(
  apiKey: 'YOUR_API_KEY',
  apiUrl: 'YOUR_API_URL',
  testMode: false,
  onError: (String error) {
    IncodeSdkInitError? e = error.toIncodeSdkInitError();
    switch (e) {
      case IncodeSdkInitError.simulatorDetected:
        print('Incode init failed, simulator detected: $IncodeSdkInitError.simulatorDetected');
        break;
      case IncodeSdkInitError.testModeEnabled:
        print('Incode init failed, test mode enabled: $IncodeSdkInitError.testModeEnabled');
        break;
      default:
        print('Incode init failed: $error');
        break;
    }
  },
  onSuccess: () {
    // Update UI, safe to start Onboarding
    print('Incode initialized successfully!');
  },
);

apiUrl and apiKey will be provided to you by Incode.

If you're running the app on a simulator, please set the testMode parameter to true.

In case initialization isn't successful, onError() callback will be triggered and the error String will contain more information. Possible values are listed in the IncodeSdkInitError enum: simulatorDetected, testModeEnabled, jailbreakDetected and unknown.

Configure Flows Locally and Run End to End

Use startOnboarding() when you want to configure the flow locally on the device and run all the modules end to end in a single call.

Configure Onboarding session

You should create an instance of OnboardingSessionConfiguration:

Dart

OnboardingSessionConfiguration sessionConfig = OnboardingSessionConfiguration();

Optionally, you can provide these parameters to the OnboardingSessionConfiguration object constructor:

Specifying interviewId or token will return an existing session that will be resumed.

Specifying externalId will return an existing session in case a session with the same externalId was already started, otherwise new session will be created.

Configure Onboarding Flow

You should create an instance of OnboardingFlowConfiguration:

Dart

OnboardingFlowConfiguration flowConfig = OnboardingFlowConfiguration();

Depending on your needs you should specify the steps you want to include, i.e.:

Dart

flowConfig.addIdScan();
flowConfig.addSelfieScan();
flowConfig.addFaceMatch();

The steps will be executed in the order you added them to the flowConfig.

Start the onboarding

Dart

IncodeOnboardingSdk.startOnboarding(
  sessionConfig: sessionConfig,
  flowConfig: flowConfig,
  onSuccess: () {
    print('Incode Onboarding completed!');
  },
  onError: (String error) {
    print('Incode onboarding error: $error');
    IncodeSdkFlowError? e = error.toIncodeSdkFlowError();
      // Handle the error accordingly
    switch (e) {
      case IncodeSdkFlowError.permissionsDenied:
        print('Incode SDK onError user denied permissions: $IncodeSdkFlowError.permissionsDenied');
        break;
      case IncodeSdkFlowError.jailbreakDetected:
        print('Incode SDK onError jailbreak detected: $IncodeSdkFlowError.jailbreakDetected');
        break;
      case IncodeSdkFlowError.faceAuthenticationFailed:
        print('Incode SDK onError face authentication failed: $IncodeSdkFlowError.faceAuthenticationFailed');
        break;
      case IncodeSdkFlowError.unknown:
        print('Incode SDK onError unknown error: $IncodeSdkFlowError.unknown');
        break;
      default:
        print('Incode SDK onError called: $error');
        break;
    }
  },
  onSelfieScanCompleted: (SelfieScanResult result) {
    print('Selfie completed result: $result');
  },
  onIdFrontCompleted: (IdScanResult result) {
    print('onIdFrontCompleted result: $result');
  },
  onIdBackCompleted: (IdScanResult result) {
    print('onIdBackCompleted result: $result');
  },
  onIdProcessed: (String ocrData) {
    print('onIdProcessed result: $ocrData');
  },
);

Once all the steps are completed by the user, the onSuccess method will be called.

In case some error occurred that stopped the flow from completing, the onError method will be called and the error String will contain more information. Possible values are listed in IncodeSdkFlowError enum.

If user cancels the flow, the onUserCancelled method is triggered.

To listen for the results of the steps in the flow as soon as they're completed, you can add optional callback methods, i.e. onSelfieScanCompleted that was added in the above example.

Configure Flows Locally and Run Step by Step

If you would like to use the SDK in a way that the default flow builder doesn't provide, you can separate the Onboarding SDK flow into multiple sections based on your needs, calling individual SDK modules or grouping SDK modules in sections, and returning control to your host application in between.

Set up an onboarding session

Dart

OnboardingSessionConfiguration sessionConfiguration = OnboardingSessionConfiguration();
IncodeOnboardingSdk.setupOnboardingSession(
  sessionConfig: sessionConfiguration,
  onError: (String error) {
    print('Incode onboarding session error: $error');
  },
  onSuccess: (OnboardingSessionResult result) {
    print('Incode Onboarding session created! $result');
  },
);

Session configuration can be configured in the same way as explained in the previous sections.

Configure section flow

Dart

IncodeOnboardingFlowConfiguration flowConfig = IncodeOnboardingFlowConfiguration();
flowConfig.addIdScan();

Start onboarding section

Dart

IncodeOnboardingSdk.startNewOnboardingSection(
  flowConfig: flowConfig,
  flowTag: 'idSection',
  onError: (String error) {
    print('Incode onboarding session error: $error');
  },
  onIdFrontCompleted: (IdScanResult result) {
    print('onIdFrontCompleted result: $result');
  },
  onIdBackCompleted: (IdScanResult result) {
    print('onIdBackCompleted result: $result');
  },
  onIdProcessed: (String ocrData) {
    print('onIdProcessed result: $ocrData');
  },
  onOnboardingSectionCompleted: (String flowTag) {
    print('section completed');
  },
);

Finish onboarding session

Dart

IncodeOnboardingSdk.finishFlow();

Run Flows Configured Online

Use startFlow() (and startWorkflow()) when your flow is configured online on the Incode dashboard.

Start flow

Dart

OnboardingSessionConfiguration sessionConfig = OnboardingSessionConfiguration(
   configurationId: "YOUR_CONFIGURATION_ID",
   interviewId: "YOUR_INTERVIEW_ID"
); // optional

IncodeOnboardingSdk.startFlow(
   sessionConfig: sessionConfig,
   moduleId: 'YOUR_MODULE_ID', // optional, ie. "PHONE"
   onError: (String error) {
    print('Incode startFlow error: $error');
   },
   onSuccess: () {
    print('Incode startFlow completed!');
   },
   onUserCancelled: () {
    print('User cancelled');
   },
);

Start flow from deep link

Dart

IncodeOnboardingSdk.startFlowFromDeepLink(
      url: 'YOUR_DEEPLINK_URL',
      onError: (String error) {
        print('Incode startFlowFromDeepLink error: $error');
      },
      onSuccess: () {
        print('Incode startFlowFromDeepLink completed!');
      },
      onUserCancelled: () {
        print('User cancelled');
      },
    );