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

# Mobile Instruments SDK

> Save a customer's card in your iOS, Android or Flutter app without charging it, then pay with it later.

> [tab] iOS
>
> **Version:** `0.2.0` (`lite-ios`)
>
> The Instruments SDK saves a customer's card without taking a payment. You get back an **instrument**: an id you can pay with later, plus the card's scheme, issuing bank, issuing country and funding source. Use it when your price or eligibility depends on the card, for example a discount for one scheme or different terms for domestic cards, or when you want to keep a card on file before the first payment.
>
> It is part of the same `LiteSDK` package as the Checkout SDK. Card details are entered in lite's secure fields and encrypted on the device: your code and your server never see them.

> [tab] Android
>
> **Version:** `0.2.0` (`sa.lite:lite-android`)
>
> The Instruments SDK saves a customer's card without taking a payment. You get back an **instrument**: an id you can pay with later, plus the card's scheme, issuing bank, issuing country and funding source. Use it when your price or eligibility depends on the card, for example a discount for one scheme or different terms for domestic cards, or when you want to keep a card on file before the first payment.
>
> It is part of the same `lite-android` library as the Checkout SDK. Card details are entered in lite's secure fields and encrypted on the device: your code and your server never see them.

> [tab] Flutter
>
> **Version:** `0.2.0` (`lite_flutter`)
>
> The Instruments SDK saves a customer's card without taking a payment. You get back an **instrument**: an id you can pay with later, plus the card's scheme, issuing bank, issuing country and funding source. Use it when your price or eligibility depends on the card, for example a discount for one scheme or different terms for domestic cards, or when you want to keep a card on file before the first payment.
>
> It is part of the same `lite_flutter` plugin as the Checkout SDK, on iOS and Android. Card details are entered in lite's native secure fields and encrypted on the device: your Dart code and your server never see them.

## Secure fields, elements and the payment sheet

> [tab] iOS
>
> lite's SDKs offer three ways to collect a payment method. A tokenization session supports two of them on iOS:
>
> | Option | What it is | On a tokenization session |
> | - | - | - |
> | **Secure fields** | Card number, expiry, CVV and cardholder name inputs that you place in your own layout. You draw the button. | Supported. This is how you save a card. |
> | **Elements** | Ready-made payment-method components, such as the Apple Pay button. | Apple Pay is supported. |
> | **Payment sheet (drop-in)** | lite's complete checkout UI, presented as a sheet or embedded as a form. | Not supported. It completes with `session_type_unsupported`. |

> [tab] Android
>
> lite's SDKs offer three ways to collect a payment method. On Android, a tokenization session supports one of them:
>
> | Option | What it is | On a tokenization session |
> | - | - | - |
> | **Secure fields** | Card number, expiry, CVV and cardholder name inputs that you place in your own layout. You draw the button. | Supported. This is how you save a card. |
> | **Elements** | Ready-made payment-method components, such as wallet buttons. | None on Android yet. |
> | **Payment sheet (drop-in)** | lite's complete checkout UI, presented as a sheet or embedded as a form. | Not supported. It completes with `session_type_unsupported`. |

> [tab] Flutter
>
> lite's SDKs offer three ways to collect a payment method. A tokenization session supports these:
>
> | Option | What it is | On a tokenization session |
> | - | - | - |
> | **Secure fields** | Card number, expiry, CVV and cardholder name widgets that you place in your own layout. You draw the button. | Supported on iOS and Android. This is how you save a card. |
> | **Elements** | Ready-made payment-method components, such as the Apple Pay button. | Apple Pay is supported on iOS. Android has no wallet elements yet. |
> | **Payment sheet (drop-in)** | lite's complete checkout UI: `LitePaymentSheet` and `LitePaymentForm`. | Not supported. They complete with `session_type_unsupported`. |

## How it works

> [tab] iOS
>
> 1. Your server creates a **tokenization session** with the lite API and gets back its `client_secret`.
> 2. Your app starts the SDK with that `client_secret`.
> 3. The customer enters a card in the secure fields, or authorizes Apple Pay.
> 4. The SDK encrypts the card and saves it with lite. Nothing is charged.
> 5. Your app receives the instrument and sends its `id` to your server.
> 6. Your server fetches the instrument from lite, decides what to do, and optionally charges it.

> [tab] Android
>
> 1. Your server creates a **tokenization session** with the lite API and gets back its `client_secret`.
> 2. Your app starts the SDK with that `client_secret`.
> 3. The customer enters a card in the secure fields.
> 4. The SDK encrypts the card and saves it with lite. Nothing is charged.
> 5. Your app receives the instrument and sends its `id` to your server.
> 6. Your server fetches the instrument from lite, decides what to do, and optionally charges it.

