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 is the root SwiftUI view that renders the entire checkout experience.
Declaration
@available(iOS 15.0, *)
public struct PrimerCheckout: View
Initializer
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 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
PrimerCheckout(clientToken: "your-client-token")
With settings and theme
PrimerCheckout(
clientToken: clientToken,
primerSettings: PrimerSettings(paymentHandling: .auto),
primerTheme: PrimerCheckoutTheme(
colors: ColorOverrides(primerColorBrand: .blue)
)
)
With scope and completion
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:
PrimerCheckoutPresenter.presentCheckout(
clientToken: clientToken,
from: viewController,
primerSettings: PrimerSettings(),
primerTheme: PrimerCheckoutTheme(),
scope: { checkoutScope in
// Same customization as SwiftUI
}
)
See UIKit integration for details.
See also
PrimerCheckoutScope
Top-level scope API
Common objects
PrimerSettings, PrimerCheckoutState, PaymentResult