From a983df42b1fae8090a0f71545457fa9ed1fc9169 Mon Sep 17 00:00:00 2001 From: dankito Date: Tue, 27 Aug 2024 23:36:18 +0200 Subject: [PATCH] Mapping BankingGroup (TODO: but is duplicated code from BankListCreator); added BankingGroup to CustomerAccountViewInfo --- .../client/model/CustomerAccountViewInfo.kt | 3 +- .../banking/client/fints4k/FinTs4kMapper.kt | 12 +++- .../prettifier/BankingGroupMapper.kt | 72 +++++++++++++++++++ 3 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 FinTs4jBankingClient/src/commonMain/kotlin/net/dankito/banking/banklistcreator/prettifier/BankingGroupMapper.kt diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/CustomerAccountViewInfo.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/CustomerAccountViewInfo.kt index fa506dd2..f58cf9e2 100644 --- a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/CustomerAccountViewInfo.kt +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/CustomerAccountViewInfo.kt @@ -10,7 +10,8 @@ import net.codinux.banking.client.model.config.NoArgConstructor open class CustomerAccountViewInfo( val bankCode: String, var loginName: String, - val bankName: String + val bankName: String, + val bankingGroup: BankingGroup? = null ) { override fun toString() = "$bankCode $bankName $loginName" } \ No newline at end of file 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 b5477516..5708dfff 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 @@ -21,6 +21,7 @@ import net.codinux.banking.fints.messages.datenelemente.implementierte.tan.TanMe import net.codinux.banking.fints.messages.datenelemente.implementierte.tan.MobilePhoneTanMedium import net.codinux.banking.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium import net.codinux.banking.fints.messages.datenelemente.implementierte.tan.TanMediumStatus +import net.dankito.banking.banklistcreator.prettifier.BankingGroupMapper import kotlin.io.encoding.Base64 import kotlin.io.encoding.ExperimentalEncodingApi @@ -28,6 +29,8 @@ open class FinTs4kMapper { protected val fintsModelMapper = FinTsModelMapper() + protected val bankingGroupMapper = BankingGroupMapper() + open fun mapToGetAccountDataParameter(credentials: AccountCredentials, options: GetAccountDataOptions) = GetAccountDataParameter( credentials.bankCode, credentials.loginName, credentials.password, @@ -52,7 +55,7 @@ open class FinTs4kMapper { open fun mapToCustomerAccountViewInfo(bank: BankData): CustomerAccountViewInfo = CustomerAccountViewInfo( - bank.bankCode, bank.customerId, bank.bankName + bank.bankCode, bank.customerId, bank.bankName, getBankingGroup(bank.bankName, bank.bic) ) open fun mapToBankAccountViewInfo(account: AccountData): BankAccountViewInfo = BankAccountViewInfo( @@ -68,9 +71,14 @@ open class FinTs4kMapper { customer.accounts.map { mapAccount(it) }, customer.selectedTanMethod?.securityFunction?.code, customer.tanMethods.map { mapTanMethod(it) }, - customer.selectedTanMedium?.mediumName, customer.tanMedia.map { mapTanMedium(it) } + customer.selectedTanMedium?.mediumName, customer.tanMedia.map { mapTanMedium(it) }, + + getBankingGroup(customer.bankName, customer.bic) ) + protected open fun getBankingGroup(bankName: String, bic: String): BankingGroup? = + bankingGroupMapper.getBankingGroup(bankName, bic) + protected open fun mapAccount(account: net.dankito.banking.client.model.BankAccount): BankAccount = BankAccount( account.identifier, account.accountHolderName, mapAccountType(account.type), account.iban, account.subAccountNumber, diff --git a/FinTs4jBankingClient/src/commonMain/kotlin/net/dankito/banking/banklistcreator/prettifier/BankingGroupMapper.kt b/FinTs4jBankingClient/src/commonMain/kotlin/net/dankito/banking/banklistcreator/prettifier/BankingGroupMapper.kt new file mode 100644 index 00000000..361fa3b2 --- /dev/null +++ b/FinTs4jBankingClient/src/commonMain/kotlin/net/dankito/banking/banklistcreator/prettifier/BankingGroupMapper.kt @@ -0,0 +1,72 @@ +package net.dankito.banking.banklistcreator.prettifier + +import net.codinux.banking.client.model.BankingGroup + +// TODO: class has been duplicated from BankListCreator, find a better place for it +class BankingGroupMapper { + + fun getBankingGroup(bankName: String, bic: String): BankingGroup? { + val lowercase = bankName.lowercase() + + return when { + bankName.contains("Sparda") -> BankingGroup.Sparda + bankName.contains("PSD") -> BankingGroup.PSD + bankName.contains("GLS") -> BankingGroup.GLS + // see https://de.wikipedia.org/wiki/Liste_der_Genossenschaftsbanken_in_Deutschland + bankName.contains("BBBank") || bankName.contains("Evangelische Bank") || bankName.contains("LIGA Bank") + || bankName.contains("Pax") || bankName.contains("Bank für Kirche und Diakonie") || bankName.contains("Bank im Bistum Essen") + || bankName.contains("Bank für Schiffahrt") || bankName.contains("Bank für Kirche") + -> BankingGroup.SonstigeGenossenschaftsbank + lowercase.contains("deutsche kreditbank") -> BankingGroup.DKB + // may check against https://de.wikipedia.org/wiki/Liste_der_Sparkassen_in_Deutschland + lowercase.contains("sparkasse") -> BankingGroup.Sparkasse + lowercase.contains("comdirect") -> BankingGroup.Comdirect + lowercase.contains("commerzbank") -> BankingGroup.Commerzbank + lowercase.contains("targo") -> BankingGroup.Targobank + lowercase.contains("santander") -> BankingGroup.Santander + bankName.contains("KfW") -> BankingGroup.KfW + bankName.contains("N26") -> BankingGroup.N26 + else -> getBankingGroupByBic(bic) + } + } + + private fun getBankingGroupByBic(bic: String): BankingGroup? { + if (bic.length < 4) { + return null + } + + if (bic.startsWith("CMCIDEDD")) { + return BankingGroup.Targobank + } + + val bankCodeOfBic = bic.substring(0, 4) + + return when (bankCodeOfBic) { + "GENO", "VBMH", "VOHA", "VBRS", "DBPB", "VBGT", "FFVB", "WIBA", "VRBU", "MVBM", "VOBA", "ULMV", "VBRT", "VBRA", "VBPF", "VOLO" -> BankingGroup.VolksUndRaiffeisenbanken + "BFSW", // Bank fuer Sozialwirtschaft + "BEVO", // Berliner Volksbank + "DAAE", // apoBank + "MHYP", // Münchener Hypothekenbank + "DZBM", // DZB Bank + "EDEK" // Edekabank + -> BankingGroup.SonstigeGenossenschaftsbank + "BYLA", "SOLA", "NOLA", "WELA", "HELA", "MALA", "BRLA", "NASS", "TRIS", "OSDD", "ESSL", "GOPS", "SBCR", "BRUS" -> BankingGroup.Sparkasse // filter out DBK, (Bayr.) Landesbank, ... + "OLBO" -> BankingGroup.OldenburgischeLandesbank + "DEUT" -> BankingGroup.DeutscheBank + "PBNK" -> BankingGroup.Postbank + "COBA", "DRES" -> BankingGroup.Commerzbank // COBA could also be comdirect, but we cannot differentiate this at this level, this has to do getBankingGroup() + "HYVE" -> BankingGroup.Unicredit + "INGB" -> BankingGroup.ING + "SCFB" -> BankingGroup.Santander + "NORS" -> BankingGroup.Norisbank + "DEGU" -> BankingGroup.Degussa + "OBKL" -> BankingGroup.Oberbank + "MARK" -> BankingGroup.Bundesbank + "KFWI", "DTAB" -> BankingGroup.KfW + "NTSB" -> BankingGroup.N26 + "CSDB" -> BankingGroup.Consors + else -> null + } + } + +} \ No newline at end of file