Added enum AccountFeature to be better extensible of upcoming implemented features
This commit is contained in:
parent
68dc62d02c
commit
8c6c65c7b0
|
@ -193,7 +193,7 @@ open class FinTsClient @JvmOverloads constructor(
|
|||
val transactionsOfLast90DaysResponses = mutableListOf<GetTransactionsResponse>()
|
||||
val balances = mutableMapOf<AccountData, BigDecimal>()
|
||||
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<TanProcedure> {
|
||||
|
|
|
@ -19,15 +19,30 @@ open class AccountData(
|
|||
val accountLimit: String?,
|
||||
val allowedJobNames: List<String>,
|
||||
var allowedJobs: List<JobParameters> = 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<AccountFeature>()
|
||||
|
||||
|
||||
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"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package net.dankito.fints.model
|
||||
|
||||
|
||||
enum class AccountFeature {
|
||||
|
||||
RetrieveAccountTransactions,
|
||||
|
||||
RetrieveBalance,
|
||||
|
||||
TransferMoney
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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? {
|
||||
|
|
Loading…
Reference in New Issue