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

# PrimerCheckout

> API reference for the PrimerCheckout SwiftUI view

`PrimerCheckout` is the root SwiftUI view that renders the entire checkout experience.

## Declaration

```swift theme={"dark"}
@available(iOS 15.0, *)
public struct PrimerCheckout: View
```

## Initializer

```swift theme={"dark"}
PrimerCheckout(
  clientToken: String,
  primerSettings: PrimerSettings = PrimerSettings(),
  primerTheme: PrimerCheckoutTheme = PrimerCheckoutTheme(),
  scope: ((PrimerCheckoutScope) -> Void)? = nil,
  onCompletion: ((PrimerCheckoutState) -> Void)? = nil
)
```

### Parameters

| Parameter        | Type                               | Default                 | Description                                                                                         |
| ---------------- | ---------------------------------- | ----------------------- | --------------------------------------------------------------------------------------------------- |
| `clientToken`    | `String`                           | Required                | A token from the [Client Session endpoint](/checkout/client-session) that authenticates the session |
| `primerSettings` | `PrimerSettings`                   | `PrimerSettings()`      | SDK behavior configuration                                                                          |
| `primerTheme`    | `PrimerCheckoutTheme`              | `PrimerCheckoutTheme()` | Design token overrides                                                                              |
| `scope`          | `((PrimerCheckoutScope) -> Void)?` | `nil`                   | Closure providing access to the checkout scope for customization and state observation              |
| `onCompletion`   | `((PrimerCheckoutState) -> Void)?` | `nil`                   | Callback invoked when the checkout reaches a terminal state                                         |

## Usage

### Minimal

```swift theme={"dark"}
PrimerCheckout(clientToken: "your-client-token")
```

### With settings and theme

```swift theme={"dark"}
PrimerCheckout(
  clientToken: clientToken,
  primerSettings: PrimerSettings(paymentHandling: .auto),
  primerTheme: PrimerCheckoutTheme(
    colors: ColorOverrides(primerColorBrand: .blue)
  )
)
```

### With scope and completion

```swift theme={"dark"}
PrimerCheckout(
  clientToken: clientToken,
  scope: { checkoutScope in
    // Customize UI
    checkoutScope.splashScreen = { AnyView(MyLoadingView()) }

    // Observe state
    Task {
      for await state in checkoutScope.state {
        print("State: \(state)")
      }
    }
  },
  onCompletion: { state in
    switch state {
    case .success(let result):
      print("Payment succeeded: \(result.payment?.id ?? "")")
    case .failure(let error):
      print("Payment failed: \(error.errorId)")
    case .dismissed:
      print("Dismissed")
    default:
      break
    }
  }
)
```

## UIKit support

For UIKit-based apps, use `PrimerCheckoutPresenter`:

```swift theme={"dark"}
PrimerCheckoutPresenter.presentCheckout(
  clientToken: clientToken,
  from: viewController,
  primerSettings: PrimerSettings(),
  primerTheme: PrimerCheckoutTheme(),
  scope: { checkoutScope in
    // Same customization as SwiftUI
  }
)
```

See [UIKit integration](/sdk/ios-checkout/v3.0.0-beta/integration-patterns/uikit-integration) for details.

## See also

<CardGroup cols={2}>
  <Card title="PrimerCheckoutScope" icon="book" href="/sdk/ios-checkout/v3.0.0-beta/api-reference/primer-checkout-scope">
    Top-level scope API
  </Card>

  <Card title="Common objects" icon="cube" href="/sdk/ios-checkout/v3.0.0-beta/api-reference/common-objects">
    PrimerSettings, PrimerCheckoutState, PaymentResult
  </Card>
</CardGroup>
