Skip to main content
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

ParameterTypeDefaultDescription
clientTokenStringRequiredA token from the Client Session endpoint that authenticates the session
primerSettingsPrimerSettingsPrimerSettings()SDK behavior configuration
primerThemePrimerCheckoutThemePrimerCheckoutTheme()Design token overrides
scope((PrimerCheckoutScope) -> Void)?nilClosure providing access to the checkout scope for customization and state observation
onCompletion((PrimerCheckoutState) -> Void)?nilCallback 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