From ae77d677078496d5160113d5e14051676fcfc6ac Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 18 Aug 2024 16:41:05 +0200 Subject: [PATCH] Added action for which TAN is required and bank to TanChallenge --- .../net/dankito/banking/fints/FinTsJobExecutor.kt | 10 +++++----- .../banking/fints/model/ActionRequiringTan.kt | 15 +++++++++++++++ .../fints/model/FlickerCodeTanChallenge.kt | 4 +++- .../banking/fints/model/ImageTanChallenge.kt | 4 +++- .../dankito/banking/fints/model/TanChallenge.kt | 2 ++ .../banking/fints/model/mapper/ModelMapper.kt | 11 +++++++++++ fints4k/src/nativeMain/kotlin/NativeApp.kt | 2 +- 7 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/ActionRequiringTan.kt diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt index 64bcbf1e..f6ed968c 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsJobExecutor.kt @@ -377,7 +377,7 @@ open class FinTsJobExecutor( // on all platforms run on Dispatchers.Main, but on iOS skip this (or wrap in withContext(Dispatchers.IO) ) // val enteredTanResult = GlobalScope.async { - val tanChallenge = createTanChallenge(tanResponse, bank) + val tanChallenge = createTanChallenge(tanResponse, modelMapper.mapToActionRequiringTan(context.type), bank) context.callback.enterTan(tanChallenge) @@ -395,7 +395,7 @@ open class FinTsJobExecutor( return handleEnterTanResult(context, enteredTanResult, tanResponse, response) } - protected open fun createTanChallenge(tanResponse: TanResponse, bank: BankData): TanChallenge { + protected open fun createTanChallenge(tanResponse: TanResponse, forAction: ActionRequiringTan, bank: BankData): TanChallenge { // TODO: is this true for all tan methods? val messageToShowToUser = tanResponse.challenge ?: "" val challenge = tanResponse.challengeHHD_UC ?: "" @@ -405,13 +405,13 @@ open class FinTsJobExecutor( TanMethodType.ChipTanFlickercode -> FlickerCodeTanChallenge( FlickerCodeDecoder().decodeChallenge(challenge, tanMethod.hhdVersion ?: HHDVersion.HHD_1_4), // HHD 1.4 is currently the most used version - messageToShowToUser, challenge, tanMethod, tanResponse.tanMediaIdentifier) + forAction, bank, messageToShowToUser, challenge, tanMethod, tanResponse.tanMediaIdentifier) TanMethodType.ChipTanQrCode, TanMethodType.ChipTanPhotoTanMatrixCode, TanMethodType.QrCode, TanMethodType.photoTan -> - ImageTanChallenge(TanImageDecoder().decodeChallenge(challenge), messageToShowToUser, challenge, tanMethod, tanResponse.tanMediaIdentifier) + ImageTanChallenge(TanImageDecoder().decodeChallenge(challenge), forAction, bank, messageToShowToUser, challenge, tanMethod, tanResponse.tanMediaIdentifier) - else -> TanChallenge(messageToShowToUser, challenge, tanMethod, tanResponse.tanMediaIdentifier) + else -> TanChallenge(forAction, bank, messageToShowToUser, challenge, tanMethod, tanResponse.tanMediaIdentifier) } } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/ActionRequiringTan.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/ActionRequiringTan.kt new file mode 100644 index 00000000..96b89ecb --- /dev/null +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/ActionRequiringTan.kt @@ -0,0 +1,15 @@ +package net.dankito.banking.fints.model + +enum class ActionRequiringTan { + GetAnonymousBankInfo, + + GetTanMedia, + + ChangeTanMedium, + + GetAccountInfo, + + GetTransactions, + + TransferMoney +} \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/FlickerCodeTanChallenge.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/FlickerCodeTanChallenge.kt index c463d89b..031c6ba0 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/FlickerCodeTanChallenge.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/FlickerCodeTanChallenge.kt @@ -5,11 +5,13 @@ import net.dankito.banking.fints.tan.FlickerCode open class FlickerCodeTanChallenge( val flickerCode: FlickerCode, + forAction: ActionRequiringTan, + bank: BankData, messageToShowToUser: String, challenge: String, tanMethod: TanMethod, tanMediaIdentifier: String? -) : TanChallenge(messageToShowToUser, challenge, tanMethod, tanMediaIdentifier) { +) : TanChallenge(forAction, bank, messageToShowToUser, challenge, tanMethod, tanMediaIdentifier) { override fun toString(): String { return "$tanMethod (medium: $tanMediaIdentifier) $flickerCode: $messageToShowToUser" diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/ImageTanChallenge.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/ImageTanChallenge.kt index 39140bcb..a1889a56 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/ImageTanChallenge.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/ImageTanChallenge.kt @@ -5,11 +5,13 @@ import net.dankito.banking.fints.tan.TanImage open class ImageTanChallenge( val image: TanImage, + forAction: ActionRequiringTan, + bank: BankData, messageToShowToUser: String, challenge: String, tanMethod: TanMethod, tanMediaIdentifier: String? -) : TanChallenge(messageToShowToUser, challenge, tanMethod, tanMediaIdentifier) { +) : TanChallenge(forAction, bank, messageToShowToUser, challenge, tanMethod, tanMediaIdentifier) { override fun toString(): String { return "$tanMethod (medium: $tanMediaIdentifier) $image: $messageToShowToUser" diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/TanChallenge.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/TanChallenge.kt index 032be286..feb0fe85 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/TanChallenge.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/TanChallenge.kt @@ -5,6 +5,8 @@ import net.dankito.banking.fints.response.client.FinTsClientResponse open class TanChallenge( + val forAction: ActionRequiringTan, + val bank: BankData, val messageToShowToUser: String, val challenge: String, val tanMethod: TanMethod, diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/mapper/ModelMapper.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/mapper/ModelMapper.kt index 5fa3992d..1e1b2623 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/mapper/ModelMapper.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/mapper/ModelMapper.kt @@ -330,4 +330,15 @@ open class ModelMapper( return accountInfo.accountType } + fun mapToActionRequiringTan(type: JobContextType): ActionRequiringTan = when(type) { + JobContextType.AnonymousBankInfo -> ActionRequiringTan.GetAnonymousBankInfo + JobContextType.GetTanMedia -> ActionRequiringTan.GetTanMedia + JobContextType.ChangeTanMedium -> ActionRequiringTan.ChangeTanMedium + JobContextType.GetAccountInfo -> ActionRequiringTan.GetAccountInfo + // TODO: may split actions and create two JobContexts, one for GetAccountInfo and one for GetTransactions + JobContextType.AddAccount -> ActionRequiringTan.GetTransactions + JobContextType.GetTransactions -> ActionRequiringTan.GetTransactions + JobContextType.TransferMoney -> ActionRequiringTan.TransferMoney + } + } \ No newline at end of file diff --git a/fints4k/src/nativeMain/kotlin/NativeApp.kt b/fints4k/src/nativeMain/kotlin/NativeApp.kt index c5be7f38..2ec91aa1 100644 --- a/fints4k/src/nativeMain/kotlin/NativeApp.kt +++ b/fints4k/src/nativeMain/kotlin/NativeApp.kt @@ -84,7 +84,7 @@ class NativeApp { private fun enterTan(tanChallenge: TanChallenge) { - println("A TAN is required:") + println("A TAN is required for ${tanChallenge.forAction}:") println(tanChallenge.messageToShowToUser) println()