> ## 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.

# iOS

> Embed the Imprint application experience in your iOS app

## Installation

Swift Package Manager

1. Add the following repository URL

```ruby theme={null}
https://github.com/Imprint-Tech/imprint-sdk-ios
```

2. Select your desired version or branch
3. Click **Add Package**

Or you can also add Imprint as a dependency to your \`Package.swift\`:

```swift theme={null}
dependencies: [
    .package(url: "https://github.com/Imprint-Tech/imprint-sdk-ios", from: "1.0.0")
]
```

## Implementation

1. **Import the SDK**

Import the SDK in your view controllers or wherever needed:

```swift theme={null}
import Imprint
```

2. **Configuration**

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

```swift theme={null}
let configuration = ImprintConfiguration(clientSecret: "client_secret", environment: .sandbox)
```

3. **Define the Completion Handler**

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

```swift theme={null}
configuration.onCompletion = { state, data in
  switch state {
  case .offerAccepted:
    print("Offer accepted, data: \(String(describing: data))")
  case .rejected:
    print("Application rejected, data: \(String(describing: data))")
  case .inProgress:
    print("Incomplete application, data: \(String(describing: data))")
  case .error:
    print("Error occurred, data: \(String(describing: data))")
  }
  // Perform any generic actions after the flow ends if needed
}
```

4. **Start the Application flow**

Once you've configured the `ImprintConfiguration`, initiate the application flow by calling `startApplication` from your view controller.

```swift theme={null}
public static func startApplication(from viewController: UIViewController, configuration: ImprintConfiguration) 
```

* `viewController`**:** The view controller from which the application flow will be presented
* `configuration`**:** The previously created `ImprintConfiguration` object containing your API key and completion handler

### Complete Code Example

Check out our complete demo project at [Imprint-Tech/imprint-sdk-ios](https://github.com/Imprint-Tech/imprint-sdk-ios)

```swift theme={null}
import Imprint

class YourViewController: UIViewController {

  // …
  
  func startImprintApplication() {
    let configuration = ImprintConfiguration(clientSecret: "client_secret", environment: .sandbox)
    
    // Define the completion handler
    configuration.onCompletion = { state, data in
      switch state {
      case .offerAccepted:
        print("Offer accepted, data: \(String(describing: data))")
      case .rejected:
        print("Application rejected, data: \(String(describing: data))")
      case .inProgress:
        print("Incomplete application, data: \(String(describing: data))")
      case .error:
        print("Error occurred, data: \(String(describing: data))")
      }
      // Perform any generic actions after the flow ends if needed
    }
    
    ImprintApp.startApplication(from: self, configuration: configuration)
  }
}
```

Request Parameters

| PROPERTY NAMES    | REQUIRED        | TYPE   | DESCRIPTION                                                 |                                           |
| ----------------- | --------------- | ------ | ----------------------------------------------------------- | ----------------------------------------- |
|                   | `client_secret` | 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`          | ErrorCode \| 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                                                              |
| --------------- | ------------------------------------------------------------------------ |
| `offerAccepted` | Application has been approved and credit offer accepted. New cardholder! |
| `rejected`      | Application has been rejected by Imprint                                 |
| `inProgress`    | Application has been exited, not completed                               |
| `error`         | Invalid request parameters (e.g., invalid token)                         |
