# capacitor-sumsub-mobile-sdk

Sumsub SDK for Capacitor apps

## Install

```bash
npm install capacitor-sumsub-mobile-sdk
npx cap sync
```

### Android

Add this to your repository `build.gradle` file:

```groovy
allprojects {
    repositories {
        maven { url "https://maven.sumsub.com/repository/maven-public/" }
    }
}
```

### iOS

Add this to your `Podfile`:

```ruby
source 'https://github.com/SumSubstance/Specs.git'
```


## Permissions

### iOS
Add the following keys to your `Info.plist` file:

```xml
<key>NSCameraUsageDescription</key>
<string>Let us take a photo</string>
<key>NSMicrophoneUsageDescription</key>
<string>Time to record a video</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Let us pick a photo</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Please provide us with your geolocation data to prove your current location</string>
```

## API

<docgen-index>

* [`initialize(...)`](#initialize)
* [`present()`](#present)
* [`dismiss()`](#dismiss)
* [`setAccessToken(...)`](#setaccesstoken)
* [`getVerificationStatus()`](#getverificationstatus)
* [`addListener('onTokenExpired', ...)`](#addlistenerontokenexpired-)
* [`addListener('onVerificationStatusChanged', ...)`](#addlisteneronverificationstatuschanged-)
* [`addListener('onVerificationFailed', ...)`](#addlisteneronverificationfailed-)
* [`addListener('onApprovedStatusChanged', ...)`](#addlisteneronapprovedstatuschanged-)
* [`addListener('onEvent', ...)`](#addlisteneronevent-)
* [`addListener('onApplicantLoaded', ...)`](#addlisteneronapplicantloaded-)
* [`addListener('onStepInitiated', ...)`](#addlisteneronstepinitiated-)
* [`addListener('onStepCompleted', ...)`](#addlisteneronstepcompleted-)
* [`addListener('onAnalyticsEvent', ...)`](#addlisteneronanalyticsevent-)
* [`addListener('onDidDismiss', ...)`](#addlistenerondiddismiss-)
* [`addListener('onLog', ...)`](#addlisteneronlog-)
* [Interfaces](#interfaces)
* [Enums](#enums)

</docgen-index>

<docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

### initialize(...)

```typescript
initialize(options: { accessToken: string; applicantConfig?: { email?: string; phone?: string; }; debug?: boolean; locale?: string; isAnalyticsEnabled?: boolean; }) => Promise<{ status: SumsubSdkStatus; }>
```

Initializes the SDK with the given access token and optional configuration.

| Param         | Type                                                                                                                                                         | Description                             |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------- |
| **`options`** | <code>{ accessToken: string; applicantConfig?: { email?: string; phone?: string; }; debug?: boolean; locale?: string; isAnalyticsEnabled?: boolean; }</code> | - The options for initializing the SDK. |

**Returns:** <code>Promise&lt;{ status: <a href="#sumsubsdkstatus">SumsubSdkStatus</a>; }&gt;</code>

--------------------


### present()

```typescript
present() => Promise<void>
```

Present the verification flow.
This method should be called after the SDK is initialized.

--------------------


### dismiss()

```typescript
dismiss() => Promise<void>
```

--------------------


### setAccessToken(...)

```typescript
setAccessToken(options: { token: string; }) => Promise<void>
```

| Param         | Type                            |
| ------------- | ------------------------------- |
| **`options`** | <code>{ token: string; }</code> |

--------------------


### getVerificationStatus()

```typescript
getVerificationStatus() => Promise<{ status: SumsubSdkStatus; }>
```

Returns the current verification status.
If the verification flow is not presented, the status will be `NOT_INITIALIZED` or `READY`.
You need to present the verification flow to get the actual verification status.

**Returns:** <code>Promise&lt;{ status: <a href="#sumsubsdkstatus">SumsubSdkStatus</a>; }&gt;</code>

--------------------


### addListener('onTokenExpired', ...)

```typescript
addListener(eventName: 'onTokenExpired', listenerFunc: () => void) => Promise<PluginListenerHandle>
```

| Param              | Type                          |
| ------------------ | ----------------------------- |
| **`eventName`**    | <code>'onTokenExpired'</code> |
| **`listenerFunc`** | <code>() =&gt; void</code>    |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### addListener('onVerificationStatusChanged', ...)

```typescript
addListener(eventName: 'onVerificationStatusChanged', listenerFunc: (status: { prevStatus: SumsubSdkStatus; newStatus: SumsubSdkStatus; statusDescription: string; verboseStatus: string; failReason: string; }) => void) => Promise<PluginListenerHandle>
```

This event is triggered when the verification status changes.

| Param              | Type                                                                                                                                                                                                                               |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`eventName`**    | <code>'onVerificationStatusChanged'</code>                                                                                                                                                                                         |
| **`listenerFunc`** | <code>(status: { prevStatus: <a href="#sumsubsdkstatus">SumsubSdkStatus</a>; newStatus: <a href="#sumsubsdkstatus">SumsubSdkStatus</a>; statusDescription: string; verboseStatus: string; failReason: string; }) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### addListener('onVerificationFailed', ...)

```typescript
addListener(eventName: 'onVerificationFailed', listenerFunc: (status: { failReason: string; }) => void) => Promise<PluginListenerHandle>
```

This event is triggered when the verification status changes to failed.

| Param              | Type                                                      |
| ------------------ | --------------------------------------------------------- |
| **`eventName`**    | <code>'onVerificationFailed'</code>                       |
| **`listenerFunc`** | <code>(status: { failReason: string; }) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### addListener('onApprovedStatusChanged', ...)

```typescript
addListener(eventName: 'onApprovedStatusChanged', listenerFunc: (event: { isApproved: boolean; }) => void) => Promise<PluginListenerHandle>
```

This event is triggered when the approval changes to approved or rejected.

| Param              | Type                                                      |
| ------------------ | --------------------------------------------------------- |
| **`eventName`**    | <code>'onApprovedStatusChanged'</code>                    |
| **`listenerFunc`** | <code>(event: { isApproved: boolean; }) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### addListener('onEvent', ...)

```typescript
addListener(eventName: 'onEvent', listenerFunc: (event: { eventName: string; payload: any; }) => void) => Promise<PluginListenerHandle>
```

All event notifications

| Param              | Type                                                                  |
| ------------------ | --------------------------------------------------------------------- |
| **`eventName`**    | <code>'onEvent'</code>                                                |
| **`listenerFunc`** | <code>(event: { eventName: string; payload: any; }) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### addListener('onApplicantLoaded', ...)

```typescript
addListener(eventName: 'onApplicantLoaded', listenerFunc: (event: { applicantId: string; }) => void) => Promise<PluginListenerHandle>
```

| Param              | Type                                                      |
| ------------------ | --------------------------------------------------------- |
| **`eventName`**    | <code>'onApplicantLoaded'</code>                          |
| **`listenerFunc`** | <code>(event: { applicantId: string; }) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### addListener('onStepInitiated', ...)

```typescript
addListener(eventName: 'onStepInitiated', listenerFunc: (event: { step: string; }) => void) => Promise<PluginListenerHandle>
```

| Param              | Type                                               |
| ------------------ | -------------------------------------------------- |
| **`eventName`**    | <code>'onStepInitiated'</code>                     |
| **`listenerFunc`** | <code>(event: { step: string; }) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### addListener('onStepCompleted', ...)

```typescript
addListener(eventName: 'onStepCompleted', listenerFunc: (event: { step: string; isCancelled: boolean; }) => void) => Promise<PluginListenerHandle>
```

| Param              | Type                                                                     |
| ------------------ | ------------------------------------------------------------------------ |
| **`eventName`**    | <code>'onStepCompleted'</code>                                           |
| **`listenerFunc`** | <code>(event: { step: string; isCancelled: boolean; }) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### addListener('onAnalyticsEvent', ...)

```typescript
addListener(eventName: 'onAnalyticsEvent', listenerFunc: (event: { eventName: string; payload: any; }) => void) => Promise<PluginListenerHandle>
```

| Param              | Type                                                                  |
| ------------------ | --------------------------------------------------------------------- |
| **`eventName`**    | <code>'onAnalyticsEvent'</code>                                       |
| **`listenerFunc`** | <code>(event: { eventName: string; payload: any; }) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### addListener('onDidDismiss', ...)

```typescript
addListener(eventName: 'onDidDismiss', listenerFunc: (event: { status: string; description: string; }) => void) => Promise<PluginListenerHandle>
```

| Param              | Type                                                                      |
| ------------------ | ------------------------------------------------------------------------- |
| **`eventName`**    | <code>'onDidDismiss'</code>                                               |
| **`listenerFunc`** | <code>(event: { status: string; description: string; }) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### addListener('onLog', ...)

```typescript
addListener(eventName: 'onLog', listenerFunc: (event: { level: LogLevel; message: string; }) => void) => Promise<PluginListenerHandle>
```

Logs all the messages from the SDK. Log level default is Error, can be change to debug when initializing the SDK.

| Param              | Type                                                                                           |
| ------------------ | ---------------------------------------------------------------------------------------------- |
| **`eventName`**    | <code>'onLog'</code>                                                                           |
| **`listenerFunc`** | <code>(event: { level: <a href="#loglevel">LogLevel</a>; message: string; }) =&gt; void</code> |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

--------------------


### Interfaces


#### PluginListenerHandle

| Prop         | Type                                      |
| ------------ | ----------------------------------------- |
| **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |


### Enums


#### SumsubSdkStatus

| Members                    | Value                              |
| -------------------------- | ---------------------------------- |
| **`NOT_INITIALIZED`**      | <code>'NotInitialized'</code>      |
| **`READY`**                | <code>'Ready'</code>               |
| **`FAILED`**               | <code>'Failed'</code>              |
| **`INITIAL`**              | <code>'Initial'</code>             |
| **`INCOMPLETE`**           | <code>'Incomplete'</code>          |
| **`PENDING`**              | <code>'Pending'</code>             |
| **`TEMPORARILY_DECLINED`** | <code>'TemporarilyDeclined'</code> |
| **`FINALLY_REJECTED`**     | <code>'FinallyRejected'</code>     |
| **`APPROVED`**             | <code>'Approved'</code>            |
| **`ACTION_COMPLETED`**     | <code>'ActionCompleted'</code>     |


#### LogLevel

| Members       | Value                  |
| ------------- | ---------------------- |
| **`OFF`**     | <code>'OFF'</code>     |
| **`ERROR`**   | <code>'ERROR'</code>   |
| **`WARNING`** | <code>'WARNING'</code> |
| **`INFO`**    | <code>'INFO'</code>    |
| **`DEBUG`**   | <code>'DEBUG'</code>   |
| **`TRACE`**   | <code>'TRACE'</code>   |
| **`UNKNOWN`** | <code>'UNKNOWN'</code> |

</docgen-api>
