Skip to main content
Primer Checkout iOS SDK is currently in beta (v3.0.0-beta.8). The API is subject to change before the stable release.
PrimerSelectionSession is the observable session that drives payment-method selection. It publishes the selection state (available methods, current selection and saved-method state) and the customer’s saved vaultedPaymentMethods, and provides the methods that act on them. The SDK raises the CVV recapture screen when a saved card needs one. 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 header and emptyState 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, so you do not initialize it yourself. The header slot of PrimerPaymentMethods and of PrimerVaultedPaymentMethods, and the emptyState slot of PrimerPaymentMethods, receive it directly. The row and submit slots do not receive it. To use the session in those slots, read it with @Environment(\.primerSelectionSession).

Properties

state is the snapshot you render from; vaultedPaymentMethods is the list of saved cards. Which card the SDK’s own screens act on is reflected back through state.selectedVaultedPaymentMethod. Keep the highlight in your own view state.

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()

Ends the checkout, as if the customer dismissed it. The checkout state moves to .dismissed. The onCompletion of .primerCheckoutSession(_:theme:onCompletion:) or PrimerCheckout receives .dismissed once, and nothing is delivered after that. Do not use it as a back or deselect action.

selectVaulted(_:)

Pays with a saved payment method. This is the pay verb, so call it from your pay button rather than from a row tap. A card that needs CVV recapture raises the CVV recapture screen first, and that screen finishes the payment. The outcome arrives through .primerCheckoutSession(_:theme:onCompletion:). Keep which row looks selected in your own view state. Returns immediately; the payment runs on. A call made while state.isVaultPaymentLoading is true does not start another payment. When the payment starts, it first passes through your onBeforePaymentCreate handler, as for every other payment method. If the handler aborts, the session reports a failure through onCompletion.
This method starts a payment. A row tap wired to it will charge the customer.

delete(_:)

Deletes a saved payment method. Once the deletion succeeds, the method leaves vaultedPaymentMethods at once. If it was the selected one, state.selectedVaultedPaymentMethod moves to the first remaining method. The SDK then re-fetches the saved methods. If that re-fetch fails, the deleted method still stays out of the list. Throws if the deletion itself fails, leaving the list unchanged.
Deletion is immediate — there is no confirmation step. Add your own if you want one. (The SDK’s own saved-methods screen, reached via showAll(), does confirm before it deletes.)

showAll()

Presents the SDK’s saved-payment-methods screen: the full list, where the customer can select a different method for payment or delete one. Works in both the managed PrimerCheckout modal and the inline integration.
PrimerVaultedPaymentMethods already wires this into its default header, so you only need to call it directly if you have replaced the header slot or built your own saved-methods UI.

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. The public initializer exists for previews and tests.

Properties

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, iterate vaultedPaymentMethods, keep the highlight in your own view state, and call selectVaulted(_:) from your pay button. A card that needs CVV recapture raises the CVV recapture screen on submit, and that screen finishes the payment.
Never mutate state directly — every property is internal(set). Change selection only through select(_:), selectVaulted(_:), delete(_:), and showAll().

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(_:).