checkout.addEventListener('primer:bin-data-available', (event) => { const { preferred, status } = event.detail; if (preferred) { document.getElementById('card-logo').src = `/images/${preferred.network.toLowerCase()}.svg`; }});
Copy
Ask AI
val controller = rememberCardFormController(checkout)val state by controller.state.collectAsStateWithLifecycle()val detected = state.networkSelection.selectedNetworkif (detected != null) { Text(text = detected.displayName)}
PrimerCardForm displays the card brand icon automatically in the card number field. Custom rendering is optional — use state.networkSelection only if you need to display the network outside the card form.
Copy
Ask AI
struct CardFormWithNetwork: View { let scope: any PrimerCardFormScope @State private var selectedNetwork: PrimerCardNetwork? var body: some View { HStack { scope.PrimerCardNumberField(label: "Card number", styling: nil) if let network = selectedNetwork { Text(network.rawValue) .font(.caption) .padding(4) .background(Color(.secondarySystemBackground)) .cornerRadius(4) } } .task { for await state in scope.state { selectedNetwork = state.selectedNetwork } } }}
The card form fields handle network detection automatically. Use state.selectedNetwork only if you need to display the network outside the card form.
Use preferred.network to get the card brand identifier
Update your UI with the appropriate logo or icon
Create a PrimerCardFormController using rememberCardFormController()
Observe its state with collectAsStateWithLifecycle()
Read state.networkSelection.selectedNetwork for the currently detected network
The state updates reactively as the user types — no event listener needed
Property
Type
Description
selectedNetwork
PrimerCardNetwork?
Currently detected network, or null
availableNetworks
List<PrimerCardNetwork>
All selectable networks (for co-badged cards)
isNetworkSelectable
Boolean
true when the card has multiple networks
Observe scope.state using for await in a .task modifier
Read state.selectedNetwork for the currently detected network
Read state.availableNetworks for all selectable networks (co-badged cards)
The state updates reactively as the user types
Property
Type
Description
selectedNetwork
PrimerCardNetwork?
Currently detected network, or nil
availableNetworks
[PrimerCardNetwork]
All selectable networks (for co-badged cards)
The preferred field contains the recommended card network based on orderedAllowedCardNetworks. It is undefined when no network is detected (e.g., empty input or insufficient digits).
The preferred object contains the detected card network and, when status is 'complete', additional issuer details:
Copy
Ask AI
{ displayName: string; // Human-readable name (e.g., "Visa", "American Express") network: string; // Backend identifier (e.g., "VISA", "AMEX") allowed: boolean; // Whether the network is allowed per orderedAllowedCardNetworks // Available when status is 'complete': issuerCountryCode?: string; issuerName?: string; accountFundingType?: string;}
See the Events Reference for the full BinDataDetails type definition.
Copy
Ask AI
data class PrimerCardNetwork( val network: CardNetwork.Type, val displayName: String, val allowed: Boolean,)
selectedNetwork is null when no card network is detected. Android uses the CardNetwork.Type enum with a displayName property.
val controller = rememberCardFormController(checkout)val state by controller.state.collectAsStateWithLifecycle()val networkName = state.networkSelection.selectedNetwork?.displayName ?: "Card"Text(text = "Paying with $networkName")
Copy
Ask AI
if let network = selectedNetwork { Text("Paying with \(network.rawValue)")} else { Text("Paying with Card")}
PrimerCardForm renders a dropdown selector for co-badged cards automatically. Use selectCardNetwork() only if building a fully custom card form.
When a card supports multiple networks, availableNetworks contains all options. Use the cobadgedCardsView property to provide a custom network selector: