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

This commit is contained in:
dankito 2024-09-09 23:01:57 +02:00
parent 73b760ae68
commit aa7b7afaf0
2 changed files with 16 additions and 9 deletions

View File

@ -29,7 +29,7 @@ open class FinTs4kBankingClient(
override suspend fun getAccountDataAsync(request: GetAccountDataRequest): Response<GetAccountDataResponse> { override suspend fun getAccountDataAsync(request: GetAccountDataRequest): Response<GetAccountDataResponse> {
val response = client.getAccountDataAsync(mapper.mapToGetAccountDataParameter(request, request.options ?: GetAccountDataOptions())) 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<BankAccount>?): Response<List<GetTransactionsResponse>> { override suspend fun updateAccountTransactionsAsync(user: User, accounts: List<BankAccount>?): Response<List<GetTransactionsResponse>> {

View File

@ -8,6 +8,7 @@ import net.codinux.banking.client.model.AccountTransaction
import net.codinux.banking.client.model.Amount import net.codinux.banking.client.model.Amount
import net.codinux.banking.client.model.tan.* import net.codinux.banking.client.model.tan.*
import net.codinux.banking.client.model.options.GetAccountDataOptions 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.request.TransferMoneyRequestForUser
import net.codinux.banking.client.model.response.* import net.codinux.banking.client.model.response.*
import net.codinux.banking.client.model.tan.ActionRequiringTan import net.codinux.banking.client.model.tan.ActionRequiringTan
@ -38,13 +39,19 @@ open class FinTs4kMapper {
protected val bankingGroupMapper = BankingGroupMapper() protected val bankingGroupMapper = BankingGroupMapper()
open fun mapToGetAccountDataParameter(credentials: AccountCredentials, options: GetAccountDataOptions) = GetAccountDataParameter( open fun mapToGetAccountDataParameter(request: GetAccountDataRequest, options: GetAccountDataOptions) = GetAccountDataParameter(
credentials.bankCode, credentials.loginName, credentials.password, request.bankCode, request.loginName, request.password,
options.accounts.map { mapBankAccountIdentifier(it) }, options.accounts.map { mapBankAccountIdentifier(it) },
options.retrieveBalance, options.retrieveBalance,
RetrieveTransactions.valueOf(options.retrieveTransactions.name), options.retrieveTransactionsFrom, options.retrieveTransactionsTo, RetrieveTransactions.valueOf(options.retrieveTransactions.name), options.retrieveTransactionsFrom, options.retrieveTransactionsTo,
preferredTanMethods = options.preferredTanMethods?.map { mapTanMethodType(it) }, 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 { 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) net.codinux.banking.fints.model.TanMethodType.valueOf(type.name)
open fun map(response: net.dankito.banking.client.model.response.GetAccountDataResponse): Response<GetAccountDataResponse> = open fun map(response: net.dankito.banking.client.model.response.GetAccountDataResponse, bank: BankInfo? = null): Response<GetAccountDataResponse> =
if (response.successful && response.customerAccount != null) { if (response.successful && response.customerAccount != null) {
Response.success(GetAccountDataResponse(mapUser(response.customerAccount!!))) Response.success(GetAccountDataResponse(mapUser(response.customerAccount!!, bank)))
} else { } else {
mapError(response) 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.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 } user.accounts.map { mapAccount(it) }.sortedBy { it.type }
.onEachIndexed { index, bankAccount -> bankAccount.displayIndex = index }, .onEachIndexed { index, bankAccount -> bankAccount.displayIndex = index },
user.selectedTanMethod?.securityFunction?.code, user.tanMethods.map { mapTanMethod(it) }, user.selectedTanMethod?.securityFunction?.code, user.tanMethods.map { mapTanMethod(it) },
user.selectedTanMedium?.mediumName, user.tanMedia.map { mapTanMedium(it) }, user.selectedTanMedium?.mediumName, user.tanMedia.map { mapTanMedium(it) },
getBankingGroup(user.bankName, user.bic), bank?.bankingGroup ?: getBankingGroup(user.bankName, user.bic),
user.finTsServerAddress user.finTsServerAddress
) )