# Antifraud

The Antifraud Check module compares the current Session against prior Sessions and known identities to detect signs of fraud.

For an overview of this module and how it works, see [Antifraud Check](https://developer.incode.com/docs/antifraud-check).

How you use this module depends on your [integration pattern](https://developer.incode.com/docs/android-common-implementation-patterns#integration-patterns). In Patterns 1 and 2, you add the module to a `FlowConfig` in code as shown on this page. In Pattern 3, you define your modules and configuration in Dashboard as a Flow or Workflow and reference it by ID with `startFlow()` or `startWorkflow()` as shown on [Run Flows Configured in Dashboard](https://developer.incode.com/docs/android-run-flows-configured-online).

## Add Antifraud

Add the module with `addAntifraud()`. Add Antifraud as the last module in your flow. The one exception is when you also use the [Custom Watchlist](https://developer.incode.com/docs/android-custom-watchlist) module. In that case, call `addAntifraud()` first, then `addCustomWatchlist()`.

```kotlin
flowConfigBuilder.addAntifraud()
```
```java
flowConfigBuilder.addAntifraud();
```

### Example

The example below adds Antifraud as the only step in the flow and listens for the result through `onAntifraudCompleted()`.

```kotlin
val flowConfig = FlowConfig.Builder()
    .addAntifraud()
    .build()

val onboardingListener = object : OnboardingListener() {
    override fun onAntifraudCompleted(antifraudResult: AntifraudResult) {
        // Antifraud step completed. Process the result.
    }
}

IncodeWelcome.getInstance()
    .startOnboarding(activityContext, sessionConfig, flowConfig, onboardingListener)
```
```java
FlowConfig flowConfig = new FlowConfig.Builder()
    .addAntifraud()
    .build();

IncodeWelcome.OnboardingListener onboardingListener = new IncodeWelcome.OnboardingListener() {
    @Override
    public void onAntifraudCompleted(@NonNull AntifraudResult antifraudResult) {
        // Antifraud step completed. Process the result.
    }
};

IncodeWelcome.getInstance()
    .startOnboarding(activityContext, sessionConfig, flowConfig, onboardingListener);
```

## Configuration Options

Antifraud has no configurable settings. It is constructed with a no-argument constructor, and `addAntifraud()` adds it for you.

## Result

Antifraud delivers an `AntifraudResult` to the `onAntifraudCompleted(AntifraudResult)` callback on the `OnboardingListener`. Key fields include:

- `result`: `true` when the antifraud check passed.
- Fields inherited from `BaseResult`:
  - `resultCode`: The `ResultCode` for this result.
  - `error`: When `resultCode` is `ERROR`, the `Throwable` that caused it; otherwise, `null`.
  - `deviceStats`: The `DeviceStats` snapshot of the device state when the result was produced.
  - `motionStatus`: Device motion assessment during capture. One of the following:
    - `UNCLEAR`: Motion could not be determined; the default.
    - `PASS`: Device motion was within acceptable limits.
    - `FAIL`: Excessive device motion was detected.

Errors surface via `OnboardingListener.onError(Throwable)`. This module does not deliver a module-specific exception subtype.

For all fields, see `AntifraudResult` in [API Reference](https://developer.incode.com/docs/android-api-reference).
