From 0b6490f50145a3b12a912f42bf942407f035e9aa Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 15 Oct 2024 01:31:46 +0200 Subject: [PATCH] Added clientData --- .../codinux/banking/client/model/BankAccess.kt | 9 +++++++++ .../client/fints4k/FinTs4kBankingClient.kt | 3 +++ .../banking/client/fints4k/FinTs4kMapper.kt | 15 +++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/BankAccess.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/BankAccess.kt index d3a87c8b..198dda4f 100644 --- a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/BankAccess.kt +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/BankAccess.kt @@ -70,6 +70,15 @@ open class BankAccess( var wrongCredentialsEntered: Boolean = false + /** + * BankingClient specific data of this account that the client needs to fullfil its job. + * + * You should treat it as opaque data, that only makes sense to the BankingClient, and pass it back to the client if set. + * + * For fints4k e.g. contains the FinTS jobs the bank supports, FinTS specific data like KundensystemID and so on. + */ + var clientData: String? = null + @get:JsonIgnore open val displayName: String diff --git a/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kBankingClient.kt b/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kBankingClient.kt index e7f5ee20..a0714d97 100644 --- a/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kBankingClient.kt +++ b/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kBankingClient.kt @@ -49,6 +49,9 @@ open class FinTs4kBankingClient( if (response.finTsModel != null) { finTsModel = response.finTsModel // so that basic account data doesn't have to be retrieved another time if user has multiple accounts } + if (response.serializedFinTsModel != null) { + bank.clientData = response.serializedFinTsModel + } Triple(account, parameter, response) } 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 6fea0a4c..62cfc8ef 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 @@ -30,6 +30,7 @@ import net.codinux.banking.fints.messages.datenelemente.implementierte.tan.TanGe import net.codinux.banking.fints.messages.datenelemente.implementierte.tan.TanMedium import net.codinux.banking.fints.messages.datenelemente.implementierte.tan.TanMediumStatus import net.codinux.banking.fints.model.* +import net.codinux.banking.fints.serialization.FinTsModelSerializer import net.codinux.banking.fints.transactions.swift.model.Holding import net.dankito.banking.banklistcreator.prettifier.BankingGroupMapper import net.dankito.banking.client.model.parameter.TransferMoneyParameter @@ -40,6 +41,8 @@ open class FinTs4kMapper { protected val fintsModelMapper = FinTsModelMapper() + protected val serializer = FinTsModelSerializer() + protected val bankingGroupMapper = BankingGroupMapper() @@ -68,11 +71,13 @@ open class FinTs4kMapper { // val preferredTanMethods = listOf(mapTanMethodType(bank.selectedTanMethod.type)) // TODO: currently we aren't saving TanMethods in database, re-enable as soon as TanMethods get saved val preferredTanMethods = defaults.preferredTanMethods?.map { mapTanMethodType(it) } + val actualFinTsModel = finTsModel ?: bank.clientData?.let { serializer.deserializeFromJson(it) } + return GetAccountDataParameter(bank.domesticBankCode, bank.loginName, bank.password!!, listOf(accountIdentifier), true, retrieveTransactions, from, preferredTanMethods = preferredTanMethods, preferredTanMedium = bank.selectedTanMediumIdentifier, - finTsModel = finTsModel + finTsModel = actualFinTsModel ) } @@ -88,7 +93,7 @@ open class FinTs4kMapper { open fun map(response: net.dankito.banking.client.model.response.GetAccountDataResponse, bank: BankInfo? = null): Response = if (response.successful && response.customerAccount != null) { - Response.success(GetAccountDataResponse(mapBank(response.customerAccount!!, bank))) + Response.success(GetAccountDataResponse(mapBank(response.customerAccount!!, bank, response.serializedFinTsModel))) } else { mapError(response) } @@ -138,7 +143,7 @@ open class FinTs4kMapper { ) - protected open fun mapBank(bank: net.dankito.banking.client.model.CustomerAccount, info: BankInfo? = null) = BankAccess( + protected open fun mapBank(bank: net.dankito.banking.client.model.CustomerAccount, info: BankInfo? = null, clientData: String? = null) = BankAccess( bank.bankCode, bank.loginName, bank.password, info?.name ?: bank.bankName, bank.bic, bank.customerName, bank.userId, bank.accounts.map { mapAccount(it) }.sortedBy { it.type } @@ -150,7 +155,9 @@ open class FinTs4kMapper { info?.bankingGroup ?: getBankingGroup(bank.bankName, bank.bic), bank.finTsServerAddress, "de" - ) + ).apply { + this.clientData = clientData + } protected open fun getBankingGroup(bankName: String, bic: String): BankingGroup? = bankingGroupMapper.getBankingGroup(bankName, bic)