Skip to main content
Primer Checkout iOS SDK is currently in beta (v3.0.0-beta.1). The API is subject to change before the stable release.
PrimerSelectionSession is the observable session that drives payment-method selection. It exposes the available methods, the current selection, search and filtering state, and vaulted-card actions (including CVV recapture) as a single @Published state value, and provides the methods that mutate that state. A single PrimerSelectionSession backs both PrimerPaymentMethods (the list of available methods) and PrimerVaultedPaymentMethods (saved methods). Both views resolve the same session from the environment supplied by the .primerCheckoutSession(_:) modifier, so you rarely construct or hold it yourself — you read it from the slots those views hand you.
PrimerSelectionSession is a @MainActor, ObservableObject final class available on iOS 15.0 and later (@available(iOS 15.0, *)). Observe it with @ObservedObject and call its methods from the main actor.

Declaration

The session is created and injected by the SDK. The slots of PrimerPaymentMethods and PrimerVaultedPaymentMethods receive it directly, so you do not initialize it yourself.

Properties

state is the snapshot you render from; vaultedPaymentMethods is the raw list of saved cards. Selection of a vaulted method is reflected back through state.selectedVaultedPaymentMethod.

Methods

select(_:)

Selects a payment method to begin its payment flow. Call this from a method row’s tap handler. The selected method is reflected in state.selectedPaymentMethod.

cancel()

Cancels the in-progress selection flow.

selectVaulted(_:)

Marks a saved payment method as selected. The selection is reflected in state.selectedVaultedPaymentMethod; a subsequent submit pays with this method. If the card requires CVV recapture, state.requiresCvvInput becomes true.

delete(_:)

Routes to the delete-confirmation screen for a saved payment method.

showAll()

Navigates to the full list of saved payment methods (the “show all saved methods” action).

updateCvvInput(_:)

Updates and validates the CVV entered for the selected vaulted card during CVV recapture. The result is published through state.cvvInput, state.isCvvValid, and state.cvvError.

PrimerPaymentMethodSelectionState

PrimerPaymentMethodSelectionState is the immutable snapshot published by state. It conforms to Equatable. Every stored property is public internal(set) — readable from your code but mutated only by the SDK, so treat it as read-only and call the session’s methods to change selection.

Properties

Because the state is Equatable, SwiftUI only re-renders observers when a meaningful field changes. Drive your custom rows and empty states directly from these properties rather than caching copies.

CheckoutPaymentMethod

paymentMethods and filteredPaymentMethods are arrays of CheckoutPaymentMethod, the model describing a single selectable method. It is documented in full on the PrimerPaymentMethods page; the key fields are id, type, name, icon, and the surcharge and styling properties.

Usage

Reading state and selecting a method

PrimerPaymentMethods hands each method slot a CheckoutPaymentMethod and an onSelect closure that calls select(_:) for you. To select outside a slot — for example from a custom header — call select(_:) on the session directly.

Working with vaulted methods and CVV recapture

When rendering saved methods, drive the UI from state and call the vaulted helpers on the session. If the selected card requires CVV recapture, state.requiresCvvInput is true; feed your CVV field through updateCvvInput(_:) and read state.isCvvValid / state.cvvError for validation feedback.
Never mutate state directly — every property is internal(set). Change selection only through select(_:), selectVaulted(_:), delete(_:), showAll(), updateCvvInput(_:), and cancel().

See also

PrimerPaymentMethods

The slot-based view that renders the available payment methods.

PrimerVaultedPaymentMethods

Render and select saved (vaulted) payment methods.

PaymentMethodsDefaults

Default slot bodies used by the payment-method views.

PrimerCheckoutSession

The top-level session injected via .primerCheckoutSession(_:).