perform Final Selection
Performs the final application selection for contact-based EMV cards and reads all necessary data records from the card.
This method completes the application selection process for contact EMV transactions by finalizing the chosen application and executing all required "Read Record" commands to retrieve application data from the card. The data retrieved includes all records specified in the Application File Locator (AFL)
Prerequisites:
startTransaction must have been called successfully with CardType.CONTACT or CardType.CONTACTLESS result
For multi-application cards: startsContactAppSelection must have completed successfully
Contact card must be properly inserted, powered up, and application selected
Contactless card must be properly close to the antenna to exchange the commands with the terminal
Processing steps:
Final application selection - Confirms and activates the selected application
Read application data - Executes READ RECORD commands for all files/records specified in the Application File Locator (AFL)
Data validation - Performs basic validation of retrieved data records
Kernel preparation - Prepares retrieved data for subsequent EMV processing
Post-conditions:
All required application data is read and available in the kernel
Card is ready for performTransaction processing
Retrieved data can be accessed via getApplicationData
Next step: After successful completion, call getApplicationData to retrieve all data collected from the card
Thread safety: Should be called from a background thread to avoid blocking the UI.
Exceptions: This function MUST NOT throw any exception. Any error must be indicated through NexusRet Any unexpected error must be mapped as NexusRet.INTERR
Return
NexusRet indicating the final selection and data reading result:
NexusRet.OK: Final selection completed and all application data successfully read
NexusRet.INTERR: Internal error during application selection or data reading
NexusRet.CANCEL: User cancelled the transaction process
NexusRet.NOCARD: User removed the contact card
NexusRet.CTLSSONDEVICE: Advice card holder to confirm the transaction on the mobile device
NexusRet.CTLSSIFCHG: Ctls card could not be read resulting in "Change Interface" outcome
NexusRet.CARDAPPNAV: No application compatible with ctls card
NexusRet.CTLSSCOMMERR: Communication error between antenna and ctls card (probably due to moving the card away)
NexusRet.CTLSSMULTIPLE: Multiple cards were tapped at the same time (most likelly to be thrown at EMVPort.startTransaction method)
Other values: Specific selection or read errors as defined by the implementation
Implementation notes:
Method blocks until all required data is read from the card
Card removal during this operation will result in transaction failure
For magnetic stripe cards, this method has no effect and returns immediately
Failed data reading may require complete transaction restart
Example usage:
try {
val cardType = emvPort.startTransaction()
if (cardType == CardType.CONTACT) {
// Handle application selection if needed
val appResult = emvPort.startsContactAppSelection()
if (appResult == NexusRet.OK) {
// Perform final selection and read application data
val finalResult = emvPort.performFinalSelection()
if (finalResult == NexusRet.OK) {
// Application data ready, proceed to transaction processing
val tCardData = emv.getApplicationData()
} else {
// Handle final selection failure
println("Final selection failed: $finalResult")
}
}
}
} catch (e: NexusException) {
// Handle critical final selection error
println("Critical error during final selection: ${e.message}")
}