> [tab] Flutter
>
> 1. Your server creates a **tokenization session** with the lite API and gets back its `client_secret`.
> 2. Your app opens a `LiteCheckout` with that `client_secret`.
> 3. The customer enters a card in the secure fields, or authorizes Apple Pay on iOS.
> 4. The SDK encrypts the card and saves it with lite. Nothing is charged.
> 5. Your app receives the instrument and sends its `id` to your server.
> 6. Your server fetches the instrument from lite, decides what to do, and optionally charges it.

## Before you begin

> [tab] iOS
>
> You need:
>
> * A lite account with a **terminal** that has **cards** enabled. To save cards with Apple Pay, enable **Apple Pay** on the same terminal. A tokenization session offers only the payment methods enabled there.
>
> * lite API keys, kept on your server.
>
> * A backend endpoint that creates tokenization sessions.
>
> * Xcode 15 or later, and an app targeting iOS 15 or later.
>
> > [!WARNING]
> >
> > Never put your lite API keys in your app. Your server creates the session and sends only its `client_secret` to the app.

> [tab] Android
>
> You need:
>
> * A lite account with a **terminal** that has **cards** enabled. A tokenization session offers only the payment methods enabled there.
>
> * lite API keys, kept on your server.
>
> * A backend endpoint that creates tokenization sessions.
>
> * An app with `minSdk` 26 or higher and `compileSdk` 34 or higher. The secure fields come as Compose functions and as Android views.
>
> > [!WARNING]
> >
> > Never put your lite API keys in your app, its resources or `BuildConfig`. Your server creates the session and sends only its `client_secret` to the app.

> [tab] Flutter
>
> You need:
>
> * A lite account with a **terminal** that has **cards** enabled. To save cards with Apple Pay, enable **Apple Pay** on the same terminal. A tokenization session offers only the payment methods enabled there.
>
> * lite API keys, kept on your server.
>
> * A backend endpoint that creates tokenization sessions.
>
> * Flutter 3.44.2 or later with Dart 3.12.2 or later, Xcode 15 or later, iOS 15 or later, and Android `minSdk` 26 or higher.
>
> * An app for iOS or Android. The SDK doesn't run on web or desktop: there its widgets show placeholder text and its calls throw.
>
> > [!WARNING]
> >
> > Never put your lite API keys in your app or Dart code. Your server creates the session and sends only its `client_secret` to the app.

## 1. Install the SDK

> [tab] iOS
>
> In Xcode, select **File → Add Package Dependencies**, enter the package URL, and add the `LiteSDK` product to your app target:
>
> ```text theme={null}
> https://github.com/lite-sa/lite-ios.git
> ```
>
> If you manage dependencies in `Package.swift`:
>
> ```swift theme={null}
> dependencies: [
>     .package(url: "https://github.com/lite-sa/lite-ios.git", exact: "0.2.0"),
> ]
> ```
>
> ```swift theme={null}
> .product(name: "LiteSDK", package: "lite-ios")
> ```
>
> Then import it where you save cards:
>
> ```swift theme={null}
> import LiteSDK
> ```

> [tab] Android
>
> Make sure Maven Central is in your repositories:
>
> ```kotlin theme={null}
> dependencyResolutionManagement {
>     repositories {
>         google()
>         mavenCentral()
>     }
> }
> ```
>
> Add the SDK to your app module. Its API uses Jetpack Compose, AndroidX `ViewModel` and Kotlin coroutines, but it doesn't put them on your app's compile classpath, so add them too. SDK 0.2.0 uses these versions:
>
> ```kotlin theme={null}
> dependencies {
>     implementation("sa.lite:lite-android:0.2.0")
>     implementation(platform("androidx.compose:compose-bom:2024.10.01"))
>     implementation("androidx.compose.material3:material3")
>     implementation("androidx.activity:activity-compose:1.9.3")
> }
> ```
>
> For the Compose samples on this page, turn on Compose in your app module: apply the Kotlin Compose compiler plugin and set `buildFeatures { compose = true }`. The samples use these imports:
>
> ```kotlin theme={null}
> import sa.lite.checkout.ui.* // Lite, LiteHost, the fields
> import sa.lite.checkout.model.LiteInstrument
> import sa.lite.checkout.model.TokenizeErrorCode
> ```
>
> The SDK declares the internet permission, and it is merged into your app's manifest.

> [tab] Flutter
>
> ```yaml theme={null}
> dependencies:
>   lite_flutter: ^0.2.0
> ```
>
> Then run `flutter pub get`. The plugin brings in the native lite SDKs itself, so don't add them to your app. Import it where you save cards:
>
> ```dart theme={null}
> import 'package:lite_flutter/lite_flutter.dart';
> ```
>
> **iOS.** Swift Package Manager is required, and is on by default since Flutter 3.44. If your app turned it off, remove `enable-swift-package-manager: false` from `flutter: config:` in `pubspec.yaml` and run `flutter pub get` again.
>
> **Android.** Make the host activity a `FlutterFragmentActivity`. The Checkout SDK's embeddable form requires it, so one activity then serves both SDKs:
>
> ```kotlin theme={null}
> import io.flutter.embedding.android.FlutterFragmentActivity
>
> class MainActivity : FlutterFragmentActivity()
> ```

