PrimerCheckoutSession is the owner of a CheckoutComponents session. You hold it (typically as a @StateObject) and wire it into your SwiftUI view hierarchy with the .primerCheckoutSession(_:theme:onCompletion:) modifier. The session builds the SDK, runs client-token initialization, creates the checkout scope, and bridges per-method scopes into observable session objects that the composable views (such as PrimerCardForm and PrimerPaymentMethods) consume from the environment.
The same session powers both the managed modal PrimerCheckout and fully inline embedding: any Primer composable view placed under the modifier resolves its session from the environment. While the session is .ready, the SDK presents its own follow-up screens (processing, success and failure, plus saved-method management and CVV recapture) in a sheet over your layout. See What the modifier provides.
This is the iOS analog of the Android
PrimerCheckoutHost. Where Android wraps your layout in a composable host, iOS wires the session into the environment with a view modifier — child composable views read their per-feature session from EnvironmentValues.Declaration
Initializer
Phase
The lifecycle phase of the session. Terminal outcomes (success, failure, dismissed) are not delivered here — they are delivered through the modifier’sonCompletion.
Published properties
This is how you read the order the customer is paying for:
Properties
onBeforePaymentCreate uses the BeforePaymentCreateHandler type:onBeforePaymentCreate, the declarative idempotencyKey provider is ignored — use the decision handler to supply the key instead.Methods
formatAmount(_:)
PrimerClientSession.currencyCode alone, because some currencies have none and some have three. The locale is the one in PrimerSettings.localeData, which defaults to the device.
Returns
nil before the session reaches .ready.
View modifier
TheView.primerCheckoutSession(_:theme:onCompletion:) modifier wires a PrimerCheckoutSession into the SwiftUI environment, bootstraps it on appear, and tears it down on disappear. Apply it once around any Primer composable views — whether presented modally via PrimerCheckout or embedded inline in your own layout.
What the modifier provides
- Environment injection — exposes the
PrimerCheckoutSession, the derivedPrimerCardFormSession, and thePrimerSelectionSessionthroughEnvironmentValues, so child views likePrimerCardFormandPrimerPaymentMethodsresolve their per-feature session automatically. - Lifecycle bootstrapping — calls
start()on appear andcancel()on disappear. - Overlay management — once the session is
.ready, the modifier presents the SDK’s own follow-up screens in a sheet over your layout: processing, success and failure after any payment you start, the screens of payment methods that need one, the saved-methods list opened byshowAll()with its delete confirmation, and the CVV recapture screen thatselectVaulted(_:)raises when a saved card needs it. 3DS challenges and web redirects open their own system UI. Do not present a sheet of your own while one of these is up.
Usage
Hold the session as a@StateObject, place the composable views in a ScrollView, and attach the modifier with your completion handler.
PrimerCardFormSession and PrimerSelectionSession, which PrimerCardForm and PrimerPaymentMethods bind to once the session reaches .ready.
Supplying an idempotency key
Provide the declarativeidempotencyKey provider at construction, or assign onBeforePaymentCreate for full control over the payment-creation decision. Either may be assigned after .ready — the change applies to the next payment attempt.
See also
PrimerCheckout
The managed modal entry point powered by the same session.
PrimerCardForm
Composable card form that resolves its session from the environment.
PrimerPaymentMethods
Composable payment-method selection list for inline layouts.
PrimerCheckoutState
The terminal outcome delivered to onCompletion.