diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanChallenge.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanChallenge.kt index 1641c2da..3b40a885 100644 --- a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanChallenge.kt +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/tan/TanChallenge.kt @@ -1,7 +1,9 @@ package net.codinux.banking.client.model.tan import net.codinux.banking.client.model.BankAccountViewInfo +import net.codinux.banking.client.model.CustomerAccount import net.codinux.banking.client.model.CustomerAccountViewInfo +import net.codinux.banking.client.model.config.JsonIgnore import net.codinux.banking.client.model.config.NoArgConstructor @NoArgConstructor @@ -9,16 +11,39 @@ open class TanChallenge( val type: TanChallengeType, val forAction: ActionRequiringTan, val messageToShowToUser: String, - val tanMethod: TanMethod, + + /** + * Identifier of selected TanMethod. + * + * As [availableTanMethods] also contains selected TanMethod, we didn't want to duplicate this object. Use + * [selectedTanMethod] to get selected TanMethod or iterate over [availableTanMethods] and filter selected one by this id. + */ + val selectedTanMethodId: String, + /** + * When adding an account, frontend has no Customer object in BankingClientCallback to know which TanMethods are + * available for Customer. + * Also on other calls to bank server, bank server may returned an updated list of available TanMethods, so that + * [CustomerAccount] may contains an outdated list of available TanMethods. + * + * Therefore i added list with up to date TanMethods here to ensure EnterTanDialog can display user's up to date TanMethods. + */ + val availableTanMethods: List, + + // TODO: add available TanMedia - which frontend cannot know when adding an account - and selected TanMedium + val tanImage: TanImage? = null, val flickerCode: FlickerCode? = null, val customer: CustomerAccountViewInfo, val account: BankAccountViewInfo? = null - // TODO: add availableTanMethods, selectedTanMedium, availableTanMedia ) { + @get:JsonIgnore + val selectedTanMethod: TanMethod + get() = availableTanMethods.first { it.identifier == selectedTanMethodId } + + override fun toString(): String { - return "$tanMethod $forAction: $messageToShowToUser" + when (type) { + return "$selectedTanMethod $forAction: $messageToShowToUser" + when (type) { TanChallengeType.EnterTan -> "" TanChallengeType.Image -> ", Image: $tanImage" TanChallengeType.Flickercode -> ", FlickerCode: $flickerCode" diff --git a/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kMapper.kt b/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kMapper.kt index 9089fb32..a9728aa3 100644 --- a/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kMapper.kt +++ b/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kMapper.kt @@ -120,14 +120,17 @@ open class FinTs4kMapper { open fun mapTanChallenge(challenge: net.codinux.banking.fints.model.TanChallenge): TanChallenge { val type = mapTanChallengeType(challenge) val action = mapActionRequiringTan(challenge.forAction) - val tanMethod = mapTanMethod(challenge.tanMethod) + + val tanMethods = challenge.bank.tanMethodsAvailableForUser.map { mapTanMethod(it) } + val selectedTanMethodId = challenge.tanMethod.securityFunction.code + val customer = mapToCustomerAccountViewInfo(challenge.bank) val account = challenge.account?.let { mapToBankAccountViewInfo(it) } val tanImage = if (challenge is ImageTanChallenge) mapTanImage(challenge.image) else null val flickerCode = if (challenge is FlickerCodeTanChallenge) mapFlickerCode(challenge.flickerCode) else null - return TanChallenge(type, action, challenge.messageToShowToUser, tanMethod, tanImage, flickerCode, customer, account) + return TanChallenge(type, action, challenge.messageToShowToUser, selectedTanMethodId, tanMethods, tanImage, flickerCode, customer, account) } protected open fun mapTanChallengeType(challenge: net.codinux.banking.fints.model.TanChallenge): TanChallengeType = when {