diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/util/TanMethodSelector.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/util/TanMethodSelector.kt index 958e5971..7f86198f 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/util/TanMethodSelector.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/util/TanMethodSelector.kt @@ -12,16 +12,24 @@ open class TanMethodSelector { val ImageBased = listOf(TanMethodType.QrCode, TanMethodType.ChipTanQrCode, TanMethodType.photoTan, TanMethodType.ChipTanPhotoTanMatrixCode) + /** + * NonVisualOrImageBased is a good default for most users as it lists the most simplistic ones (which also work with + * the command line) first and then continues with image based TAN methods, which for UI applications are easily to display. + */ + val NonVisualOrImageBased = buildList { + // decoupled TAN method is the most simplistic TAN method, user only has to confirm the action in her TAN app, no manual TAN entering required + // AppTan is the second most simplistic TAN method: user has to confirm action in her TAN app and then enter the displayed TAN + addAll(listOf(TanMethodType.DecoupledTan, TanMethodType.DecoupledPushTan, TanMethodType.AppTan, TanMethodType.SmsTan, TanMethodType.EnterTan)) + addAll(ImageBased) + addAll(listOf(TanMethodType.ChipTanManuell)) // this is quite inconvenient for user, so i added it as last + } + } open fun getSuggestedTanMethod(tanMethods: List): TanMethod? { - return tanMethods.firstOrNull { it.type == TanMethodType.DecoupledPushTan || it.type == TanMethodType.DecoupledTan } // decoupled TAN method is the most simplistic TAN method, user only has to confirm the action in her TAN app, no manual TAN entering required - ?: tanMethods.firstOrNull { it.type == TanMethodType.AppTan } // that's the second most simplistic TAN method: user has to confirm action in her TAN app and then enter the displayed TAN - ?: tanMethods.firstOrNull { it.type != TanMethodType.ChipTanUsb && it.type != TanMethodType.SmsTan && it.type != TanMethodType.ChipTanManuell } - ?: tanMethods.firstOrNull { it.type != TanMethodType.ChipTanUsb && it.type != TanMethodType.SmsTan } - ?: tanMethods.firstOrNull { it.type != TanMethodType.ChipTanUsb } - ?: first(tanMethods) + return findPreferredTanMethod(tanMethods, NonVisualOrImageBased) // we use NonVisualOrImageBased as it provides a good default for most users + ?: tanMethods.firstOrNull() } open fun findPreferredTanMethod(tanMethods: List, preferredTanMethods: List?): TanMethod? { @@ -34,42 +42,4 @@ open class TanMethodSelector { return null } - - open fun nonVisual(tanMethods: List): TanMethod? { - return findPreferredTanMethod(tanMethods, NonVisual) - ?: tanMethods.firstOrNull { it.displayName.contains("manuell", true) } - } - - open fun nonVisualOrFirst(tanMethods: List): TanMethod? { - return nonVisual(tanMethods) - ?: first(tanMethods) - } - - - open fun imageBased(tanMethods: List): TanMethod? { - return findPreferredTanMethod(tanMethods, ImageBased) - } - - open fun imageBasedOrFirst(tanMethods: List): TanMethod? { - return imageBased(tanMethods) - ?: first(tanMethods) - } - - - open fun nonVisualOrImageBased(tanMethods: List): TanMethod? { - return nonVisual(tanMethods) - ?: imageBased(tanMethods) - } - - open fun nonVisualOrImageBasedOrFirst(tanMethods: List): TanMethod? { - return nonVisual(tanMethods) - ?: imageBased(tanMethods) - ?: first(tanMethods) - } - - - open fun first(tanMethods: List): TanMethod? { - return tanMethods.firstOrNull() - } - } \ No newline at end of file