Observable card form session: field updates, validation, network selection, and submission
Primer Checkout iOS SDK is currently in beta (v3.0.0-beta.1).
The API is subject to change before the stable release.
PrimerCardFormSession is the observable session for the card payment form. It publishes the current
PrimerCardFormState and exposes field update methods, co-badge network
selection, and submission controls.The session is created by the SDK and injected into every PrimerCardForm
slot closure. Read state to render your UI and call the session’s methods to mutate the form.
@available(iOS 15.0, *)@MainActorpublic final class PrimerCardFormSession: ObservableObject
You never instantiate PrimerCardFormSession yourself. Each PrimerCardForm slot
(cardDetails, billingAddress, submitButton) receives the session as a closure parameter.
Observe it with @ObservedObject.
The latest card form state. @Published private(set) — read-only, observe it through @ObservedObject. Contains field values, validation errors, loading state, network selection, and surcharge information.
Each setter forwards a raw string to the form. The session re-validates and re-publishes state
after every update. Updating the card number triggers network detection and may populate
state.availableNetworks and state.binData.
Method
Description
updateCardNumber(_ value: String)
Updates the card number. Triggers network detection.
updateCvv(_ value: String)
Updates the CVV / security code.
updateExpiryDate(_ value: String)
Updates the expiry date (MM/YY).
updateCardholderName(_ value: String)
Updates the cardholder name.
updatePostalCode(_ value: String)
Updates the billing postal / ZIP code.
updateCountryCode(_ value: String)
Updates the billing country code (ISO 3166-1 alpha-2).
Submits the form for tokenization and payment. Sets state.isLoading to true during submission.
cancel()
Cancels the active card form flow.
When wiring custom TextFields, drive each field with the matching update* method and read
back the current value from session.state.data so the form stays the single source of truth.
The complete state of the card payment form: configuration, current field values, validation errors,
loading and validity flags, co-badge network selection, and surcharge information.
Returns the human-readable error message for the field, or nil when there is none.
PrimerCardForm( cardDetails: { session in VStack(alignment: .leading) { CardFormDefaults.cardNumber(session) if session.state.hasError(for: .cardNumber), let message = session.state.errorMessage(for: .cardNumber) { Text(message).foregroundColor(.red) } } })
Validation errors surface in fieldErrors after the form evaluates a field. Use isValid to
gate the submit button and errorMessage(for:) to display per-field messages. See
ValidationResult.