> ## 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 Checkout SDK

> Accept card payments in your iOS, Android or Flutter app with lite's payment sheet, elements or secure fields, and Apple Pay on iOS.

> [tab] iOS
>
> **Version:** `0.2.0` (`lite-ios`)
>
> The Checkout SDK takes a payment in your iOS app. It collects the card or Apple Pay, encrypts card details on the device, and submits the payment to lite. Raw card details never reach your code or your server.

> [tab] Android
>
> **Version:** `0.2.0` (`sa.lite:lite-android`)
>
> The Checkout SDK takes a payment in your Android app. It collects the card, encrypts it on the device, and submits the payment to lite. Raw card details never reach your code or your server.

> [tab] Flutter
>
> **Version:** `0.2.0` (`lite_flutter`)
>
> The Checkout SDK takes a payment in your Flutter app, on iOS and Android. It collects the card or Apple Pay in native views, encrypts card details on the device, and submits the payment to lite. Raw card details never reach your Dart code or your server.

## Choose an integration

> [tab] iOS
>
> The SDK offers three ways to collect a payment method. All three use the same checkout session and return the same result.
>
> | Option | What you get | Use it when |
> | - | - | - |
> | **Payment sheet (drop-in)** | lite's complete checkout: card entry, saved cards, Apple Pay and the pay button. Present it over your screen, or place it inside your own screen as the embeddable payment form. | You want the quickest integration. Recommended. |
> | **Elements** | Ready-made payment-method components you place in your own screen: the Apple Pay button. | You lay out the checkout yourself and want Apple Pay in it. |
> | **Secure fields** | Card number, expiry, CVV and cardholder name inputs. You draw everything else, including the pay button. | You build the checkout UI yourself. Cards only. |

> [tab] Android
>
> The SDK offers three ways to collect a payment method. All three use the same checkout session and return the same result.
>
> | Option | What you get | Use it when |
> | - | - | - |
> | **Payment sheet (drop-in)** | lite's complete checkout: card entry, saved cards and the pay button. Present it over your screen, or place it inside your own screen as the embeddable payment form. | You want the quickest integration. Recommended. |
> | **Elements** | Ready-made payment-method components, such as wallet buttons. | Not available on Android yet. |
> | **Secure fields** | Card number, expiry, CVV and cardholder name inputs. You draw everything else, including the pay button. | You build the checkout UI yourself. Cards only. |

> [tab] Flutter
>
> The SDK offers three ways to collect a payment method. All three use the same checkout session and return the same result.
>
> | Option | What you get | Use it when |
> | - | - | - |
> | **Payment sheet (drop-in)** | lite's complete checkout: card entry, saved cards, Apple Pay on iOS and the pay button. Present it over your screen, or place it inside your own screen as the embeddable payment form. | You want the quickest integration. Recommended. |
> | **Elements** | Ready-made payment-method components you place in your own screen: the Apple Pay button (iOS). | You lay out the checkout yourself and want Apple Pay in it. |
> | **Secure fields** | Card number, expiry, CVV and cardholder name widgets. You draw everything else, including the pay button. | You build the checkout UI yourself. Cards only. |

## How it works

> [tab] iOS
>
> 1. Your server creates a **checkout session** with the lite API and gets back its `client_secret`.
> 2. Your app passes the `client_secret` to the SDK.
> 3. The SDK loads the session and shows the payment methods enabled for it.
> 4. The customer pays with a new card, a saved card or Apple Pay.
> 5. The SDK submits the payment and returns a result to your app.
> 6. Your server confirms the payment before you fulfil the order.

> [tab] Android
>
> 1. Your server creates a **checkout session** with the lite API and gets back its `client_secret`.
> 2. Your app passes the `client_secret` to the SDK.
> 3. The SDK loads the session and shows the payment methods enabled for it.
> 4. The customer pays with a new card or a saved card.
> 5. The SDK submits the payment and returns a result to your app.
> 6. Your server confirms the payment before you fulfil the order.

> [tab] Flutter
>
> 1. Your server creates a **checkout session** with the lite API and gets back its `client_secret`.
> 2. Your app passes the `client_secret` to the SDK.
> 3. The SDK loads the session and shows the payment methods enabled for it.
> 4. The customer pays with a new card, a saved card or Apple Pay on iOS.
> 5. The SDK submits the payment and returns a result to your app.
> 6. Your server confirms the payment before you fulfil the order.

## Before you begin