## 2. Create a tokenization session

A **tokenization session** is a checkout session that saves one card instead of taking a payment. Your server creates it with your API key, the same way as a payment session, with `type: "tokenization"` and the customer's `id` (at least 3 characters).

```bash theme={null}
curl https://api.lite.sa/checkout-sessions \
  -H "x-api-key: $LITE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "tokenization",
    "customer": { "id": "cust_8f3a91" },
    "expiry": 600
  }'
```

```json theme={null}
{
  "id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
  "session_id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
  "type": "tokenization",
  "client_secret": "eyJhbGciOiJIUzI1NiIs...",
  "status": "Pending",
  "expires_on": "2026-06-01T12:10:00.000Z",
  "customer": { "id": "cust_8f3a91" }
}
```

Check that `type` is `tokenization` and `customer.id` is the customer you're serving. Send the `client_secret` to the app exactly as you received it: it's a signed token (a JWT), not an ID, and the SDK fails to start with any other value.

A tokenization session takes no payment fields. Sending `amount`, `currency`, `order`, `redirect_urls`, `splits`, `capture_mode`, `processing_type`, `three_ds_required` or `metadata` returns a 400. Send only `type`, `customer`, and optionally `terminal_id` and `expiry`. The fields the [Create a checkout session](https://docs.lite.sa/api-reference/hosted-checkout/create-a-checkout-session.md) reference marks required apply to payment sessions only.

`terminal_id` is optional and sets the card networks and wallets the session offers. Without it, the session uses your default online terminal. To use another, send its ID: open the terminal under **Acceptance → Online** in the dashboard, and the ID is the last part of the page address.

Create the session when the customer reaches the card step, not when the app launches. It expires after `expiry` seconds, or after 15 minutes if you leave `expiry` out.

## 3. Pass the client secret to the SDK

> [tab] iOS
>
> The **`client_secret`** is a short-lived credential for this one session. It lets the SDK read the session and save one card on it. It cannot read other sessions, and it cannot pay. Return it from your server to the app. Keep the session `id` on your server.
>
> Do not log the `client_secret`.
>
> Create one `Lite` for the screen that saves the card, and start it with the secret:
>
> ```swift theme={null}
> @StateObject private var lite = Lite()
>
> // When your server returns the client secret:
> await lite.start(clientSecret: clientSecret)
> ```
>
> `lite.phase` becomes `.ready` once the session is loaded, or `.failed(message)` if the secret is expired or rejected. `lite.session?.isTokenization` is `true` for a tokenization session.

> [tab] Android
>
> The **`client_secret`** is a short-lived credential for this one session. It lets the SDK read the session and save one card on it. It cannot read other sessions, and it cannot pay. Return it from your server to the app. Keep the session `id` on your server.
>
> Do not log the `client_secret`.
>
> `Lite` is a `ViewModel`. Own it in the Activity, and start it with the secret:
>
> ```kotlin theme={null}
> class SaveCardActivity : ComponentActivity() {
>     private val lite: Lite by viewModels()
>
>     override fun onCreate(savedInstanceState: Bundle?) {
>         super.onCreate(savedInstanceState)
>         // Lite outlives a rotation: start it only once.
>         if (lite.phase.value == Lite.Phase.Idle) lite.start(clientSecret)
>         setContent {
>             LiteHost(lite) {
>                 SaveCardScreen(lite)
>             }
>         }
>     }
> }
> ```
>
> `lite.phase` becomes `Lite.Phase.Ready` once the session is loaded, or `Lite.Phase.Failed` if the secret is expired or rejected. Start only while `lite.phase` is `Idle`: starting again forgets that this `Lite` already saved a card on the session.

> [tab] Flutter
>
> The **`client_secret`** is a short-lived credential for this one session. It lets the SDK read the session and save one card on it. It cannot read other sessions, and it cannot pay. Return it from your server to the app. Keep the session `id` on your server.
>
> Do not log the `client_secret`.
>
> Open a `LiteCheckout` with the secret and start it:
>
> ```dart theme={null}
> final checkout = LiteCheckout(clientSecret: clientSecret);
>
> try {
>   await checkout.start();
> } on LiteCheckoutException catch (error) {
>   // The secret is expired or rejected.
>   showError(error.message);
> } catch (error) {
>   // A blank secret, an unsupported platform, no Android activity, or the checkout was disposed.
>   showError('Checkout is unavailable. Try again.');
> }
> ```
>
> `checkout.isTokenization` is `true` for a tokenization session. `LiteCheckout` is a `ChangeNotifier`, so you can rebuild your UI from it with `ListenableBuilder`.

## 4. Collect the card

> [tab] iOS
>
> ### Secure fields (cards)
>
> Place the secure fields in your layout and add your own **Save card** button. Enable it on `lite.isComplete`, which is `true` once the card in the fields is complete.
>
> ```swift theme={null}
> VStack(spacing: 12) {
>     LiteCardholderNameField(lite: lite)
>     LiteCardNumberField(lite: lite)
>     LiteExpiryField(lite: lite)
>     LiteCvvField(lite: lite)
>
>     Button("Save card") {
>         Task {
>             let result = await lite.tokenize(storeForFuture: true)
>             handle(result)
>         }
>     }
>     .disabled(!lite.isComplete)
> }
> ```
>
> * `tokenize` saves the card and never charges it. Pass `storeForFuture: true` only with the customer's consent to keep the card for later payments. Without it, the instrument is for a single payment.
> * Place at most one field of each type for a `Lite`. Keep the fields in a `VStack` or `ScrollView`, not a `List` or `LazyVStack`, which clear the typed card when it scrolls away.
> * Each field's `onChange` reports `valid`, `focused`, `brand` and `error`, and never the card data.
> * Calling `tokenize` again while a save is running returns the same result.
>
> ### Elements: Apple Pay
>
> On a tokenization session, `LiteApplePayButton` saves the card the customer authorizes instead of paying. The sheet reads **Save card** with nothing due, and nothing is charged. Give the button an `onTokenize`. It receives the same result as `tokenize()`, after the sheet closes:
>
> ```swift theme={null}
> LiteApplePayButton(lite, onResult: { _ in }, onTokenize: { result in
>     handle(result)
> })
> ```
>
> * Without `onTokenize`, the button does not show on a tokenization session.
> * The button shows only when the session enables Apple Pay and the device can pay with it.
> * The button never asks lite to keep the card for later payments: the instrument it saves is for a single payment. To keep a card on file, use the secure fields with `tokenize(storeForFuture: true)`.
> * If the customer closes the Apple Pay sheet without authorizing, the button calls nothing.
> * If the customer tries again in the same sheet after a failure, you get only the last attempt's result.
>
> Apple Pay needs your app to carry the Apple Pay entitlement, with the Merchant ID that matches the session's `merchant_identifier`. Follow [Apple Pay](https://docs.lite.sa/guides/checkout-sdk.md#apple-pay) in the Checkout SDK guide. Test it on a physical device.

> [tab] Android
>
> ### Secure fields (cards)
>
> Place the secure fields in your layout and add your own **Save card** button. Enable it on `lite.isComplete`, which is `true` once the card in the fields is complete.
>
> ```kotlin theme={null}
> @Composable
> fun SaveCardScreen(lite: Lite) {
>     val complete by lite.isComplete.collectAsState()
>     val scope = rememberCoroutineScope()
>
>     Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
>         LiteCardholderNameField(lite)
>         LiteCardNumberField(lite)
>         LiteExpiryField(lite)
>         LiteCvvField(lite)
>
>         Button(
>             onClick = { scope.launch { handle(lite.tokenize(storeForFuture = true)) } },
>             enabled = complete,
>         ) {
>             Text("Save card")
>         }
>     }
> }
> ```
>
> * `tokenize` saves the card and never charges it. Pass `storeForFuture = true` only with the customer's consent to keep the card for later payments. Without it, the instrument is for a single payment.
> * `lite.launchTokenize(storeForFuture) { result -> … }` does the same on the `Lite` scope, if you'd rather not launch a coroutine.
> * Place at most one field of each type for a `Lite`. Keep the fields in a `Column`, not a `LazyColumn` or `LazyRow`, which clear the typed card when it scrolls away. With views instead of Compose, use `LiteCardNumberFieldView`, `LiteExpiryFieldView`, `LiteCvvFieldView` and `LiteCardholderNameFieldView`.
> * Each field's change callback reports `valid`, `focused`, `brand` and `error`, and never the card data. While a field is on screen, the SDK sets `FLAG_SECURE` on the window.
> * Calling `tokenize` again while a save is running returns the same result.

> [tab] Flutter
>
> ### Secure fields (cards)
>
> Place the secure fields in your layout and add your own **Save card** button. Enable it on `checkout.isComplete`, which is `true` once the card in the fields is complete and nothing is running.
>
> ```dart theme={null}
> ListenableBuilder(
>   listenable: checkout,
>   builder: (context, _) => Column(
>     crossAxisAlignment: CrossAxisAlignment.stretch,
>     children: [
>       LiteCardholderNameField(checkout: checkout),
>       LiteCardNumberField(checkout: checkout),
>       LiteExpiryField(checkout: checkout),
>       LiteCvvField(checkout: checkout),
>       FilledButton(
>         onPressed: checkout.isComplete
>             ? () async => handle(await checkout.tokenize(storeForFuture: true))
>             : null,
>         child: const Text('Save card'),
>       ),
>     ],
>   ),
> )
> ```
>
> * `tokenize` saves the card and never charges it. Pass `storeForFuture: true` only with the customer's consent to keep the card for later payments. Without it, the instrument is for a single payment.
> * Use `isComplete` for the Save button, not `isReadyToPay`, which is about paying.
> * Place at most one field of each type for a checkout. The fields can be in the tree before `start()` finishes; they stay empty until the session opens, and they stay alive when a `ListView` scrolls them off screen.
> * Each field's `onChange` reports `valid`, `focused`, `brand` and `error`, and never the card data. Style the fields with `LiteFieldStyle`.
> * Calling `tokenize` again while a save is running returns the same future. `checkout.isTokenizing` is `true` meanwhile.
>
> ### Elements: Apple Pay (iOS)
>
> On iOS, on a tokenization session, `LiteApplePayButton` saves the card the customer authorizes instead of paying. The sheet reads **Save card** with nothing due, and nothing is charged. The result arrives on `checkout.onTokenizeResult`, after the sheet closes:
>
> ```dart theme={null}
> checkout.onTokenizeResult = handle;
>
> // In your layout:
> LiteApplePayButton(checkout: checkout)
> ```
>
> * The button shows only on iOS, when the session enables Apple Pay, the device can pay with it, and `onTokenizeResult` is set. Set the listener before the button is on screen. On Android it takes no space.
> * The button never asks lite to keep the card for later payments: the instrument it saves is for a single payment. To keep a card on file, use the secure fields with `tokenize(storeForFuture: true)`.
> * If the customer closes the Apple Pay sheet without authorizing, nothing is reported.
> * If the customer tries again in the same sheet after a failure, you get only the last attempt's result.
>
> Apple Pay needs your iOS app to carry the Apple Pay entitlement, with the Merchant ID that matches the session's `merchant_identifier`. Follow [Apple Pay (iOS)](https://docs.lite.sa/guides/checkout-sdk.md#apple-pay-ios) in the Checkout SDK guide. Test it on a physical device.

## 5. Handle the tokenization result

> [tab] iOS
>
> Both `tokenize()` and the Apple Pay button return a `TokenizeResult`:
>
> ```swift theme={null}
> func handle(_ result: TokenizeResult) {
>     switch result.status {
>     case .success:
>         // Send the id to your server; fetch the instrument there before you rely on it.
>         sendToServer(result.instrument!.id)
>     case .failure:
>         show(result.errorCode)
>     }
> }
> ```
>
> On success, `result.instrument` is a `LiteInstrument`:
>
> | Property | API field | Description |
> | - | - | - |
> | `id` | `id` | The instrument's id. Pay with this. |
> | `type` | `type` | `.card` for the secure fields, `.applePay` for Apple Pay. |
> | `holderId` | `holder_id` | The session's customer. |
> | `futureUsage` | `future_usage` | Set when the card is kept for later payments. `nil` for a single-use instrument. |
> | `agreementId` | `agreement_id` | The agreement the card is kept under. Set whenever `futureUsage` is. See [Payment instruments](https://docs.lite.sa/guides/payment-instruments.md). |
> | `card.scheme` | `card.scheme` | `mada`, `visa`, `mastercard`, and others. |
> | `card.last4` | `card.last4` | The last four digits. |
> | `card.expiryMonth`, `card.expiryYear` | `card.expiry_month`, `card.expiry_year` | Strings: `"03"`, `"2028"`. |
> | `card.issuerBin` | `card.issuer_bin` | The issuer's BIN. |
> | `card.fundingSource` | `card.funding_source` | `credit`, `debit`, `prepaid` or `charge`. |
> | `card.issuerName` | `card.issuer_name` | The issuing bank's name. |
> | `card.issuerCountry` | `card.issuer_country` | ISO 3166-1 alpha-2, such as `SA`. |
>
> Any card detail lite doesn't know is `nil`. If you pass `storeForFuture: true` and the customer already has this card stored, lite returns the instrument they already have, with its `id`.
>
> On failure, `result.errorCode` says why, and `result.apiErrorCode` carries lite's own code when there is one:
>
> | `errorCode` | What happened | What to do |
> | - | - | - |
> | `tokenize_failed` | The card was incomplete, lite refused it, or lite could not be reached. | Let the customer correct the card and try again on the same session. |
> | `session_expired` | The session expired before the card was saved. | Create a new session. |
> | `session_consumed` | This `Lite` already saved a card on this session. | Create a new session for another card. |
> | `session_type_unsupported` | The `client_secret` belongs to a payment session. | Create the session with `type: "tokenization"`. |
> | `card_not_configured` | Cards are not enabled on the session. | Enable cards on the terminal. |
>
> A session saves **one** card, whether from the secure fields or Apple Pay. A refused attempt doesn't use the session up, so the customer can retry until it expires.
>
> > [!WARNING]
> >
> > **Make decisions on your server.** The instrument reached your app through the customer's device. Send only its `id` to your server, fetch the instrument from lite there, and check that its `holder_id` is the customer you're serving before you rely on its card details.

> [tab] Android
>
> `tokenize()` returns a `Lite.TokenizeResult`:
>
> ```kotlin theme={null}
> fun handle(result: Lite.TokenizeResult) {
>     if (result.isSuccess) {
>         // Send the id to your server; fetch the instrument there before you rely on it.
>         sendToServer(result.instrument!!.id)
>     } else {
>         show(result.errorCode)
>     }
> }
> ```
>
> On success, `result.instrument` is a `LiteInstrument`. Its `card` is `null` for an instrument that isn't backed by a card, so read it as `result.instrument?.card?.scheme`.
>
> | Property | API field | Description |
> | - | - | - |
> | `id` | `id` | The instrument's id. Pay with this. |
> | `type` | `type` | `InstrumentType.CARD`. |
> | `createdAt` | `created_at` | When lite created the instrument. |
> | `merchantId` | `merchant_id` | The account the instrument belongs to. |
> | `holderId` | `holder_id` | The session's customer. |
> | `holderType` | `holder_type` | The type of holder, such as `CUSTOMER`. |
> | `futureUsage` | `future_usage` | Set when the card is kept for later payments. `null` for a single-use instrument. |
> | `agreementId` | `agreement_id` | The agreement the card is kept under. Set whenever `futureUsage` is. See [Payment instruments](https://docs.lite.sa/guides/payment-instruments.md). |
> | `card.scheme` | `card.scheme` | `mada`, `visa`, `mastercard`, and others. |
> | `card.last4` | `card.last4` | The last four digits. |
> | `card.expiryMonth`, `card.expiryYear` | `card.expiry_month`, `card.expiry_year` | Strings: `"03"`, `"2028"`. |
> | `card.issuerBin` | `card.issuer_bin` | The issuer's BIN. |
> | `card.fundingSource` | `card.funding_source` | `credit`, `debit`, `prepaid` or `charge`. |
> | `card.issuerName` | `card.issuer_name` | The issuing bank's name. |
> | `card.issuerCountry` | `card.issuer_country` | ISO 3166-1 alpha-2, such as `SA`. |
>
> Any card detail lite doesn't know is `null`. If you pass `storeForFuture = true` and the customer already has this card stored, lite returns the instrument they already have, with its `id`.
>
> On failure, `result.errorCode` says why: compare it with the `TokenizeErrorCode` constants, such as `TokenizeErrorCode.SESSION_EXPIRED`. `result.apiErrorCode` carries lite's own code when there is one:
>
> | `errorCode` | What happened | What to do |
> | - | - | - |
> | `tokenize_failed` | The card was incomplete, lite refused it, or lite could not be reached. | Let the customer correct the card and try again on the same session. |
> | `session_expired` | The session expired before the card was saved. | Create a new session. |
> | `session_consumed` | This `Lite` already saved a card on this session. | Create a new session for another card. |
> | `session_type_unsupported` | The `client_secret` belongs to a payment session. | Create the session with `type: "tokenization"`. |
> | `card_not_configured` | Cards are not enabled on the session. | Enable cards on the terminal. |
>
> A session saves **one** card. A refused attempt doesn't use the session up, so the customer can retry until it expires. After a successful save, the SDK clears the fields.
>
> > [!WARNING]
> >
> > **Make decisions on your server.** The instrument reached your app through the customer's device. Send only its `id` to your server, fetch the instrument from lite there, and check that its `holder_id` is the customer you're serving before you rely on its card details.

> [tab] Flutter
>
> Both `tokenize()` and `onTokenizeResult` give you a `TokenizeResult`:
>
> ```dart theme={null}
> void handle(TokenizeResult result) {
>   if (result.isSuccess) {
>     // Send the id to your server; fetch the instrument there before you rely on it.
>     sendToServer(result.instrument!.id);
>   } else {
>     showError(result.error ?? 'Could not save the card.');
>   }
> }
> ```
>
> On success, `result.instrument` is a `LiteInstrument`:
>
> | Property | API field | Description |
> | - | - | - |
> | `id` | `id` | The instrument's id. Pay with this. |
> | `type` | `type` | `LiteInstrumentType.card` for the secure fields, `LiteInstrumentType.applePay` for Apple Pay. |
> | `holderId` | `holder_id` | The session's customer. |
> | `futureUsage` | `future_usage` | Set when the card is kept for later payments. `null` for a single-use instrument. |
> | `agreementId` | `agreement_id` | The agreement the card is kept under. Set whenever `futureUsage` is. See [Payment instruments](https://docs.lite.sa/guides/payment-instruments.md). |
> | `card.scheme` | `card.scheme` | `mada`, `visa`, `mastercard`, and others. |
> | `card.last4` | `card.last4` | The last four digits. |
> | `card.expiryMonth`, `card.expiryYear` | `card.expiry_month`, `card.expiry_year` | Strings: `'03'`, `'2028'`. |
> | `card.issuerBin` | `card.issuer_bin` | The issuer's BIN. |
> | `card.fundingSource` | `card.funding_source` | `credit`, `debit`, `prepaid` or `charge`. |
> | `card.issuerName` | `card.issuer_name` | The issuing bank's name. |
> | `card.issuerCountry` | `card.issuer_country` | ISO 3166-1 alpha-2, such as `SA`. |
>
> Any card detail lite doesn't know is `null`. If you pass `storeForFuture: true` and the customer already has this card stored, lite returns the instrument they already have, with its `id`.
>
> On failure, `result.errorCode` is one of the `TokenizeErrorCode` constants: compare it with them, as in `result.errorCode == TokenizeErrorCode.sessionExpired`. `result.apiErrorCode` carries lite's own code when there is one:
>
> | `errorCode` | What happened | What to do |
> | - | - | - |
> | `tokenize_failed` (`TokenizeErrorCode.tokenizeFailed`) | The card was incomplete, lite refused it, or lite could not be reached. | Let the customer correct the card and try again on the same session. |
> | `session_expired` (`TokenizeErrorCode.sessionExpired`) | The session expired before the card was saved. | Create a new session. |
> | `session_consumed` (`TokenizeErrorCode.sessionConsumed`) | This `LiteCheckout` already saved a card on this session. | Create a new session for another card. |
> | `session_type_unsupported` (`TokenizeErrorCode.sessionTypeUnsupported`) | The `client_secret` belongs to a payment session. | Create the session with `type: "tokenization"`. |
> | `card_not_configured` (`TokenizeErrorCode.cardNotConfigured`) | Cards are not enabled on the session. | Enable cards on the terminal. |
>
> `tokenize()` doesn't throw for these: it resolves with the failure. It throws a `StateError` if you call it before `start()` or after `dispose()`. Its future fails if you dispose the checkout while a save runs, or if the plugin isn't available on the platform.
>
> A session saves **one** card, whether from the secure fields or Apple Pay. A refused attempt doesn't use the session up, so the customer can retry until it expires. After a success, disable your Save button.
>
> > [!WARNING]
> >
> > **Make decisions on your server.** The instrument reached your app through the customer's device. Send only its `id` to your server, fetch the instrument from lite there, and check that its `holder_id` is the customer you're serving before you rely on its card details.

## 6. Charge the instrument (optional)

> [tab] iOS
>
> Saving a card authorizes nothing, so the card can still be declined when you charge it. A card saved without `storeForFuture: true` is for one payment: charge it within about 20 minutes. There are two ways to charge an instrument.
>
> ### With the Checkout SDK
>
> Use this when the customer confirms the final price in your app. Your server creates a normal **payment session** for the same customer with the final amount. Start a `Lite` with that session's `client_secret` and pay with the instrument id. The customer doesn't enter the card again.
>
> ```swift theme={null}
> await lite.start(clientSecret: paymentClientSecret)
> let result = await lite.pay(instrumentId: instrumentId)
> ```
>
> `result` is the Checkout SDK's payment result: see [Handle the result](https://docs.lite.sa/guides/checkout-sdk.md#7-handle-the-result).
>
> ### With the Payments API
>
> A card saved with this SDK is stored as `unscheduled`, with no consent record, so charge it only with the customer present: in the app, with the Checkout SDK, as in the previous section. To charge a customer who isn't there, store the card with an agreement through the [instruments API](https://docs.lite.sa/guides/payment-instruments.md#store-a-card-with-an-agreement), then charge it from your server with [`POST /payments`](https://docs.lite.sa/guides/payments-api#charging-a-stored-card-card-on-file).

> [tab] Android
>
> Saving a card authorizes nothing, so the card can still be declined when you charge it. A card saved without `storeForFuture = true` is for one payment: charge it within about 20 minutes. There are two ways to charge an instrument.
>
> ### With the Checkout SDK
>
> Use this when the customer confirms the final price in your app. Your server creates a normal **payment session** for the same customer with the final amount. Start `Lite` with that session's `client_secret`, inside `LiteHost`, and pay with the instrument id. The customer doesn't enter the card again.
>
> ```kotlin theme={null}
> scope.launch {
>     // startSuspend returns once the session has loaded or failed.
>     lite.startSuspend(paymentClientSecret)
>     if (lite.phase.value == Lite.Phase.Ready) {
>         handle(lite.pay(instrumentId))
>     }
> }
> ```
>
> `start` doesn't wait for the session, and `pay` called before the session loads fails.
>
> `result` is the Checkout SDK's payment result: see [Handle the result](https://docs.lite.sa/guides/checkout-sdk.md#7-handle-the-result).
>
> ### With the Payments API
>
> A card saved with this SDK is stored as `unscheduled`, with no consent record, so charge it only with the customer present: in the app, with the Checkout SDK, as in the previous section. To charge a customer who isn't there, store the card with an agreement through the [instruments API](https://docs.lite.sa/guides/payment-instruments.md#store-a-card-with-an-agreement), then charge it from your server with [`POST /payments`](https://docs.lite.sa/guides/payments-api#charging-a-stored-card-card-on-file).

> [tab] Flutter
>
> Saving a card authorizes nothing, so the card can still be declined when you charge it. A card saved without `storeForFuture: true` is for one payment: charge it within about 20 minutes. There are two ways to charge an instrument.
>
> ### With the Checkout SDK
>
> Use this when the customer confirms the final price in your app. Your server creates a normal **payment session** for the same customer with the final amount. Open a new `LiteCheckout` with that session's `client_secret`, select the instrument, and pay. The customer doesn't enter the card again, so this screen needs no card fields.
>
> ```dart theme={null}
> final payment = LiteCheckout(clientSecret: paymentClientSecret);
>
> try {
>   await payment.start();
>   if (await payment.selectStoredInstrument(instrumentId)) {
>     final result = await payment.pay();
>     // See the Checkout SDK guide for PayResult.
>   }
> } on LiteCheckoutException catch (error) {
>   showError(error.message);
> } finally {
>   payment.dispose();
> }
> ```
>
> Dispose each `LiteCheckout` when you're done with it: until you do, it keeps a native checkout and its session open. `selectStoredInstrument` returns `false`, and sends nothing, for an empty id or a listed card whose scheme the session doesn't take. Any other id goes to lite, which accepts or refuses it. See [Handle the result](https://docs.lite.sa/guides/checkout-sdk.md#7-handle-the-result) for the payment result.
>
> ### With the Payments API
>
> A card saved with this SDK is stored as `unscheduled`, with no consent record, so charge it only with the customer present: in the app, with the Checkout SDK, as in the previous section. To charge a customer who isn't there, store the card with an agreement through the [instruments API](https://docs.lite.sa/guides/payment-instruments.md#store-a-card-with-an-agreement), then charge it from your server with [`POST /payments`](https://docs.lite.sa/guides/payments-api#charging-a-stored-card-card-on-file).

## 7. Clean up

> [tab] iOS
>
> When the customer leaves the screen without saving, or to start again with a new session, reset the SDK:
>
> ```swift theme={null}
> lite.reset()
> ```
>
> `reset()` cancels any running save and clears the session and the typed card. To save another card, create a new tokenization session and call `start` again.

> [tab] Android
>
> When the customer leaves the screen without saving, or to start again with a new session, reset the SDK:
>
> ```kotlin theme={null}
> lite.reset()
> ```
>
> `reset()` cancels any running save and clears the session and the typed card. To save another card, create a new tokenization session and call `start` again.

> [tab] Flutter
>
> Each `LiteCheckout` holds a native session. Dispose it when its screen goes away, usually in your `State.dispose`:
>
> ```dart theme={null}
> @override
> void dispose() {
>   checkout.dispose();
>   super.dispose();
> }
> ```
>
> A save still running at that point completes with a `StateError`. To save another card, create a new tokenization session and a new `LiteCheckout`.

## What's new in 0.2.0

> [tab] iOS
>
> * **Save cards with Apple Pay.** On a tokenization session, `LiteApplePayButton` saves the card when you pass `onTokenize`. `lite.isApplePayEnabledInSession` is now `true` on a tokenization session with Apple Pay active.
> * **Breaking: renamed instrument fields.** `card.funding` is now `card.fundingSource`, `card.issuer` is now `card.issuerName`, and `card.bin` is now `card.issuerBin`, read from the API's `issuer_bin`. New: `instrument.agreementId`.

> [tab] Android
>
> * **Breaking: renamed instrument fields.** `card.funding` is now `card.fundingSource`, `card.issuer` is now `card.issuerName`, and `card.bin` is now `card.issuerBin`, read from the API's `issuer_bin`. New: `instrument.agreementId`.

> [tab] Flutter
>
> * **Save cards with Apple Pay on iOS.** On a tokenization session, `LiteApplePayButton` saves the card, and `LiteCheckout.onTokenizeResult` reports it.
> * **Breaking: renamed instrument fields.** `card.funding` is now `card.fundingSource`, `card.issuer` is now `card.issuerName`, and `card.bin` is now `card.issuerBin`, read from the API's `issuer_bin`. New: `instrument.agreementId`. To get 0.2.0, change your constraint to `lite_flutter: ^0.2.0`: a caret on a 0.x version never moves to the next minor version.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.