From a59b33531609055acb08ecf1a7a1f4435148a2f5 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 22 Sep 2020 01:18:27 +0200 Subject: [PATCH] If account type field is not set (as it e.g. comdirect does), trying to extract account type from account name --- .../net/dankito/banking/fints/FinTsClient.kt | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt index a45fdd65..ea879071 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt @@ -1049,7 +1049,7 @@ open class FinTsClient( ?: run { val newAccount = AccountData(accountInfo.accountIdentifier, accountInfo.subAccountAttribute, accountInfo.bankCountryCode, accountInfo.bankCode, accountInfo.iban, accountInfo.customerId, - accountInfo.accountType, accountInfo.currency, accountHolderName, accountInfo.productName, + mapAccountType(accountInfo), accountInfo.currency, accountHolderName, accountInfo.productName, accountInfo.accountLimit, accountInfo.allowedJobNames) bank.addAccount(newAccount) @@ -1237,8 +1237,7 @@ open class FinTsClient( protected open fun findExistingAccount(bank: BankData, accountInfo: AccountInfo): AccountData? { bank.accounts.forEach { account -> if (account.accountIdentifier == accountInfo.accountIdentifier - && account.productName == accountInfo.productName - && account.accountType == accountInfo.accountType) { + && account.productName == accountInfo.productName) { return account } @@ -1247,4 +1246,20 @@ open class FinTsClient( return null } + protected open fun mapAccountType(accountInfo: AccountInfo): AccountType? { + if (accountInfo.accountType == null || accountInfo.accountType == AccountType.Sonstige) { + accountInfo.productName?.let { name -> + // comdirect doesn't set account type field but names its bank accounts according to them like 'Girokonto', 'Tagesgeldkonto', ... + return when { + name.contains("Girokonto", true) -> AccountType.Girokonto + name.contains("Tagesgeld", true) || name.contains("Festgeld", true) -> AccountType.Festgeldkonto + name.contains("Kreditkarte", true) -> AccountType.Kreditkartenkonto + else -> accountInfo.accountType + } + } + } + + return accountInfo.accountType + } + } \ No newline at end of file