From a9e8e2e96cfc617a9ade801eb7f939c3dc4197c5 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 1 Nov 2021 18:08:28 +0100 Subject: [PATCH] Fixed back mapping TanMethod --- .../banking/mapper/fints4kModelMapper.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt index 4223c1e6..16d48199 100644 --- a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt +++ b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt @@ -388,7 +388,15 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) { } - open fun mapTanMethod(tanMethod: TanMethod): net.dankito.banking.fints.model.TanMethod { + open fun mapTanMethod(tanMethod: TanMethod, bank: BankData): net.dankito.banking.fints.model.TanMethod { + bank.tanMethodsAvailableForUser.firstOrNull { equals(it, tanMethod) }?.let { + return it + } + + bank.tanMethodsSupportedByBank.firstOrNull { equals(it, tanMethod) }?.let { + return it + } + return net.dankito.banking.fints.model.TanMethod( tanMethod.displayName, Sicherheitsfunktion.values().first { it.code == tanMethod.bankInternalMethodCode }, @@ -396,6 +404,7 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) { null, // TODO: where to get HDD Version from? tanMethod.maxTanInputLength, mapAllowedTanFormat(tanMethod.allowedTanFormat) + // TODO: also nameOfTanMediumRequired is missing - which is required for some banks like Postbank ) } @@ -422,9 +431,14 @@ open class fints4kModelMapper(protected val modelCreator: IModelCreator) { } } + private fun equals(tanMethod: net.dankito.banking.fints.model.TanMethod, uiTanMethod: TanMethod): Boolean { + return tanMethod.displayName == uiTanMethod.displayName && tanMethod.securityFunction.code == uiTanMethod.bankInternalMethodCode + } + + open fun mapEnterTanResult(result: EnterTanResult, bank: BankData): net.dankito.banking.fints.model.EnterTanResult { result.changeTanMethodTo?.let { changeTanMethodTo -> - return net.dankito.banking.fints.model.EnterTanResult.userAsksToChangeTanMethod(mapTanMethod(changeTanMethodTo)) + return net.dankito.banking.fints.model.EnterTanResult.userAsksToChangeTanMethod(mapTanMethod(changeTanMethodTo, bank)) } result.changeTanMediumTo?.let { changeTanMediumTo ->