Skip to main content
Primer Checkout Android SDK is currently in beta (v3.0.0-beta.2). The API is subject to change before the stable release.
Controller interface for the card payment form. Exposes observable state, field update methods, and submission actions.

Creation

@Composable
fun rememberCardFormController(
    checkout: PrimerCheckoutController,
): PrimerCardFormController
ParameterTypeDescription
checkoutPrimerCheckoutControllerCheckout controller from rememberPrimerCheckoutController()
Must be called inside PrimerCheckoutHost content or a PrimerCheckoutSheet slot.

Property

PropertyTypeDescription
stateStateFlow<State>Observable state containing field values, validation errors, loading state, and form configuration

Methods

Field update methods

MethodParameterDescription
updateCardNumber(value: String)Raw card numberUpdates card number. Triggers network detection.
updateCvv(value: String)CVV digitsUpdates CVV field
updateExpiryDate(value: String)Raw expiry inputUpdates expiry date. Auto-formats to MM/YY.
updateCardholderName(value: String)Full nameUpdates cardholder name
updatePostalCode(value: String)Postal/ZIP codeUpdates billing postal code
updateCountryCode(value: String)ISO country codeUpdates billing country code
updateCity(value: String)City nameUpdates billing city
updateState(value: String)State/regionUpdates billing state
updateAddressLine1(value: String)Street addressUpdates billing address line 1
updateAddressLine2(value: String)Apt, suite, etc.Updates billing address line 2
updatePhoneNumber(value: String)Phone numberUpdates billing phone number
updateFirstName(value: String)First nameUpdates billing first name
updateLastName(value: String)Last nameUpdates billing last name

Action methods

MethodDescription
submit()Submits the form for tokenization and payment. Sets state.isLoading to true during submission.
selectCardNetwork(network: PrimerCardNetwork)Selects a network for co-badged cards. Only applicable when state.networkSelection has multiple networks.
onFieldFocusChange(type: PrimerInputElementType, hasFocus: Boolean)Notifies controller of field focus changes. Triggers on-blur validation.
requestCountrySelection()Opens the country selection picker UI
setVaultOnSuccess(vault: Boolean)Configures whether to save the payment method to vault after success. Requires customerId in session.

State

data class State(
    val cardFields: List<PrimerInputElementType>,
    val billingFields: List<PrimerInputElementType>,
    val fieldErrors: List<SyncValidationError>?,
    val data: Map<PrimerInputElementType, String>,
    val isLoading: Boolean,
    val isFormEnabled: Boolean,
    val selectedCountry: PrimerCountry?,
    val networkSelection: NetworkSelection?,
    val fieldFocusStates: Map<PrimerInputElementType, FieldState>,
    val isFormValid: Boolean,
    val vaultOnSuccess: Boolean,
)
PropertyTypeDescription
cardFieldsList<PrimerInputElementType>Card input fields required by the session
billingFieldsList<PrimerInputElementType>Billing address fields required by the session. Empty if not required.
fieldErrorsList<SyncValidationError>?Validation errors per field. null before first validation. See Validation.
dataMap<PrimerInputElementType, String>Current field values keyed by input element type
isLoadingBooleantrue while submitting a payment
isFormEnabledBooleantrue when the form accepts input. false during submission.
selectedCountryPrimerCountry?Selected billing country, or null
networkSelectionNetworkSelection?Co-badge network selection data. null when card is not co-badged.
fieldFocusStatesMap<PrimerInputElementType, FieldState>Focus state per field. FieldState contains hasFocus, hasBeenFocused, and shouldShowError.
isFormValidBooleantrue when all required fields pass validation. Updates in real-time.
vaultOnSuccessBooleanWhether payment method will be saved to vault on success

NetworkSelection

data class NetworkSelection(
    val availableNetworks: List<PrimerCardNetwork>,
    val selectedNetwork: PrimerCardNetwork?,
)
PropertyTypeDescription
availableNetworksList<PrimerCardNetwork>Card networks available for this card
selectedNetworkPrimerCardNetwork?Currently selected network, or null

PrimerInputElementType

ValueField
CARD_NUMBERCard number
EXPIRY_DATEExpiry date (MM/YY)
CVVCVV / security code
CARDHOLDER_NAMECardholder name
POSTAL_CODEBilling postal code
COUNTRY_CODEBilling country
CITYBilling city
STATEBilling state/region
ADDRESS_LINE_1Billing address line 1
ADDRESS_LINE_2Billing address line 2
PHONE_NUMBERBilling phone number
FIRST_NAMEBilling first name
LAST_NAMEBilling last name

SyncValidationError

class SyncValidationError {
    val inputElementType: PrimerInputElementType
    val errorId: String
    val fieldId: Int
    val errorResId: Int?
    val errorFormatId: Int?
}
PropertyTypeDescription
inputElementTypePrimerInputElementTypeField that has the error
errorIdStringError identifier describing the validation failure
fieldIdIntField identifier
errorResIdInt?Android string resource ID for the error message
errorFormatIdInt?Android string resource ID for the error format
See Validation for details.

FieldState

data class FieldState(
    val hasFocus: Boolean,
    val hasBeenFocused: Boolean,
    val shouldShowError: Boolean,
)
PropertyTypeDescription
hasFocusBooleanWhether the field currently has focus
hasBeenFocusedBooleanWhether the field has been focused at least once
shouldShowErrorBooleanWhether the field should display its validation error
Validation errors appear on blur (when the user leaves a field), not while typing. Use isFormValid for submit button state and fieldErrors for error messages.