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.
You never instantiate
PrimerCardFormSession yourself. Each PrimerCardForm slot
(cardDetails, billingAddress, submitButton) receives the session as a closure parameter.
Observe it with @ObservedObject.Accessing the session
The session is passed to eachPrimerCardForm slot. Capture it and observe state to drive your UI:
@ObservedObject:
Property
Methods
Field update methods
Each setter forwards a raw string to the form. The session re-validates and re-publishesstate
after every update. Updating the card number triggers network detection and may populate
state.availableNetworks and state.binData.
Every setter drives the field the customer sees. The value you set becomes what the field displays,
and the form re-validates it so a prefilled field does not hold back the submit button. The card
number shows formatted, the same way typing it would.
updateCountryCode also resolves the country
picker’s selection from the ISO code. See
Pre-fill cardholder name.
Writes and reads are asymmetric on purpose. updateCardNumber and updateCvv accept a raw value
and show it in the SDK-rendered field, but the card number and CVV are never handed back to your
code: state.data carries a masked card number and an empty CVV.
Network selection
Lifecycle
When wiring custom
TextFields, drive each field with the matching update* method. You can round-trip
through session.state.data for every field except the card number and the CVV: that map is the
merchant-facing state, so the card number reads back masked (424242••••••4242) and the CVV reads
back empty. Binding a custom card-number field to it would feed the mask straight back into the form
on the next keystroke.
PrimerCardFormState
Properties
Convenience properties
Helper methods
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.CardFormConfiguration
CardFormConfiguration.default requires [.cardNumber, .expiryDate, .cvv, .cardholderName]
with no billing fields.
FormData
PrimerInputElementType. Subscript access returns an
empty string for unset fields.
FieldError
PrimerInputElementType
The field identifier used throughoutPrimerCardFormState (in configuration, data, and
fieldErrors).
See also
PrimerCardForm
The card form component and its customizable slots.
Card field components
Prebuilt field views from CardFormDefaults.
ValidationResult
Field validation model and error handling.
PrimerCountry
Country model for billing address selection.