From aa7b7afaf07d6cbb65df802a17326ec66b1a4ff6 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 9 Sep 2024 23:01:57 +0200 Subject: [PATCH] Passing known bank data on to FinTsClient as e.g. bank names returned from bank server are often quite bad, e.g. DB24 for Deutsche Bank --- .../client/fints4k/FinTs4kBankingClient.kt | 2 +- .../banking/client/fints4k/FinTs4kMapper.kt | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) 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 94634174..4d0acbed 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 @@ -29,7 +29,7 @@ open class FinTs4kBankingClient( override suspend fun getAccountDataAsync(request: GetAccountDataRequest): Response { val response = client.getAccountDataAsync(mapper.mapToGetAccountDataParameter(request, request.options ?: GetAccountDataOptions())) - return mapper.map(response) + return mapper.map(response, request.bankInfo) } override suspend fun updateAccountTransactionsAsync(user: User, accounts: List?): 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 fbbb50f7..cbe63316 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 @@ -8,6 +8,7 @@ import net.codinux.banking.client.model.AccountTransaction import net.codinux.banking.client.model.Amount import net.codinux.banking.client.model.tan.* import net.codinux.banking.client.model.options.GetAccountDataOptions +import net.codinux.banking.client.model.request.GetAccountDataRequest import net.codinux.banking.client.model.request.TransferMoneyRequestForUser import net.codinux.banking.client.model.response.* import net.codinux.banking.client.model.tan.ActionRequiringTan @@ -38,13 +39,19 @@ open class FinTs4kMapper { protected val bankingGroupMapper = BankingGroupMapper() - open fun mapToGetAccountDataParameter(credentials: AccountCredentials, options: GetAccountDataOptions) = GetAccountDataParameter( - credentials.bankCode, credentials.loginName, credentials.password, + open fun mapToGetAccountDataParameter(request: GetAccountDataRequest, options: GetAccountDataOptions) = GetAccountDataParameter( + request.bankCode, request.loginName, request.password, options.accounts.map { mapBankAccountIdentifier(it) }, options.retrieveBalance, RetrieveTransactions.valueOf(options.retrieveTransactions.name), options.retrieveTransactionsFrom, options.retrieveTransactionsTo, preferredTanMethods = options.preferredTanMethods?.map { mapTanMethodType(it) }, - abortIfTanIsRequired = options.abortIfTanIsRequired + abortIfTanIsRequired = options.abortIfTanIsRequired, + defaultBankValues = request.bankInfo?.let { mapToBankData(request, it) } + ) + + protected open fun mapToBankData(credentials: AccountCredentials, bank: BankInfo): BankData = BankData( + credentials.bankCode, credentials.loginName, credentials.password, + bank.serverAddress, bank.bic, bank.name ) open fun mapToUpdateAccountTransactionsParameter(user: User, account: BankAccount, finTsModel: BankData?): GetAccountDataParameter { @@ -71,9 +78,9 @@ open class FinTs4kMapper { net.codinux.banking.fints.model.TanMethodType.valueOf(type.name) - open fun map(response: net.dankito.banking.client.model.response.GetAccountDataResponse): Response = + open fun map(response: net.dankito.banking.client.model.response.GetAccountDataResponse, bank: BankInfo? = null): Response = if (response.successful && response.customerAccount != null) { - Response.success(GetAccountDataResponse(mapUser(response.customerAccount!!))) + Response.success(GetAccountDataResponse(mapUser(response.customerAccount!!, bank))) } else { mapError(response) } @@ -119,16 +126,16 @@ open class FinTs4kMapper { ) - protected open fun mapUser(user: net.dankito.banking.client.model.CustomerAccount) = User( + protected open fun mapUser(user: net.dankito.banking.client.model.CustomerAccount, bank: BankInfo? = null) = User( user.bankCode, user.loginName, user.password, - user.bankName, user.bic, user.customerName, user.userId, + bank?.name ?: user.bankName, user.bic, user.customerName, user.userId, user.accounts.map { mapAccount(it) }.sortedBy { it.type } .onEachIndexed { index, bankAccount -> bankAccount.displayIndex = index }, user.selectedTanMethod?.securityFunction?.code, user.tanMethods.map { mapTanMethod(it) }, user.selectedTanMedium?.mediumName, user.tanMedia.map { mapTanMedium(it) }, - getBankingGroup(user.bankName, user.bic), + bank?.bankingGroup ?: getBankingGroup(user.bankName, user.bic), user.finTsServerAddress )