diff --git a/fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt index e92f477a..2f46bab1 100644 --- a/fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -193,7 +193,7 @@ open class FinTsClient @JvmOverloads constructor( val transactionsOfLast90DaysResponses = mutableListOf() val balances = mutableMapOf() customer.accounts.forEach { account -> - if (account.supportsRetrievingAccountTransactions) { + if (account.supportsFeature(AccountFeature.RetrieveAccountTransactions)) { val response = tryGetTransactionsOfLast90DaysWithoutTan(bank, customer, account, false) transactionsOfLast90DaysResponses.add(response) response.balance?.let { balances.put(account, it) } @@ -225,7 +225,7 @@ open class FinTsClient @JvmOverloads constructor( val now = Date() val ninetyDaysAgo = Date(now.time - NinetyDaysAgoMilliseconds - now.timezoneOffset * 60 * 1000) // map to UTC - val response = getTransactions(GetTransactionsParameter(account.supportsRetrievingBalance, ninetyDaysAgo), bank, customer, account) + val response = getTransactions(GetTransactionsParameter(account.supportsFeature(AccountFeature.RetrieveBalance), ninetyDaysAgo), bank, customer, account) account.triedToRetrieveTransactionsOfLast90DaysWithoutTan = true @@ -261,7 +261,7 @@ open class FinTsClient @JvmOverloads constructor( var balance: BigDecimal? = null - if (parameter.alsoRetrieveBalance && account.supportsRetrievingBalance) { + if (parameter.alsoRetrieveBalance && account.supportsFeature(AccountFeature.RetrieveBalance)) { val balanceResponse = getBalanceAfterDialogInit(account, dialogContext) if (balanceResponse.successful == false && balanceResponse.couldCreateMessage == true) { // don't break here if required HKSAL message is not implemented @@ -864,9 +864,9 @@ open class FinTsClient @JvmOverloads constructor( account.allowedJobs = allowedJobsForAccount - account.supportsRetrievingAccountTransactions = messageBuilder.supportsGetTransactions(account) - account.supportsRetrievingBalance = messageBuilder.supportsGetBalance(account) - account.supportsTransferringMoney = messageBuilder.supportsBankTransfer(account) + account.setSupportsFeature(AccountFeature.RetrieveAccountTransactions, messageBuilder.supportsGetTransactions(account)) + account.setSupportsFeature(AccountFeature.RetrieveBalance, messageBuilder.supportsGetBalance(account)) + account.setSupportsFeature(AccountFeature.TransferMoney, messageBuilder.supportsBankTransfer(account)) } protected open fun mapToTanProcedures(tanInfo: TanInfo): List { diff --git a/fints4k/src/main/kotlin/net/dankito/fints/model/AccountData.kt b/fints4k/src/main/kotlin/net/dankito/fints/model/AccountData.kt index 35542cbb..b7af240b 100644 --- a/fints4k/src/main/kotlin/net/dankito/fints/model/AccountData.kt +++ b/fints4k/src/main/kotlin/net/dankito/fints/model/AccountData.kt @@ -19,15 +19,30 @@ open class AccountData( val accountLimit: String?, val allowedJobNames: List, var allowedJobs: List = listOf(), - var supportsRetrievingAccountTransactions: Boolean = false, - var supportsRetrievingBalance: Boolean = false, - var supportsTransferringMoney: Boolean = false, var supportsRetrievingTransactionsOfLast90DaysWithoutTan: Boolean? = null, var triedToRetrieveTransactionsOfLast90DaysWithoutTan: Boolean = false ) { internal constructor() : this("", null, Laenderkennzeichen.Germany, "", null, "", null, null, "", null, null, listOf()) // for object deserializers + + protected val supportedFeatures = mutableSetOf() + + + open fun supportsFeature(feature: AccountFeature): Boolean { + return supportedFeatures.contains(feature) + } + + open fun setSupportsFeature(feature: AccountFeature, isSupported: Boolean) { + if (isSupported) { + supportedFeatures.add(feature) + } + else { + supportedFeatures.remove(feature) + } + } + + override fun toString(): String { return "$productName $accountIdentifier $accountHolderName" } diff --git a/fints4k/src/main/kotlin/net/dankito/fints/model/AccountFeature.kt b/fints4k/src/main/kotlin/net/dankito/fints/model/AccountFeature.kt new file mode 100644 index 00000000..1d7f5710 --- /dev/null +++ b/fints4k/src/main/kotlin/net/dankito/fints/model/AccountFeature.kt @@ -0,0 +1,12 @@ +package net.dankito.fints.model + + +enum class AccountFeature { + + RetrieveAccountTransactions, + + RetrieveBalance, + + TransferMoney + +} \ No newline at end of file diff --git a/fints4k/src/test/java/net/dankito/fints/java/JavaShowcase.java b/fints4k/src/test/java/net/dankito/fints/java/JavaShowcase.java index f10ec091..b2dbcc25 100644 --- a/fints4k/src/test/java/net/dankito/fints/java/JavaShowcase.java +++ b/fints4k/src/test/java/net/dankito/fints/java/JavaShowcase.java @@ -66,7 +66,7 @@ public class JavaShowcase { /* Other stuff you can do with the lib */ for (AccountData account : customer.getAccounts()) { // accounts are now retrieved - if (account.getSupportsRetrievingAccountTransactions()) { + if (account.supportsFeature(AccountFeature.RetrieveAccountTransactions)) { // retrieves all account transactions, but requires entering a TAN (FinTsClientCallback.enterTan() will be called) // GetTransactionsResponse response = finTsClient.getTransactions( // new GetTransactionsParameter(true), bank, customer, account); @@ -74,7 +74,7 @@ public class JavaShowcase { // showGetTransactionsResponse(response); } - if (account.getSupportsTransferringMoney()) { + if (account.supportsFeature(AccountFeature.TransferMoney)) { // transfer 0.01 € to yourself // BankTransferData data = new BankTransferData(customer.getName(), account.getIban(), bank.getBic(), new BigDecimal("0.01"), "Hey I can transfer money to myself") // FinTsClientResponse transferMoneyResponse = finTsClient.doBankTransfer(data, bank, customer, account); diff --git a/fints4k/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt b/fints4k/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt index 063653a3..b56650c6 100644 --- a/fints4k/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt +++ b/fints4k/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt @@ -139,7 +139,7 @@ class FinTsClientTest { // given underTest.addAccount(Bank, Customer) // retrieve basic data, e.g. accounts - val account = Customer.accounts.firstOrNull { it.allowedJobNames.contains(CustomerSegmentId.AccountTransactionsMt940.id) } + val account = Customer.accounts.firstOrNull { it.supportsFeature(AccountFeature.RetrieveAccountTransactions) } assertThat(account).describedAs("We need at least one account that supports retrieving account transactions (${CustomerSegmentId.AccountTransactionsMt940.id})").isNotNull() // when @@ -194,7 +194,7 @@ class FinTsClientTest { underTest.addAccount(Bank, Customer) // retrieve basic data, e.g. accounts // we need at least one account that supports cash transfer - val account = Customer.accounts.firstOrNull { it.allowedJobNames.contains(CustomerSegmentId.SepaBankTransfer.id) } + val account = Customer.accounts.firstOrNull { it.supportsFeature(AccountFeature.TransferMoney) } assertThat(account).describedAs("We need at least one account that supports cash transfer (${CustomerSegmentId.SepaBankTransfer.id})").isNotNull() // IBAN should be set diff --git a/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/mapper/fints4javaModelMapper.kt b/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/mapper/fints4javaModelMapper.kt index b426a916..73549b73 100644 --- a/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/mapper/fints4javaModelMapper.kt +++ b/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/mapper/fints4javaModelMapper.kt @@ -7,6 +7,7 @@ import net.dankito.banking.ui.model.responses.GetTransactionsResponse import net.dankito.banking.ui.model.tan.* import net.dankito.fints.messages.datenelemente.implementierte.signatur.Sicherheitsfunktion import net.dankito.fints.model.AccountData +import net.dankito.fints.model.AccountFeature import net.dankito.fints.model.BankData import net.dankito.fints.model.CustomerData import net.dankito.fints.response.client.FinTsClientResponse @@ -103,8 +104,8 @@ open class fints4javaModelMapper { open fun mapBankAccount(account: Account, accountData: AccountData): BankAccount { return BankAccount(account, accountData.accountIdentifier, accountData.accountHolderName, accountData.iban, accountData.subAccountAttribute, BigDecimal.ZERO, accountData.currency ?: "EUR", - mapBankAccountType(accountData.accountType), accountData.supportsRetrievingAccountTransactions, - accountData.supportsRetrievingBalance, accountData.supportsTransferringMoney) + mapBankAccountType(accountData.accountType), accountData.supportsFeature(AccountFeature.RetrieveAccountTransactions), + accountData.supportsFeature(AccountFeature.RetrieveBalance), accountData.supportsFeature(AccountFeature.TransferMoney)) } open fun mapBankAccountType(type: AccountType?): BankAccountType { @@ -149,9 +150,9 @@ open class fints4javaModelMapper { open fun updateBankAccount(account: AccountData, updatedAccount: AccountData) { account.allowedJobs = updatedAccount.allowedJobs - account.supportsRetrievingAccountTransactions = updatedAccount.supportsRetrievingAccountTransactions - account.supportsRetrievingBalance = updatedAccount.supportsRetrievingBalance - account.supportsTransferringMoney = updatedAccount.supportsTransferringMoney + AccountFeature.values().forEach { feature -> + account.setSupportsFeature(feature, updatedAccount.supportsFeature(feature)) + } } open fun findAccountForBankAccount(customer: CustomerData, bankAccount: BankAccount): AccountData? {