CardNumberTextField
A PCI-compliant XML view component for entering credit/debit card numbers.
This component provides a secure input field for card numbers with automatic formatting and validation. It supports various card number formats (8-19 digits) and automatically detects card types based on BIN (Bank Identification Number).
Features:
PCI-compliant input handling
Automatic card number formatting
BIN detection and card type identification
Real-time validation using Luhn algorithm
Customizable appearance and behavior
Example XML usage:
<com.mercadopago.sdk.android.coremethods.ui.components.textfield.cardnumber.xml.CardNumberTextField
android:id="@+id/cardNumberField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:maxLength="16"
app:readOnly="false"
app:cursorColor="@color/primary" />
Example Kotlin usage:
val cardNumberField = findViewById<CardNumberTextField>(R.id.cardNumberField)
// Configure the field
cardNumberField.maxLength = 16 // For standard credit cards
cardNumberField.textStyle = TextStyle(
color = Color.Black,
fontSize = 16.sp
)
// Handle events
cardNumberField.onEvent = { event ->
when (event) {
is CardNumberTextFieldEvent.OnBinChanged -> {
// Handle BIN change and detect card type
val cardType = detectCardType(event.cardBin)
updateCardIssuerIcon(cardType)
}
is CardNumberTextFieldEvent.IsValid -> {
if (event.isValid) {
// Enable next step
}
}
}
}
Parameters
The context in which the view is running
The attributes of the XML tag that is inflating the view
The default style to apply to this view
Properties
Brush applied to customize the text cursor appearance. Default is unspecified color.
Callbacks for keyboard action events. Use this to handle keyboard actions like "Done" or "Next".
Configuration for the software keyboard. Use this to customize keyboard behavior and appearance.
Callback triggered for field events (BIN changes, validation, input completion). Use this to handle user interactions and update the UI accordingly.
The state holder that manages the card number input value and PCI compliance. This state is automatically initialized when the view is created and persists across configuration changes.
Visual transformation for formatting the card number display. Default is card number mask with spaces between groups.