PrimerCardForm is a SwiftUI View that renders a complete card payment form, composed from three section slots: card details, billing address, and submit button. Each section is a @ViewBuilder slot you can replace.
The form resolves its PrimerCardFormSession from the environment. The .primerCheckoutSession(_:theme:onCompletion:) modifier provides it, so you can embed the form anywhere in your own SwiftUI layout. The modal PrimerCheckout renders its own card screen and does not take composable views.
Requires iOS 15.0+.
PrimerCardForm is @available(iOS 15.0, *).Signature
Parameters
Each slot receives the active
PrimerCardFormSession, which exposes the published state and the field-update and submit() methods you need to drive custom UI.
Every slot is generic and defaults to a
CardFormDefaults builder. Because the defaults are supplied per-parameter, you can override any single slot and leave the rest at their default styling — you never have to re-implement the whole form.Default layout
The default form stacks the three slots vertically:
When no card-form session is available, the form renders
CardFormDefaults.unavailable() (an empty view) instead. This happens when the .primerCheckoutSession(_:theme:onCompletion:) modifier is missing, or when the checkout session is still initializing (its phase is not yet .ready). It also happens when the checkout session has no card payment method.
While a payment is processing, the default submit button and the input fields rendered by CardFormDefaults are disabled automatically. This covers the cardDetails and billingAddress sections and the per-field builders, except cardNetwork(_:). The cardNetwork(_:) selector and views of your own inside a slot stay enabled, so disable them with session.state.isLoading.
Usage
Default form
Render the fully styled default card form with no arguments:Overriding a single slot
To customize one section, pass a labeled argument and leave the others at their defaults. Here only the submit button is replaced —cardDetails and billingAddress keep the default styling:
Recomposing the card section from building blocks
You don’t have to discard the default fields when customizing a slot. Compose the default content with your own views using the per-field builders onCardFormDefaults:
CardFormDefaults.cardNumber, expiryDate, cvv, and cardholderName:
See also
PrimerCardFormSession
State, field-update methods, and
submit() passed into every slot.CardFormDefaults
Default section and field builders used by each slot.
Card field components
Individual field building blocks for recomposing the card section.
PrimerPaymentMethods
Render the list of available payment methods alongside the card form.