From c158097d3a9f70d1df0dc2f83035d2f3d30a32b0 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 10 Sep 2024 02:57:12 +0200 Subject: [PATCH] Added tanMethodsNotSupportedByApplication to filter out TAN methods that client application does not support (e.g. chipTanUsb) --- .../net/codinux/banking/fints/FinTsClient.kt | 6 +++--- .../codinux/banking/fints/FinTsClientDeprecated.kt | 2 +- .../net/codinux/banking/fints/FinTsJobExecutor.kt | 11 ++++++----- .../banking/fints/model/AddAccountParameter.kt | 1 + .../net/codinux/banking/fints/model/JobContext.kt | 3 +++ .../banking/fints/model/mapper/ModelMapper.kt | 3 ++- .../banking/fints/util/TanMethodSelector.kt | 14 ++++++++------ .../client/model/parameter/FinTsClientParameter.kt | 1 + .../model/parameter/GetAccountDataParameter.kt | 3 ++- .../model/parameter/TransferMoneyParameter.kt | 3 ++- 10 files changed, 29 insertions(+), 18 deletions(-) diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsClient.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsClient.kt index 66517972..390f257a 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsClient.kt @@ -80,7 +80,7 @@ open class FinTsClient( } protected open suspend fun getAccountTransactions(param: GetAccountDataParameter, bank: BankData, account: AccountData): GetAccountTransactionsResponse { - val context = JobContext(JobContextType.GetTransactions, this.callback, config, bank, account, param.preferredTanMethods, param.preferredTanMedium) + val context = JobContext(JobContextType.GetTransactions, this.callback, config, bank, account, param.preferredTanMethods, param.tanMethodsNotSupportedByApplication, param.preferredTanMedium) return config.jobExecutor.getTransactionsAsync(context, mapper.toGetAccountTransactionsParameter(param, bank, account)) } @@ -138,7 +138,7 @@ open class FinTsClient( accountToUse = selectedAccount } - val context = JobContext(JobContextType.TransferMoney, this.callback, config, bank, accountToUse, param.preferredTanMethods, param.preferredTanMedium) + val context = JobContext(JobContextType.TransferMoney, this.callback, config, bank, accountToUse, param.preferredTanMethods, param.tanMethodsNotSupportedByApplication, param.preferredTanMedium) val response = config.jobExecutor.transferMoneyAsync(context, BankTransferData(param.recipientName, param.recipientAccountIdentifier, recipientBankIdentifier, param.amount, param.reference, param.instantPayment)) @@ -205,7 +205,7 @@ open class FinTsClient( // return GetAccountInfoResponse(it) } - val context = JobContext(JobContextType.GetAccountInfo, this.callback, config, bank, null, param.preferredTanMethods, param.preferredTanMedium) + val context = JobContext(JobContextType.GetAccountInfo, this.callback, config, bank, null, param.preferredTanMethods, param.tanMethodsNotSupportedByApplication, param.preferredTanMedium) /* First dialog: Get user's basic data like BPD, customer system ID and her TAN methods */ diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsClientDeprecated.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsClientDeprecated.kt index e1883c12..f13ed8a6 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsClientDeprecated.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsClientDeprecated.kt @@ -39,7 +39,7 @@ open class FinTsClientDeprecated( open suspend fun addAccountAsync(param: AddAccountParameter): AddAccountResponse { val bank = param.bank - val context = JobContext(JobContextType.AddAccount, this.callback, config, bank, null, param.preferredTanMethods, param.preferredTanMedium) + val context = JobContext(JobContextType.AddAccount, this.callback, config, bank, null, param.preferredTanMethods, param.tanMethodsNotSupportedByApplication, param.preferredTanMedium) /* First dialog: Get user's basic data like BPD, customer system ID and her TAN methods */ diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt index 33ce4df2..0fcc99e1 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/FinTsJobExecutor.kt @@ -145,6 +145,7 @@ open class FinTsJobExecutor( return BankResponse(true, internalError = "Die TAN Verfahren der Bank konnten nicht ermittelt werden") // TODO: translate } else { bank.tanMethodsAvailableForUser = bank.tanMethodsSupportedByBank + .filterNot { context.tanMethodsNotSupportedByApplication.contains(it.type) } val didSelectTanMethod = getUsersTanMethod(context) @@ -714,13 +715,13 @@ Log.info { "Terminating waiting for TAN input" } // TODO: remove again return true } else { - tanMethodSelector.findPreferredTanMethod(bank.tanMethodsAvailableForUser, context.preferredTanMethods)?.let { + tanMethodSelector.findPreferredTanMethod(bank.tanMethodsAvailableForUser, context.preferredTanMethods, context.tanMethodsNotSupportedByApplication)?.let { bank.selectedTanMethod = it return true } // we know user's supported tan methods, now ask user which one to select - val suggestedTanMethod = tanMethodSelector.getSuggestedTanMethod(bank.tanMethodsAvailableForUser) + val suggestedTanMethod = tanMethodSelector.getSuggestedTanMethod(bank.tanMethodsAvailableForUser, context.tanMethodsNotSupportedByApplication) val selectedTanMethod = context.callback.askUserForTanMethod(bank.tanMethodsAvailableForUser, suggestedTanMethod) @@ -741,14 +742,14 @@ Log.info { "Terminating waiting for TAN input" } // TODO: remove again protected open fun updateBankAndCustomerDataIfResponseSuccessful(context: JobContext, response: BankResponse) { if (response.successful) { - updateBankAndCustomerData(context.bank, response) + updateBankAndCustomerData(context.bank, response, context) } } - protected open fun updateBankAndCustomerData(bank: BankData, response: BankResponse) { + protected open fun updateBankAndCustomerData(bank: BankData, response: BankResponse, context: JobContext) { updateBankData(bank, response) - modelMapper.updateCustomerData(bank, response) + modelMapper.updateCustomerData(bank, response, context) } diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/AddAccountParameter.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/AddAccountParameter.kt index b293dca4..ef7a1899 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/AddAccountParameter.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/AddAccountParameter.kt @@ -7,6 +7,7 @@ open class AddAccountParameter @JvmOverloads constructor( open val bank: BankData, open val fetchBalanceAndTransactions: Boolean = true, open val preferredTanMethods: List? = null, + open val tanMethodsNotSupportedByApplication: List? = null, open val preferredTanMedium: String? = null ) { diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/JobContext.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/JobContext.kt index 13d56923..a61ea76b 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/JobContext.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/JobContext.kt @@ -26,6 +26,7 @@ open class JobContext( */ open val account: AccountData? = null, open val preferredTanMethods: List? = null, + tanMethodsNotSupportedByApplication: List? = null, open val preferredTanMedium: String? = null, protected open val messageLogCollector: MessageLogCollector = MessageLogCollector(callback, config.options) ) : MessageBaseData(bank, config.options.product), IMessageLogAppender { @@ -37,6 +38,8 @@ open class JobContext( protected open val _dialogs = mutableListOf() + open val tanMethodsNotSupportedByApplication: List = tanMethodsNotSupportedByApplication ?: emptyList() + open val mt940Parser: IAccountTransactionsParser = Mt940AccountTransactionsParser(Mt940Parser(this), this) open val responseParser: ResponseParser = ResponseParser(logAppender = this) diff --git a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/mapper/ModelMapper.kt b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/mapper/ModelMapper.kt index adaa4cea..c63f5747 100644 --- a/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/mapper/ModelMapper.kt +++ b/fints4k/src/commonMain/kotlin/net/codinux/banking/fints/model/mapper/ModelMapper.kt @@ -63,7 +63,7 @@ open class ModelMapper( } } - open fun updateCustomerData(bank: BankData, response: BankResponse) { + open fun updateCustomerData(bank: BankData, response: BankResponse, context: JobContext) { response.getFirstSegmentById(InstituteSegmentId.BankParameters)?.let { bankParameters -> // TODO: ask user if there is more than one supported language? But it seems that almost all banks only support German. if (bank.selectedLanguage == Dialogsprache.Default && bankParameters.supportedLanguages.isNotEmpty()) { @@ -146,6 +146,7 @@ open class ModelMapper( if (response.supportedTanMethodsForUser.isNotEmpty()) { bank.tanMethodsAvailableForUser = response.supportedTanMethodsForUser.mapNotNull { findTanMethod(it, bank) } + .filterNot { context.tanMethodsNotSupportedByApplication.contains(it.type) } if (bank.tanMethodsAvailableForUser.firstOrNull { it.securityFunction == bank.selectedTanMethod.securityFunction } == null) { // supportedTanMethods don't contain selectedTanMethod anymore bank.resetSelectedTanMethod() 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 7f86198f..fa563220 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 @@ -27,15 +27,17 @@ open class TanMethodSelector { } - open fun getSuggestedTanMethod(tanMethods: List): TanMethod? { - return findPreferredTanMethod(tanMethods, NonVisualOrImageBased) // we use NonVisualOrImageBased as it provides a good default for most users - ?: tanMethods.firstOrNull() + open fun getSuggestedTanMethod(tanMethods: List, tanMethodsNotSupportedByApplication: List = emptyList()): TanMethod? { + return findPreferredTanMethod(tanMethods, NonVisualOrImageBased, tanMethodsNotSupportedByApplication) // we use NonVisualOrImageBased as it provides a good default for most users + ?: tanMethods.firstOrNull { it.type !in tanMethodsNotSupportedByApplication } } - open fun findPreferredTanMethod(tanMethods: List, preferredTanMethods: List?): TanMethod? { + open fun findPreferredTanMethod(tanMethods: List, preferredTanMethods: List?, tanMethodsNotSupportedByApplication: List = emptyList()): TanMethod? { preferredTanMethods?.forEach { preferredTanMethodType -> - tanMethods.firstOrNull { it.type == preferredTanMethodType }?.let { - return it + if (preferredTanMethodType !in tanMethodsNotSupportedByApplication) { + tanMethods.firstOrNull { it.type == preferredTanMethodType }?.let { + return it + } } } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/parameter/FinTsClientParameter.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/parameter/FinTsClientParameter.kt index dd7913d4..88f6e5df 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/parameter/FinTsClientParameter.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/parameter/FinTsClientParameter.kt @@ -12,6 +12,7 @@ open class FinTsClientParameter( password: String, open val preferredTanMethods: List? = null, + open val tanMethodsNotSupportedByApplication: List? = null, open val preferredTanMedium: String? = null, // the ID of the medium open val abortIfTanIsRequired: Boolean = false, open val finTsModel: BankData? = null diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/parameter/GetAccountDataParameter.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/parameter/GetAccountDataParameter.kt index 556396dd..94cf3c49 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/parameter/GetAccountDataParameter.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/parameter/GetAccountDataParameter.kt @@ -21,11 +21,12 @@ open class GetAccountDataParameter( open val retrieveTransactionsTo: LocalDate? = null, preferredTanMethods: List? = null, + tanMethodsNotSupportedByApplication: List? = null, preferredTanMedium: String? = null, abortIfTanIsRequired: Boolean = false, finTsModel: BankData? = null, open val defaultBankValues: BankData? = null -) : FinTsClientParameter(bankCode, loginName, password, preferredTanMethods, preferredTanMedium, abortIfTanIsRequired, finTsModel) { +) : FinTsClientParameter(bankCode, loginName, password, preferredTanMethods, tanMethodsNotSupportedByApplication, preferredTanMedium, abortIfTanIsRequired, finTsModel) { open val retrieveOnlyAccountInfo: Boolean get() = retrieveBalance == false && retrieveTransactions == RetrieveTransactions.No diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/parameter/TransferMoneyParameter.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/parameter/TransferMoneyParameter.kt index 5b8385bf..87ad51ca 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/parameter/TransferMoneyParameter.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/client/model/parameter/TransferMoneyParameter.kt @@ -34,10 +34,11 @@ open class TransferMoneyParameter( open val instantPayment: Boolean = false, preferredTanMethods: List? = null, + tanMethodsNotSupportedByApplication: List? = null, preferredTanMedium: String? = null, abortIfTanIsRequired: Boolean = false, finTsModel: BankData? = null, open val selectAccountToUseForTransfer: ((List) -> AccountData?)? = null // TODO: use BankAccount instead of AccountData -) : FinTsClientParameter(bankCode, loginName, password, preferredTanMethods, preferredTanMedium, abortIfTanIsRequired, finTsModel) \ No newline at end of file +) : FinTsClientParameter(bankCode, loginName, password, preferredTanMethods, tanMethodsNotSupportedByApplication, preferredTanMedium, abortIfTanIsRequired, finTsModel) \ No newline at end of file