> [tab] iOS
>
> You need:
>
> * A lite account with a **terminal**. Enable the payment methods you want to offer there: **cards**, and **Apple Pay** if you'll offer it. A checkout session offers only the methods enabled on its terminal.
>
> * lite API keys, kept on your server.
>
> * A backend endpoint that creates checkout 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** with **cards** enabled. A checkout session offers only the methods enabled on its terminal.
>
> * lite API keys, kept on your server.
>
> * A backend endpoint that creates checkout sessions.
>
> * An app with `minSdk` 26 or higher and `compileSdk` 34 or higher. The payment sheet works from any Activity. The embeddable form needs Jetpack Compose. 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**. Enable the payment methods you want to offer there: **cards**, and **Apple Pay** if you'll offer it on iOS. A checkout session offers only the methods enabled on its terminal.
>
> * lite API keys, kept on your server.
>
> * A backend endpoint that creates checkout 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, so don't offer checkout on those platforms.
>
> > [!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. Create a checkout session

Your server creates a checkout session with your API key for each payment attempt. The session fixes the amount, currency, customer, and the payment methods and card networks on offer.

```bash theme={null}
curl https://api.lite.sa/checkout-sessions \
  -H "x-api-key: $LITE_API_KEY" \
  -H "idempotency-key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 4999,
    "currency": "SAR",
    "customer": {
      "id": "cust_8f3a91",
      "email": "john.doe@email.com",
      "first_name": "John",
      "last_name": "Doe"
    },
    "order": { "reference": "ORD-123456" },
    "redirect_urls": {
      "success": "https://example.com/checkout/success",
      "failure": "https://example.com/checkout/failure"
    },
    "expiry": 1800
  }'
```

```json theme={null}
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "type": "payment",
  "hosted_url": "https://checkout.lite.sa/pay/550e8400-e29b-41d4-a716-446655440000#eyJhbGciOiJIUzI1NiIs...",
  "client_secret": "eyJhbGciOiJIUzI1NiIs...",
  "status": "Pending",
  "expires_on": "2026-06-01T12:30:00.000Z",
  "order_id": "ORD-123456",
  "amount": 4999,
  "currency": "SAR",
  "customer": {
    "id": "cust_8f3a91",
    "email": "john.doe@email.com",
    "first_name": "John",
    "last_name": "Doe"
  },
  "order": { "reference": "ORD-123456" },
  "terminal_id": "0b9d1c3e-6a51-4f6e-9a54-0f4f2b6e7d11"
}
```

Send the `client_secret` to the app exactly as you received it. It's a signed token (a JWT), not an ID: the SDK reads from it which session to load and which lite server to call, so any other value fails when the SDK starts. The app doesn't use `hosted_url`, which is for the [hosted checkout page](https://docs.lite.sa/guides/hosted-checkout-page.md).

`amount` is in minor units: `4999` is SAR 49.99. `terminal_id` is optional: 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. Include the customer's `id` to offer the cards they saved before. If you send `customer` at all, its `id` is required, at least 3 characters: a `customer` with only an email or a name is refused with a 400. `redirect_urls` is required, with `https` URLs, even though the app never redirects to them. See [Create a checkout session](https://docs.lite.sa/api-reference/hosted-checkout/create-a-checkout-session.md) for every field.

Only one unexpired session can exist per `order.reference`, whatever its status. Creating another for the same reference returns `409` `DUPLICATE_REQUEST`, with or without an idempotency key. So give each new session its own `order.reference`, for example `ORD-123456-2`, and check first that the earlier attempt didn't succeed.

MOTO sessions (`processing_type: "MOTO"`) are not supported in the app. Create them for the web SDK only.

## 2. 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 take payments:
>
> ```swift theme={null}
> import LiteSDK
> ```
>
> **App privacy.** With each payment, the SDK sends lite details of the device: its identifier for vendor, model, iOS version, screen size, preferred language, and time zone. The package has no privacy manifest, so include this data in your app's privacy details in App Store Connect.

> [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, LitePaymentSheet, LitePaymentForm, the fields, LiteFieldStyle
> import sa.lite.checkout.model.PaymentOperationStatus
> import sa.lite.checkout.core.LiteCardFieldChange
> ```
>
> The SDK declares the internet permission, and it is merged into your app's manifest.
>
> **Data safety.** On Android, with each payment the SDK sends lite the device's model, manufacturer, Android version, language, screen size and time zone offset, and an identifier derived from its Android ID and your app's package name. Include this data in your app's Data safety form on Google Play.

> [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 (`lite-ios` and `lite-android` 0.2.0), so don't add them to your app. Import it where you take payments:
>
> ```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 embeddable form requires it. Use it for the secure fields and the payment sheet too, so one activity serves the whole checkout:
>
> ```kotlin theme={null}
> import io.flutter.embedding.android.FlutterFragmentActivity
>
> class MainActivity : FlutterFragmentActivity()
> ```
>
> The plugin builds with `compileSdk` 35 and declares the internet permission, which is merged into your app's manifest.
>
> **App privacy.** On iOS, with each payment the SDK sends lite details of the device: its identifier for vendor, model, iOS version, screen size, preferred language and time zone. Include this data in your app's privacy details in App Store Connect.
>
> **Data safety.** On Android, with each payment the SDK sends lite the device's model, manufacturer, Android version, language, screen size and time zone offset, and an identifier derived from its Android ID and your app's package name. Include this data in your app's Data safety form on Google Play.

## 3. Pass the client secret to the SDK

> [tab] iOS
>
> The **`client_secret`** is a short-lived credential for this one checkout session. It lets the SDK read the session and pay it, and nothing else: it can't read other sessions or move money elsewhere. Return it from your server to the app, and keep the session `id` on your server to confirm the payment later.
>
> Do not log the `client_secret`, and create a new session for each checkout attempt.
>
> The payment sheet and the embeddable form take the secret directly. With the Apple Pay button or the secure fields, start a `Lite` with it yourself. `Lite` runs on the main actor, so start it from your view, for example in `.task`:
>
> ```swift theme={null}
> struct CheckoutView: View {
>     let clientSecret: String
>     @StateObject private var lite = Lite()
>
>     var body: some View {
>         CardFields(lite: lite) // Your layout: see step 5.
>             .task { await lite.start(clientSecret: clientSecret) }
>     }
> }
> ```
>
> `lite.phase` becomes `.ready` once the session is loaded. It becomes `.failed(message)` if the secret is expired or rejected, the session is MOTO, or lite can't be reached. With the Apple Pay button or the secure fields, show that message to the customer. The payment sheet and the embeddable form show it themselves, and don't report it as a result: the form never calls `onPayResult`, so watch `lite.phase` for `.failed`, and the sheet completes with `.cancelled` when the customer closes it.
>
> A session that already ended still loads. `phase` becomes `.ready`, and `lite.lastPayResult` holds the outcome: `.alreadyCompleted` if the session was paid, `.failure` if it failed. The payment sheet and the embeddable form pass it to your callback. With the Apple Pay button or the secure fields nothing calls you, so check `lite.lastPayResult` once `phase` is `.ready`, and don't show the pay controls if it's set.

> [tab] Android
>
> The **`client_secret`** is a short-lived credential for this one checkout session. It lets the SDK read the session and pay it, and nothing else: it can't read other sessions or move money elsewhere. Return it from your server to the app, and keep the session `id` on your server to confirm the payment later.
>
> Do not log the `client_secret`, and create a new session for each checkout attempt.
>
> The payment sheet and the embeddable form take the secret directly. With the secure fields, start `Lite` with it yourself. `Lite` is a `ViewModel`: own it in the Activity, and wrap your checkout in `LiteHost`, which connects `Lite` to the Activity it needs while paying:
>
> ```kotlin theme={null}
> class CheckoutActivity : 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) {
>                 CheckoutScreen(lite)
>             }
>         }
>     }
> }
> ```
>
> Without `LiteHost`, call `lite.attach(this)` in `onCreate` and `lite.detach(this)` in `onDestroy` instead. Don't do both for the same `Lite`.
>
> Start only while `lite.phase` is `Idle`. Starting again reloads the session and clears the selected saved card and the save-card switch. If the system ends your app's process, the session and the typed card are gone: start again with a `client_secret` from your server. `start` returns at once. To wait until the session has loaded or failed, call `startSuspend` from a coroutine instead.
>
> `lite.phase` becomes `Lite.Phase.Ready` once the session is loaded. It becomes `Lite.Phase.Failed(message)` if the secret is expired or rejected, the session is MOTO, or lite can't be reached. With the secure fields, show that message to the customer. The payment sheet and the embeddable form show it themselves, and the form doesn't call `onPayResult` then.
>
> A session that already ended still loads. `phase` becomes `Ready`, and `lite.lastPayResult` holds the outcome: `ALREADY_COMPLETED` if the session was paid, `FAILURE` if it failed. The payment sheet and the embeddable form pass it to your callback. With the secure fields nothing calls you, so check `lite.lastPayResult.value` once `phase` is `Ready`, and don't show the card fields if it's set.

> [tab] Flutter
>
> The **`client_secret`** is a short-lived credential for this one checkout session. It lets the SDK read the session and pay it, and nothing else: it can't read other sessions or move money elsewhere. Return it from your server to the app, and keep the session `id` on your server to confirm the payment later.
>
> Do not log the `client_secret`, and create a new session for each checkout attempt.
>
> The payment sheet and the embeddable form take the secret directly. With the Apple Pay button or the secure fields, open a `LiteCheckout` with it 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, or the session is MOTO.
>   showError(error.message);
> } catch (error) {
>   showError('Checkout is unavailable. Try again.');
> }
> ```
>
> `start()` throws a `LiteCheckoutException` when lite refuses the session. It throws other errors when the secret is blank, the platform isn't iOS or Android, the native side can't open checkout (on Android, for example, when there's no activity), or you dispose the checkout while it starts.
>
> A session that already ended still starts. `checkout.lastPayResult` then holds `alreadyCompleted` or `failure`, and `onPayResult` receives it too. Check it after `start()`, and don't show the pay controls if it's set.
>
> The payment sheet and the embeddable form handle a bad secret themselves: if it's expired or rejected, the sheet shows the message and completes with `cancelled` when the customer closes it.
>
> `LiteCheckout` is a `ChangeNotifier`, so you can rebuild your UI from it with `ListenableBuilder`.

## 4. Payment sheet and elements

> [tab] iOS
>
> ### Payment sheet (drop-in)
>
> `LitePaymentSheet` presents lite's complete checkout over a visible `UIViewController`, and calls you back when it closes. A SwiftUI view has no view controller of its own: present the sheet from your window's top view controller.
>
> ```swift theme={null}
> LitePaymentSheet.present(
>     from: self,
>     clientSecret: clientSecret,
>     configuration: .init(
>         cardLayout: .compact,
>         defaultStoreForFuture: false,
>         showResultBeforeDismiss: true,
>         applePayEnabled: true,
>         privacyPolicyUrl: "https://merchant.example/privacy"
>     )
> ) { result in
>     handle(result)
> }
> ```
>
> | Option | Default | What it does |
> | - | - | - |
> | `cardLayout` | `.compact` | The card entry layout, as for the embeddable form. |
> | `defaultStoreForFuture` | `false` | Turns the **Save card for future purchase** control on by default. |
> | `showResultBeforeDismiss` | `true` | Shows the outcome in the sheet before it closes. |
> | `applePayEnabled` | `true` | Offers Apple Pay when the session enables it. |
> | `privacyPolicyUrl` | `nil` | Your privacy policy, linked in the sheet's footer. |
>
> Only one sheet can be on screen at a time. A second `present` completes with a failure whose error code is `already_presenting`.
>
> ### Cards: the embeddable payment form
>
> `LitePaymentForm` is lite's card and saved-card checkout, placed inside your SwiftUI screen. It draws its own pay button.
>
> ```swift theme={null}
> struct CheckoutView: View {
>     let clientSecret: String
>     @StateObject private var lite = Lite()
>
>     var body: some View {
>         LitePaymentForm(
>             lite: lite,
>             cardLayout: .compact,
>             clientSecret: clientSecret,
>             applePayEnabled: true,
>             privacyPolicyUrl: "https://merchant.example/privacy",
>             onPayResult: { result in
>                 handle(result)
>             }
>         )
>     }
> }
> ```
>
> Label `onPayResult:`. Written as a trailing closure, the closure goes to `onPrivacyClick` instead, and Swift 6 refuses to compile it.
>
> Passing `clientSecret` starts the SDK for you. Keep one `Lite` for the checkout, owned by `@StateObject` or something with the same lifetime: don't create one during a view update. `LitePaymentForm` and `LiteApplePayButton` are SwiftUI views: in a UIKit screen, host them in a `UIHostingController`.
>
> | Option | Default | What it does |
> | - | - | - |
> | `cardLayout` | `.compact` | The card entry layout. See the next table. |
> | `applePayEnabled` | `true` | Shows Apple Pay in the form when the session offers it. |
> | `showResultInline` | `false` | Shows the outcome in the form after a payment. By default the form shows no result: your `onPayResult` handles it. |
> | `privacyPolicyUrl` | `nil` | Your privacy policy, linked in the form's footer. |
> | `onPrivacyClick` | `nil` | Called when the customer taps the privacy link, instead of opening `privacyPolicyUrl`. |
>
> | `cardLayout` | Card entry |
> | - | - |
> | `.compact` | A grouped, compact card form. The default. |
> | `.form` | Separate card number, expiry, CVV and cardholder name fields. |
> | `.line` | A single condensed row. |
>
> ### Apple Pay
>
> `LiteApplePayButton` is Apple Pay as a standalone button, for a checkout you lay out yourself:
>
> ```swift theme={null}
> LiteApplePayButton(lite, type: .buy, style: .black) { result in
>     handle(result)
> }
> ```
>
> The button shows only when the session enables Apple Pay and the device can pay with one of its card networks. It runs the Apple Pay sheet and the payment itself. Don't route Apple Pay through `lite.pay()`. If the customer closes the Apple Pay sheet without paying, the button calls nothing, and your screen stays as it was.
>
> Apple Pay needs your app to carry the Apple Pay entitlement:
>
> 1. Create your own Apple Pay Merchant ID in your Apple Developer account: an iOS app can't use lite's. Then contact lite to set it on your online terminal and to exchange the payment processing certificate, so lite can decrypt your Apple Pay payments. The dashboard can't do this for business accounts yet.
> 2. In Apple Developer, enable Apple Pay for your app's identifier.
> 3. In Xcode, open your target's **Signing & Capabilities**, add **Apple Pay**, and select that Merchant ID.
> 4. Refresh the provisioning profile so it carries the entitlement.
>
> The Merchant ID must match the session's `merchant_identifier`, and the session must return Apple Pay as `ACTIVE`. The SDK reads both from the session. Test Apple Pay on a physical device with a card in Wallet.
>
> ### Appearance and language
>
> The payment sheet and the embeddable form are in English only and always light, whatever the device's language or dark mode setting, and you can't change their colours or fonts. The secure fields' placeholders and messages are in English too, and the card number, expiry, and CVV always run left to right. To match your app's look, use the secure fields and style them with `LiteFieldStyle`: see step 5.

> [tab] Android
>
> ### Payment sheet (drop-in)
>
> `LitePaymentSheet` presents lite's complete checkout from an `Activity`, and calls you back when it closes:
>
> ```kotlin theme={null}
> LitePaymentSheet.present(
>     activity = this,
>     clientSecret = clientSecret,
>     configuration = LitePaymentSheet.Configuration(
>         cardLayout = LiteCardLayout.COMPACT,
>         defaultStoreForFuture = false,
>         showResultBeforeDismiss = true,
>         privacyPolicyUrl = "https://merchant.example/privacy",
>     ),
> ) { result ->
>     handle(result)
> }
> ```
>
> | Option | Default | What it does |
> | - | - | - |
> | `cardLayout` | `COMPACT` | The card entry layout, as for the embeddable form. |
> | `defaultStoreForFuture` | `false` | Turns the **Save card for future purchase** control on by default. |
> | `showResultBeforeDismiss` | `true` | Shows the outcome in the sheet before it closes. |
> | `privacyPolicyUrl` | `null` | Your privacy policy, linked in the sheet's footer. |
>
> The sheet connects itself to the Activity, so it needs no `LiteHost`. Only one sheet can be on screen at a time. A second `present` completes with a failure whose error code is `already_presenting`.
>
> * The sheet works from any `Activity`. From a `ComponentActivity`, it uses the Activity's own `Lite`, the one `by viewModels()` returns, so it replaces a session you started there.
> * On `CANCELLED`, the sheet closes at once, even with `showResultBeforeDismiss`.
> * If the Activity is destroyed while the sheet is open, on a rotation for example, the sheet completes with `CANCELLED`.
> * Screenshots and screen recordings of the sheet come out blank.
>
> ### Cards: the embeddable payment form
>
> `LitePaymentForm` is lite's card and saved-card checkout, placed inside your Compose screen. It draws its own pay button.
>
> ```kotlin theme={null}
> setContent {
>     LiteHost(lite) {
>         LitePaymentForm(
>             lite = lite,
>             cardLayout = LiteCardLayout.COMPACT,
>             clientSecret = clientSecret,
>             privacyPolicyUrl = "https://merchant.example/privacy",
>             onPayResult = { result -> handle(result) },
>         )
>     }
> }
> ```
>
> Passing `clientSecret` starts the SDK for you.
>
> | Option | Default | What it does |
> | - | - | - |
> | `cardLayout` | `COMPACT` | The card entry layout. See the next table. |
> | `defaultStoreForFuture` | `false` | Turns the **Save card for future purchase** switch on by default. |
> | `showResultInline` | `false` | Shows the outcome in the form after a payment. By default the form shows no result: your `onPayResult` handles it. |
> | `scrollableContent` | `false` | Scrolls the form inside its own bounds. Turn it on when the form sits in a fixed-height container. By default the form doesn't scroll, so it fits inside a scrolling parent. |
> | `privacyPolicyUrl` | `null` | Your privacy policy, linked in the form's footer. |
> | `onPrivacyClick` | `null` | Called when the customer taps the privacy link, instead of opening `privacyPolicyUrl`. |
>
> | `cardLayout` | Card entry |
> | - | - |
> | `LiteCardLayout.COMPACT` | A grouped, compact card form. The default. |
> | `LiteCardLayout.FORM` | Separate card number, expiry, CVV and cardholder name fields. |
> | `LiteCardLayout.LINE` | A single condensed row. |
>
> ### Appearance and language
>
> The payment sheet and the embeddable form are in English only and always light, whatever the device's language or dark theme setting, and you can't change their colours or fonts. The secure fields' placeholders and messages are in English too, and the card number, expiry, and CVV always run left to right. To match your app's look, use the secure fields and style them with `LiteFieldStyle`: see step 5. Your app doesn't need an AppCompat or Material theme for them.

> [tab] Flutter
>
> ### Payment sheet (drop-in)
>
> `LitePaymentSheet.present` shows lite's complete checkout and completes when the sheet closes:
>
> ```dart theme={null}
> import 'package:flutter/services.dart'; // PlatformException
>
> try {
>   final result = await LitePaymentSheet.present(
>     clientSecret,
>     configuration: const LitePaymentConfiguration(
>       cardLayout: LiteCardLayout.compact,
>     ),
>   );
>   handle(result);
> } on PlatformException catch (error) {
>   if (error.code == 'already_presenting') return; // A sheet is already on screen.
>   showError('Checkout is unavailable. Try again.');
> }
> ```
>
> `cardLayout` is the only option. The rest is fixed: the sheet keeps its result on screen until the customer closes it, the save-card switch starts off, Apple Pay shows on iOS when the session enables it, and the footer links to lite's privacy policy. Only one sheet can be on screen at a time: a second call throws a `PlatformException` with the code `already_presenting`.
>
> ### Cards: the embeddable payment form
>
> `LitePaymentForm` is lite's card and saved-card checkout, placed inside your screen. It draws its own pay button. Give it a bounded height: the native form scrolls inside it, so keep it out of a parent `ListView`.
>
> ```dart theme={null}
> LitePaymentForm(
>   key: ValueKey<String>(clientSecret),
>   clientSecret: clientSecret,
>   configuration: const LitePaymentConfiguration(
>     cardLayout: LiteCardLayout.compact,
>   ),
>   onPayResult: handle,
> )
> ```
>
> Passing `clientSecret` starts the SDK for you. Key the widget on the session secret, so a new session mounts a new form. The form reports through `onPayResult` only; it does not show a result screen. On iOS it also offers Apple Pay when the session enables it.
>
> | `cardLayout` | Card entry |
> | - | - |
> | `LiteCardLayout.compact` | A grouped, compact card form. The default. |
> | `LiteCardLayout.form` | Separate card number, expiry, CVV and cardholder name fields. |
> | `LiteCardLayout.line` | A single condensed row. |
>
> ### Apple Pay (iOS)
>
> `LiteApplePayButton` is Apple Pay as a standalone button, for a checkout you lay out yourself. It belongs to a started `LiteCheckout`, and reports through `checkout.onPayResult`:
>
> ```dart theme={null}
> checkout.onPayResult = handle;
>
> // In your layout:
> LiteApplePayButton(checkout: checkout, style: LiteApplePayButtonStyle.black)
> ```
>
> The button shows only on iOS, when the session enables Apple Pay and the device can pay with one of its card networks. On Android it takes no space. It's 44 points high, takes the full width, and shows the plain Apple Pay mark. `style` is `black` (the default), `white` or `whiteOutline`. If the customer closes the Apple Pay sheet without paying, nothing is reported.
>
> Apple Pay needs your iOS app to carry the Apple Pay entitlement:
>
> 1. Create your own Apple Pay Merchant ID in your Apple Developer account: an iOS app can't use lite's. Then contact lite to set it on your online terminal and to exchange the payment processing certificate, so lite can decrypt your Apple Pay payments. The dashboard can't do this for business accounts yet.
> 2. In Apple Developer, enable Apple Pay for your app's identifier.
> 3. In Xcode, open the Runner target's **Signing & Capabilities**, add **Apple Pay**, and select that Merchant ID.
> 4. Refresh the provisioning profile so it carries the entitlement.
>
> The Merchant ID must match the session's `merchant_identifier`, and the session must return Apple Pay as `ACTIVE`. The SDK reads both from the session; you don't pass them in Dart. Test Apple Pay on a physical device with a card in Wallet.
>
> ### Appearance and language
>
> The payment sheet, the embeddable form and the secure fields are native views. They're in English only and always light, whatever your app's language or dark mode setting, and the card number, expiry, and CVV always run left to right. You can't change the colours or fonts of the sheet and the form. To match your app's look, use the secure fields and style them with `LiteFieldStyle`: see step 5.

## 5. Secure fields (cards)

> [tab] iOS
>
> Place the secure fields, add your own pay button, and call `lite.pay()`. Start the session first, as in step 3.
>
> ```swift theme={null}
> VStack(spacing: 12) {
>     LiteCardNumberField(lite: lite, onChange: { change in
>         // change.valid, change.brand, change.error, change.focused
>     })
>     LiteExpiryField(lite: lite)
>     LiteCvvField(lite: lite)
>     LiteCardholderNameField(lite: lite)
>
>     Button("Pay") {
>         Task { handle(await lite.pay()) }
>     }
>     .disabled(!lite.isReadyToPay)
> }
> ```
>
> * `lite.isReadyToPay` is `true` when the card is complete, or an enabled saved card is selected.
> * 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. In UIKit, use `LiteCardNumberFieldView`, `LiteExpiryFieldView`, `LiteCvvFieldView` and `LiteCardholderNameFieldView`.
> * `onChange` reports `valid`, `focused`, `brand` and `error` (`invalidNumber`, `invalidExpiry`, `invalidCvv`), with `message` as text to show. It never includes the card data. Cardholder name is optional.
> * A card whose scheme the session doesn't take is not a field error. The payment fails with `PAYMENT_METHOD_NOT_SUPPORTED`, and `lite.isPayLocked` stays `true`, with `lite.payLockMessage` to show, until the card number changes.
> * `lite.pay(storeForFuture: true)` also saves the new card for later payments. Pass it only with the customer's consent.
> * Every field takes a `style`. `LiteFieldStyle` sets the font, the colours (text, placeholder, background, border, error, and focused border), the border width, the corner radius, the padding, and the minimum height. A field is at least 48 points high.
>
> ```swift theme={null}
> let style = LiteFieldStyle(
>     font: .systemFont(ofSize: 16),
>     colors: .init(text: .label, background: .secondarySystemBackground),
>     cornerRadius: 12
> )
>
> LiteCardNumberField(lite: lite, style: style)
> ```

> [tab] Android
>
> Place the secure fields, add your own pay button, and call `lite.pay()`. Start the session and wrap the screen in `LiteHost` first, as in step 3.
>
> ```kotlin theme={null}
> @Composable
> fun CheckoutScreen(lite: Lite) {
>     val canPay by lite.canPay.collectAsState()
>     val scope = rememberCoroutineScope()
>
>     Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
>         LiteCardNumberField(lite, onChange = { change ->
>             // change.valid, change.brand, change.error, change.focused
>         })
>         LiteExpiryField(lite)
>         LiteCvvField(lite)
>         LiteCardholderNameField(lite)
>
>         Button(onClick = { scope.launch { handle(lite.pay()) } }, enabled = canPay) {
>             Text("Pay")
>         }
>     }
> }
> ```
>
> * `lite.canPay` is `true` when the card is complete or an enabled saved card is selected, and no payment is running. Enable your pay button on it, not on `lite.isReadyToPay`, which stays `true` while a payment runs.
> * 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, use `LiteCardNumberFieldView`, `LiteExpiryFieldView`, `LiteCvvFieldView` and `LiteCardholderNameFieldView`.
> * `onChange` reports `valid`, `focused`, `brand` and `error` (`INVALID_NUMBER`, `INVALID_EXPIRY`, `INVALID_CVV`), with `message` as text to show. It never includes the card data. Cardholder name is optional. While a field is on screen, the SDK sets `FLAG_SECURE` on the window.
> * A card whose scheme the session doesn't take is not a field error. The payment fails with `PAYMENT_METHOD_NOT_SUPPORTED`, and `lite.isPayLocked` stays `true`, with `lite.payLockMessage` to show, until the card number changes.
> * `lite.pay(storeForFuture = true)` also saves the new card for later payments. Pass it only with the customer's consent. `lite.launchPay { result -> … }` pays on the `Lite` scope, if you'd rather not launch a coroutine.
> * Every field takes a `style`. `LiteFieldStyle` sets the colours (text, placeholder, background, border, error, and focused border), the typeface, the text size, the border width, the corner radius, the padding, and the minimum height. A field is at least 48 dp high.
>
> ```kotlin theme={null}
> val style = LiteFieldStyle(
>     textColor = 0xFFFFFFFF.toInt(),
>     backgroundColor = 0xFF1E1E1E.toInt(),
>     cornerRadiusDp = 12f,
> )
>
> LiteCardNumberField(lite, style = style)
> ```

> [tab] Flutter
>
> Place the secure fields, add your own pay button, and call `checkout.pay()`. Start the checkout first, as in step 3.
>
> ```dart theme={null}
> ListenableBuilder(
>   listenable: checkout,
>   builder: (context, _) => Column(
>     crossAxisAlignment: CrossAxisAlignment.stretch,
>     children: [
>       LiteCardNumberField(
>         checkout: checkout,
>         onChange: (change) {
>           // change.valid, change.brand, change.error, change.focused, change.message
>         },
>       ),
>       LiteExpiryField(checkout: checkout),
>       LiteCvvField(checkout: checkout),
>       LiteCardholderNameField(checkout: checkout),
>       FilledButton(
>         onPressed: checkout.isReadyToPay ? () async => handle(await checkout.pay()) : null,
>         child: const Text('Pay'),
>       ),
>     ],
>   ),
> )
> ```
>
> * `checkout.isReadyToPay` is `true` when the card is complete, or an enabled saved card is selected, and pay isn't locked.
> * 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.
> * `onChange` reports `valid`, `focused`, `brand` (`visa`, `mastercard`, `mada` or null) and `error` (`invalidNumber`, `invalidExpiry`, `invalidCvv`), with `message` as text to show beside the field. The field doesn't draw `message`, so show it yourself. It never includes the card data.
> * `checkout.onPayResult` also receives the result of `pay()`. If you set it for the Apple Pay button, handle every result there, and just `await checkout.pay()` in your pay button, or you handle each card payment twice.
> * `checkout.getEnabledCardNetworks()` lists the schemes the session takes, for brand logos. A card whose scheme the session doesn't take is not a field error. The payment fails with `PAYMENT_METHOD_NOT_SUPPORTED`, and `checkout.isPayLocked` stays `true`, with `checkout.payLockMessage` to show, until the card number changes.
> * `checkout.pay(storeForFuture: true)` also saves the new card for later payments. Pass it only with the customer's consent.
>
> Each field takes a `style`. A field is at least 48 logical pixels high, grows with the system text size, and takes the width you give it.
>
> ```dart theme={null}
> LiteCardNumberField(
>   checkout: checkout,
>   style: const LiteFieldStyle(cornerRadius: 12, fontSize: 16),
> )
> ```
>
> | `LiteFieldStyle` property | Default |
> | - | - |
> | `textColor` | `Color(0xFF161616)` |
> | `placeholderColor` | `Color(0xFFA2A2A2)` |
> | `backgroundColor` | `Color(0xFFFFFFFF)` |
> | `borderColor` | `Color(0xFFDEDEDE)` |
> | `errorColor` | `Color(0xFFCD0202)` |
> | `focusedBorderColor` | `Color(0xFF6335EA)` |
> | `borderWidth` | `1` |
> | `cornerRadius` | `8` |
> | `horizontalPadding` | `12` |
> | `verticalPadding` | `0` |
> | `minHeight` | `48`. A lower value is raised to 48. |
> | `fontSize` | `17` |
>
> `copyWith` returns a copy with some properties changed.

## 6. Stored instruments

> [tab] iOS
>
> Cards the customer saved before are **stored instruments**. The payment sheet and the embeddable form list them automatically, and offer a **Save card for future purchase** control for a new card.
>
> With the secure fields, list them yourself after `start`:
>
> ```swift theme={null}
> let cards = lite.getStoredInstruments(enabledOnly: true)
>
> ForEach(cards) { card in
>     Button("\(card.display.scheme) •••• \(card.display.last4)") {
>         lite.selectStoredInstrument(card.id)
>     }
> }
> ```
>
> Then call `lite.pay()` as usual, or pay one directly with `lite.pay(instrumentId:)`. `lite.selectNewCard()` returns to the fields. `enabledOnly: true` drops cards whose scheme this session doesn't take.
>
> Stored instruments appear when your server creates the session with the customer's `id` and that customer has cards saved for later payments. A card shows only if its payment method is enabled on the session's terminal.

> [tab] Android
>
> Cards the customer saved before are **stored instruments**. The payment sheet and the embeddable form list them automatically, and offer a **Save card for future purchase** control for a new card.
>
> With the secure fields, list them yourself. `getStoredInstruments` reads the session once, so read it again when `lite.session` changes:
>
> ```kotlin theme={null}
> val session by lite.session.collectAsState()
> val cards = remember(session) { lite.getStoredInstruments(enabledOnly = true) }
>
> cards.forEach { card ->
>     TextButton(onClick = { lite.selectStoredInstrument(card.id) }) {
>         Text("${card.display.scheme} •••• ${card.display.last4}")
>     }
> }
> ```
>
> Then call `lite.pay()` as usual, or pay one directly with `lite.pay(instrumentId)`. `lite.selectNewCard()` returns to the fields. `enabledOnly = true` drops cards whose scheme this session doesn't take.
>
> Stored instruments appear when your server creates the session with the customer's `id` and that customer has cards saved for later payments. A card shows only if its payment method is enabled on the session's terminal.

> [tab] Flutter
>
> Cards the customer saved before are **stored instruments**. The payment sheet and the embeddable form list them automatically, and offer a **Save card for future purchase** switch for a new card. The switch starts off.
>
> With the secure fields, list them yourself after `start()`:
>
> ```dart theme={null}
> for (final card in checkout.getStoredInstruments(enabledOnly: true))
>   ListTile(
>     title: Text(card.title), // e.g. "Visa  •••• 4242"
>     subtitle: Text(card.expiry),
>     onTap: () => checkout.selectStoredInstrument(card.id),
>   ),
> ```
>
> Then call `checkout.pay()` as usual. `selectStoredInstrument` completes with whether the SDK took the card, and `checkout.selectNewCard()` returns to the fields. `enabledOnly: true` drops cards whose scheme this session doesn't take.
>
> Stored instruments appear when your server creates the session with the customer's `id` and that customer has cards saved for later payments. A card shows only if its payment method is enabled on the session's terminal.

## 7. Handle the result

> [tab] iOS
>
> Each payment attempt ends with a `Lite.PayResult`:
>
> ```swift theme={null}
> func handle(_ result: Lite.PayResult) {
>     switch result.status {
>     case .success:
>         // Show success, then confirm result.paymentId on your server.
>         break
>     case .failure:
>         // Show result.error, or your own message when it's nil.
>         break
>     case .processing:
>         // Keep the order pending and confirm it on your server.
>         break
>     case .cancelled:
>         // The customer closed checkout, or the 3D Secure page.
>         break
>     case .alreadyCompleted:
>         // This session was already paid. Don't charge again.
>         break
>     }
> }
> ```
>
> | `status` | Meaning |
> | - | - |
> | `.success` | The payment was authorized or captured. `paymentId` identifies it. |
> | `.failure` | The payment failed or was refused. When the bank declines the card, `error` and `errorCode` are both `nil`: show your own message. `errorCode` is set when lite or the SDK refused the request, for example `PAYMENT_METHOD_NOT_SUPPORTED` or `already_presenting`. |
> | `.processing` | The SDK checked the payment for about 20 seconds, and it hadn't reached a final state. Confirm it from your server: the webhook tells you when it does. |
> | `.cancelled` | The customer closed checkout before paying, or closed the 3D Secure page. In the second case `errorCode` is `THREE_DS_CHALLENGE_DISMISSED` and `paymentId` is set: see below. |
> | `.alreadyCompleted` | The session already had a completed payment. This is not a new payment. |
>
> A second `pay()` while one is running returns the same result, so a double tap pays once. Keep the checkout screen alive until the result arrives.
>
> > [!WARNING]
> >
> > **Confirm on your server.** A success in the app is not enough to fulfil the order: the app can close, lose its connection, or be tampered with. Fulfil from the [webhook](https://docs.lite.sa/guides/create-webhook.md#which-event-means-the-order-is-paid): with the default instant capture, that's `payment.authorized` with `data.status` `CAPTURED`. To show the customer a result straight away, retrieve the checkout session or payment from your server.
>
> ### 3D Secure
>
> 3D Secure is the card issuer's extra check, usually a one-time code. When the issuer asks for it, the SDK opens the issuer's page itself, full screen over your app's top view controller: you add nothing for it, but don't present anything over it. After 10 minutes the SDK closes the page and reports `.failure`.
>
> If the customer closes that page, a payment already exists and waits for 3D Secure. lite fails it 15 minutes after the challenge started, and until then refuses another payment on this session. Before you offer a new attempt, look the payment up from your server with `GET /payments?order_id=<order.reference>`. The payment sheet and the embeddable form stay open and don't call you back. If the customer then closes the sheet, it completes with a plain `.cancelled`, with no `paymentId`. `lite.pay()` returns `.cancelled` with `paymentId`.

> [tab] Android
>
> Every integration ends with a `Lite.PayResult`:
>
> ```kotlin theme={null}
> fun handle(result: Lite.PayResult) {
>     when (result.status) {
>         PaymentOperationStatus.SUCCESS -> {
>             // Show success, then confirm result.paymentId on your server.
>         }
>         PaymentOperationStatus.FAILURE -> {
>             // Show result.error, or your own message when it's null.
>         }
>         PaymentOperationStatus.PROCESSING -> {
>             // Keep the order pending and confirm it on your server.
>         }
>         PaymentOperationStatus.CANCELLED -> {
>             // The customer closed checkout, or the 3D Secure page.
>         }
>         PaymentOperationStatus.ALREADY_COMPLETED -> {
>             // This session was already paid. Don't charge again.
>         }
>     }
> }
> ```
>
> | `status` | Meaning |
> | - | - |
> | `SUCCESS` | The payment was authorized or captured. `paymentId` identifies it. |
> | `FAILURE` | The payment failed or was refused. When the bank declines the card, `error` and `errorCode` are both `null`: show your own message. `errorCode` is set when lite or the SDK refused the request, for example `PAYMENT_METHOD_NOT_SUPPORTED` or `already_presenting`. |
> | `PROCESSING` | The SDK checked the payment for about 20 seconds, and it hadn't reached a final state. Confirm it from your server: the webhook tells you when it does. |
> | `CANCELLED` | The customer closed checkout before paying, or closed the 3D Secure page. In the second case `errorCode` is `THREE_DS_CHALLENGE_DISMISSED` and `paymentId` is set: see below. |
> | `ALREADY_COMPLETED` | The session already had a completed payment. This is not a new payment. |
>
> A second `pay()` while one is running doesn't share its result: it waits for the first to end, then makes its own attempt. Enable your pay button on `lite.canPay`, as in step 5, so a double tap can't pay twice. Keep the Activity and checkout screen alive until the result arrives.
>
> > [!WARNING]
> >
> > **Confirm on your server.** A success in the app is not enough to fulfil the order: the app can close, lose its connection, or be tampered with. Fulfil from the [webhook](https://docs.lite.sa/guides/create-webhook.md#which-event-means-the-order-is-paid): with the default instant capture, that's `payment.authorized` with `data.status` `CAPTURED`. To show the customer a result straight away, retrieve the checkout session or payment from your server.
>
> ### 3D Secure
>
> 3D Secure is the card issuer's extra check, usually a one-time code. When the issuer asks for it, the SDK shows the issuer's page itself, in a full-screen dialog over your Activity: you add no deep link, browser tab or manifest entry for it. It needs `LiteHost` or `lite.attach(activity)`. The payment sheet attaches itself. Without either, a payment that needs 3D Secure ends as `FAILURE` after lite created it. After 10 minutes the SDK closes the page and reports `FAILURE`.
>
> If the customer closes that page, a payment already exists and waits for 3D Secure. lite fails it 15 minutes after the challenge started, and until then refuses another payment on this session. Before you offer a new attempt, look the payment up from your server with `GET /payments?order_id=<order.reference>`. The payment sheet and the embeddable form stay open and don't call you back. If the customer then closes the sheet, it completes with a plain `CANCELLED`, with no `paymentId`. `lite.pay()` returns `CANCELLED` with `paymentId`.

> [tab] Flutter
>
> Every integration ends with a `PayResult`:
>
> ```dart theme={null}
> void handle(PayResult result) {
>   switch (result.status) {
>     case LitePaymentStatus.success:
>       // Show success, then confirm result.paymentId on your server.
>       break;
>     case LitePaymentStatus.failure:
>       // Show result.error, or your own message when it's null.
>       break;
>     case LitePaymentStatus.processing:
>       // Keep the order pending and confirm it on your server.
>       break;
>     case LitePaymentStatus.cancelled:
>       // The customer closed checkout, or the 3D Secure page.
>       break;
>     case LitePaymentStatus.alreadyCompleted:
>       // This session was already paid. Don't charge again.
>       break;
>   }
> }
> ```
>
> | `status` | Meaning |
> | - | - |
> | `success` | The payment was authorized or captured. `paymentId` identifies it. |
> | `failure` | The payment failed or was refused. When the bank declines the card, `error` and `errorCode` are both null: show your own message. `errorCode` is set when lite or the SDK refused the request, for example `PAYMENT_METHOD_NOT_SUPPORTED`. |
> | `processing` | The SDK checked the payment for about 20 seconds, and it hadn't reached a final state. Confirm it from your server: the webhook tells you when it does. |
> | `cancelled` | The customer closed checkout before paying, or closed the 3D Secure page. In the second case `errorCode` is `THREE_DS_CHALLENGE_DISMISSED` and `paymentId` is set: see below. `result.isCancelled` is `true` for both. |
> | `alreadyCompleted` | The session already had a completed payment. This is not a new payment. |
>
> A second `pay()` while one is running returns the same future, so a double tap pays once. Keep the checkout screen in the tree until the result arrives.
>
> > [!WARNING]
> >
> > **Confirm on your server.** A success in the app is not enough to fulfil the order: the app can close, lose its connection, or be tampered with. Fulfil from the [webhook](https://docs.lite.sa/guides/create-webhook.md#which-event-means-the-order-is-paid): with the default instant capture, that's `payment.authorized` with `data.status` `CAPTURED`. To show the customer a result straight away, retrieve the checkout session or payment from your server.
>
> ### 3D Secure
>
> 3D Secure is the card issuer's extra check, usually a one-time code. When the issuer asks for it, the native SDK shows the issuer's page itself, full screen: you add nothing for it. After 10 minutes the SDK closes the page and reports `failure`.
>
> If the customer closes that page, a payment already exists and waits for 3D Secure. lite fails it 15 minutes after the challenge started, and until then refuses another payment on this session. Before you offer a new attempt, look the payment up from your server with `GET /payments?order_id=<order.reference>`. The payment sheet and the embeddable form stay open and don't report it. If the customer then closes the sheet, it completes with a plain `cancelled`, with no `paymentId`. `pay()` reports `cancelled` with `paymentId`.

## 8. Clean up

> [tab] iOS
>
> The payment sheet clears the card when it closes. For the embeddable form, the Apple Pay button or the secure fields, reset the SDK when the customer leaves checkout or you start again with a new session:
>
> ```swift theme={null}
> lite.reset()
> ```
>
> `reset()` cancels a payment in progress and clears the session, the typed card, the selected saved card and the last result.

> [tab] Android
>
> The payment sheet clears the card when it closes. For the embeddable form or the secure fields, reset the SDK when the customer leaves checkout or you start again with a new session:
>
> ```kotlin theme={null}
> lite.reset()
> ```
>
> `reset()` cancels a payment in progress and clears the session, the typed card, the selected saved card and the last result.

> [tab] Flutter
>
> The payment sheet clears the card when it closes.
>
> * **Embeddable form:** remove `LitePaymentForm` from the tree when the customer leaves checkout. That disposes the native checkout and the typed card. For a new session, mount a new form with a new `ValueKey`.
> * **Apple Pay button and secure fields:** dispose the `LiteCheckout` when its screen goes away, usually in your `State.dispose`. A payment still running then completes with a `StateError`. For a new session, create a new `LiteCheckout`.
>
> ```dart theme={null}
> @override
> void dispose() {
>   checkout.dispose();
>   super.dispose();
> }
> ```

## What's new in 0.2.0

> [tab] iOS
>
> * **Apple Pay retries report once.** If the customer tries again in the Apple Pay sheet after a failed attempt, `onResult` gets only the last attempt's result.
> * **Instruments SDK:** saving a card with Apple Pay, and renamed instrument fields. See the [Instruments SDK guide](https://docs.lite.sa/guides/instruments-sdk.md).

> [tab] Android
>
> * **Instruments SDK:** renamed instrument fields. See the [Instruments SDK guide](https://docs.lite.sa/guides/instruments-sdk.md).

> [tab] Flutter
>
> * Wraps the native SDKs 0.2.0.
> * **Apple Pay retries report once.** On iOS, if the customer tries again in the Apple Pay sheet after a failed attempt, `onPayResult` gets only the last attempt's result.
> * **Instruments SDK:** saving a card with Apple Pay on iOS, and renamed instrument fields. See the [Instruments SDK guide](https://docs.lite.sa/guides/instruments-sdk.md).
> * **Upgrading from 0.1.x:** change your constraint to `lite_flutter: ^0.2.0`. On a 0.x version, a caret constraint never moves to the next minor version, so `^0.1.0` stays on 0.1.x.


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