Added fetchBalanceAndTransactions to addAccount() to determine if balance and transactions should be retrieved after retrieving bank accounts of a newly added account
This commit is contained in:
parent
9e5b18a522
commit
f4d8b09260
|
@ -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<AccountData, RetrievedAccountData>,
|
||||
callback: (AddAccountResponse) -> Unit) {
|
||||
protected open fun addAccountDone(bank: BankData, getAccountsResponse: BankResponse,
|
||||
didOverwriteUserUnselectedTanMethod: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean,
|
||||
retrievedAccountData: Map<AccountData, RetrievedAccountData>,
|
||||
callback: (AddAccountResponse) -> Unit) {
|
||||
if (didOverwriteUserUnselectedTanMethod) {
|
||||
bank.resetSelectedTanMethod()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -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<GetTransactionsResponse>()
|
||||
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<FinTsClientResponse>()
|
||||
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()
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue