> ## Documentation Index
> Fetch the complete documentation index at: https://docs.imprint.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Android

> Embed the Imprint application experience in your Android app

## Installation

#### Step 1: Add to app-level build.gradle and sync project to gradle

```groovy theme={null}
dependencies {     
    implementation 'co.imprint.sdk:imprint-sdk:0.5.0'
}
```

## Implementation

#### Step 2: Import the SDK

```kotlin theme={null}
import co.imprint.sdk.Imprint
```

#### Step 3: Configuration

Create an instance of `ImprintConfiguration` with your `clientSecret` and `environment`, then assign additional optional fields as needed.

```kotlin theme={null}
val configuration = ImprintConfiguration(
  clientSecret = "client_secret",
  environment = ImprintEnvironment.PRODUCTION,
)
```

#### Step 4: Define the completion handler

Define the completion handler `onCompletion` to manage the terminal states when the application flow ends.

```kotlin theme={null}
val onCompletion =
      { state: ImprintCompletionState, metadata: Map<String, Any?>? ->
        val metadataInfo = metadata?.toString() ?: "No metadata"
        val resultText = when (state) {
          ImprintCompletionState.OFFER_ACCEPTED -> {
            "Offer accepted\n$metadataInfo"
          }
          ImprintCompletionState.REJECTED -> {
            "Application rejected\n$metadataInfo"
          }
          ImprintCompletionState.IN_PROGRESS -> {
            "Incomplete application\n$metadataInfo"
          }
          ImprintCompletionState.ERROR -> {
            "Error occurred\n$metadataInfo"
          }
        }
        Log.d("Application result:", resultText)
      }
```

#### Step 5: Starting the Application flow

Once you have configured the `ImprintConfiguration`, initiate the application flow by calling `Imprint.startApplication`. This will start within a new Activity.

```kotlin theme={null}
  fun startApplication(
    context: Context,
    configuration: ImprintConfiguration,
    onCompletion: (ImprintCompletionState, Map<String, Any?>?) -> Unit,
  )
```

`context`: The context from which the application process will be presented

`configuration`: The previously created ImprintConfiguration object containing your API key and completion handler

`onCompletion`: The completion handler of the flow

## Complete code example

```kotlin theme={null}
fun startApplication(context: Context) {
    val configuration = ImprintConfiguration(
      clientSecret = "client_secret",
      environment = ImprintEnvironment.PRODUCTION,
    )

    val onCompletion =
      { state: ImprintCompletionState, metadata: Map<String, Any?>? ->
        val metadataInfo = metadata?.toString() ?: "No metadata"
        val resultText = when (state) {
          ImprintCompletionState.OFFER_ACCEPTED -> {
            "Offer accepted\n$metadataInfo"
          }
          ImprintCompletionState.REJECTED -> {
            "Application rejected\n$metadataInfo"
          }
          ImprintCompletionState.IN_PROGRESS -> {
            "Incomplete application\n$metadataInfo"
          }
          ImprintCompletionState.ERROR -> {
            "Error occurred\n$metadataInfo"
          }
        }
        Log.d("Application result:", resultText)
      }

    // Start the application process with the provided context, configuration, and callback
    Imprint.startApplication(
      context = context,
      configuration = configuration,
      onCompletion = onCompletion,
    )
  }
```

Request Parameters

| PROPERTY NAME     | REQUIRED | TYPE   | DESCRIPTION                                                 |   |
| ----------------- | -------- | ------ | ----------------------------------------------------------- | - |
| `clientSecret`    | TRUE     | String | Generated through Create Customer Session                   |   |
| `offerConfigUUID` | FALSE    | String | Identifier for specific reward offer in the referral system |   |

Response Data

| PROPERTY NAMES        | TYPE                     | DESCRIPTION                                   |
| --------------------- | :----------------------- | --------------------------------------------- |
| `customer_id`         | String \| null           | Imprint identifier for customer               |
| `partner_customer_id` | String \| null           | Partner identifier for customer               |
| `payment_method_id`   | String \| null           | ID to the payment method of customer          |
| `error_code`          | ImprintErrorCode \| null | Identifier for the specific error encountered |

ErrorCode (Enum)

| ENUM                    | DESCRIPTION                              |
| :---------------------- | :--------------------------------------- |
| `INVALID_CLIENT_SECRET` | Indicate Client Secret is invalid        |
| `UNKNOWN_ERROR`         | Indicate other unexpected error happened |

Application States

| ENUM             | DESCRIPTION                                                              |
| ---------------- | ------------------------------------------------------------------------ |
| `OFFER_ACCEPTED` | Application has been approved and credit offer accepted. New cardholder! |
| `REJECTED`       | Application has been rejected by Imprint                                 |
| `IN_PROGRESS`    | Application has been exited, not completed                               |
| `ERROR`          | Invalid request parameters (e.g., invalid client secret)                 |
