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 3740b298..d8a82c9a 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt @@ -244,7 +244,8 @@ open class FinTsClient( } - open fun addAccountAsync(bank: BankData, callback: (AddAccountResponse) -> Unit) { + open fun addAccountAsync(parameter: AddAccountParameter, callback: (AddAccountResponse) -> Unit) { + val bank = parameter.bank val originalAreWeThatGentleToCloseDialogs = areWeThatGentleToCloseDialogs areWeThatGentleToCloseDialogs = false @@ -286,10 +287,16 @@ open class FinTsClient( return@getAccounts } - /* Fourth dialog: Try to retrieve account balances and transactions of last 90 days without TAN */ + /* Fourth dialog (if requested): Try to retrieve account balances and transactions of last 90 days without TAN */ - addAccountGetAccountBalancesAndTransactions(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod, - originalAreWeThatGentleToCloseDialogs, callback) + if (parameter.fetchBalanceAndTransactions) { + addAccountGetAccountBalancesAndTransactions(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod, + originalAreWeThatGentleToCloseDialogs, callback) + } + else { + addAccountDone(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod, originalAreWeThatGentleToCloseDialogs, + mapOf(), callback) + } } } } @@ -306,7 +313,7 @@ open class FinTsClient( var countRetrievedAccounts = 0 if (countAccountsSupportingRetrievingTransactions == 0) { - addAccountAfterRetrievingTransactions(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod, + addAccountDone(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod, originalAreWeThatGentleToCloseDialogs, retrievedAccountData, callback) } @@ -316,17 +323,17 @@ open class FinTsClient( countRetrievedAccounts++ if (countRetrievedAccounts == countAccountsSupportingRetrievingTransactions) { - addAccountAfterRetrievingTransactions(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod, originalAreWeThatGentleToCloseDialogs, + addAccountDone(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod, originalAreWeThatGentleToCloseDialogs, retrievedAccountData, callback) } } } } - protected open fun addAccountAfterRetrievingTransactions(bank: BankData, getAccountsResponse: BankResponse, - didOverwriteUserUnselectedTanMethod: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean, - retrievedAccountData: Map, - callback: (AddAccountResponse) -> Unit) { + protected open fun addAccountDone(bank: BankData, getAccountsResponse: BankResponse, + didOverwriteUserUnselectedTanMethod: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean, + retrievedAccountData: Map, + callback: (AddAccountResponse) -> Unit) { if (didOverwriteUserUnselectedTanMethod) { bank.resetSelectedTanMethod() } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClientForCustomer.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClientForCustomer.kt index 8180a53d..175e1628 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClientForCustomer.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClientForCustomer.kt @@ -34,7 +34,11 @@ open class FinTsClientForCustomer( open fun addAccountAsync(callback: (AddAccountResponse) -> Unit) { - client.addAccountAsync(bank, callback) + addAccountAsync(bank.toAddAccountParameter(), callback) + } + + open fun addAccountAsync(parameter: AddAccountParameter, callback: (AddAccountResponse) -> Unit) { + client.addAccountAsync(parameter, callback) } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/AddAccountParameter.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/AddAccountParameter.kt new file mode 100644 index 00000000..f5535cfe --- /dev/null +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/AddAccountParameter.kt @@ -0,0 +1,17 @@ +package net.dankito.banking.fints.model + +import kotlin.jvm.JvmOverloads + + +open class AddAccountParameter @JvmOverloads constructor( + open val bank: BankData, + open val fetchBalanceAndTransactions: Boolean = true +) { + + constructor(bankCode: String, customerId: String, pin: String, finTs3ServerAddress: String) + : this(bankCode, customerId, pin, finTs3ServerAddress, "") + + constructor(bankCode: String, customerId: String, pin: String, finTs3ServerAddress: String, bic: String = "", fetchBalanceAndTransactions: Boolean = true) + : this(BankData(bankCode, customerId, pin, finTs3ServerAddress, bic), fetchBalanceAndTransactions) + +} \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/BankDataExtensions.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/BankDataExtensions.kt new file mode 100644 index 00000000..de04be63 --- /dev/null +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/BankDataExtensions.kt @@ -0,0 +1,10 @@ +package net.dankito.banking.fints.model + + +fun BankData.toAddAccountParameter(): AddAccountParameter { + return toAddAccountParameter(true) +} + +fun BankData.toAddAccountParameter(fetchBalanceAndTransactions: Boolean = true): AddAccountParameter { + return AddAccountParameter(this, fetchBalanceAndTransactions) +} \ No newline at end of file diff --git a/fints4k/src/jvm6Test/kotlin/net/dankito/banking/fints/FinTsClientTestBase.kt b/fints4k/src/jvm6Test/kotlin/net/dankito/banking/fints/FinTsClientTestBase.kt index 0b01484d..d2f71f6d 100644 --- a/fints4k/src/jvm6Test/kotlin/net/dankito/banking/fints/FinTsClientTestBase.kt +++ b/fints4k/src/jvm6Test/kotlin/net/dankito/banking/fints/FinTsClientTestBase.kt @@ -110,7 +110,7 @@ open class FinTsClientTestBase { // when - underTest.addAccountAsync(Bank) { + underTest.addAccountAsync(Bank.toAddAccountParameter()) { response.set(it) countDownLatch.countDown() } @@ -148,7 +148,7 @@ open class FinTsClientTestBase { val response = AtomicReference() val countDownLatch = CountDownLatch(1) - underTest.addAccountAsync(Bank) { // retrieve basic data, e.g. accounts + underTest.addAccountAsync(Bank.toAddAccountParameter(false)) { // retrieve basic data, e.g. accounts val account = Bank.accounts.firstOrNull { it.supportsFeature(AccountFeature.RetrieveAccountTransactions) } expect(account).withRepresentation("We need at least one account that supports retrieving account transactions (${CustomerSegmentId.AccountTransactionsMt940.id})").notToBeNull() @@ -224,7 +224,7 @@ open class FinTsClientTestBase { val response = AtomicReference() val countDownLatch = CountDownLatch(1) - underTest.addAccountAsync(Bank) { // retrieve basic data, e.g. accounts + underTest.addAccountAsync(Bank.toAddAccountParameter(false)) { // retrieve basic data, e.g. accounts // we need at least one account that supports cash transfer val account = Bank.accounts.firstOrNull { it.supportsFeature(AccountFeature.TransferMoney) } expect(account).withRepresentation("We need at least one account that supports cash transfer (${CustomerSegmentId.SepaBankTransfer.id})").notToBeNull() diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/AddAccountResponse.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/AddAccountResponse.kt index 264c6656..c62b10ad 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/AddAccountResponse.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/AddAccountResponse.kt @@ -15,7 +15,8 @@ open class AddAccountResponse( override val successful: Boolean - get() = super.successful && bank.accounts.isNotEmpty() + get() = noErrorOccurred + && bank.accounts.isNotEmpty() open val supportsRetrievingTransactionsOfLast90DaysWithoutTan: Boolean get() = retrievedData.isNotEmpty() && retrievedData.any { it.successfullyRetrievedData } diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/BankingClientResponse.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/BankingClientResponse.kt index f423c1a1..3a1469e9 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/BankingClientResponse.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/BankingClientResponse.kt @@ -9,6 +9,11 @@ open class BankingClientResponse( ) { + protected open val noErrorOccurred: Boolean + get() = errorToShowToUser == null + && wrongCredentialsEntered == false + + override fun toString(): String { return if (successful) { "Successful" diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/GetTransactionsResponse.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/GetTransactionsResponse.kt index ff36a2ab..0508f044 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/GetTransactionsResponse.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/model/responses/GetTransactionsResponse.kt @@ -23,8 +23,7 @@ open class GetTransactionsResponse( override val successful: Boolean - get() = errorToShowToUser == null - && wrongCredentialsEntered == false + get() = noErrorOccurred && retrievedData.isNotEmpty() && retrievedData.none { it.account.supportsRetrievingAccountTransactions && it.successfullyRetrievedData == false } diff --git a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt index 3fc9413f..db208214 100644 --- a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt +++ b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt @@ -58,7 +58,11 @@ open class fints4kBankingClient( override fun addAccountAsync(callback: (AddAccountResponse) -> Unit) { - client.addAccountAsync { response -> + addAccountAsync(AddAccountParameter(fintsBank), callback) + } + + protected open fun addAccountAsync(parameter: AddAccountParameter, callback: (AddAccountResponse) -> Unit) { + client.addAccountAsync(parameter) { response -> handleAddAccountResponse(response, callback) } } @@ -167,7 +171,7 @@ open class fints4kBankingClient( findAccountResult(mappedAccount, null) } else { // then try to get account data by fetching data from bank - addAccountAsync { response -> + addAccountAsync(AddAccountParameter(fintsBank, false)) { response -> if (response.successful) { findAccountResult(mapper.findMatchingAccount(fintsBank, account), response) }