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 and the session republishesstate. The setters do
not validate. Validation runs in the SDK-rendered field for that type, a CardFormDefaults field or
a default slot body, while it is on screen. The SDK never validates a field you render yourself, so
setter calls alone never make state.isValid true. Updating the card number triggers network
detection and may populate state.availableNetworks and state.binData.
Every setter drives the SDK-rendered field the customer sees. The value you set becomes what that
field displays. When that field is on screen, the form re-validates the value, so a prefilled field
does not hold back the submit button. While the field has focus, the customer’s typing wins and the
setter does not change the visible text. 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
Saving the card
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.
The SDK validates only the fields it renders. When you replace a card field with your own,
state.isValid stays false and the default submit button stays disabled. Validate your fields
yourself and provide your own submitButton. Pass the expiry date to updateExpiryDate as MM/YY.
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.