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
|
val originalAreWeThatGentleToCloseDialogs = areWeThatGentleToCloseDialogs
|
||||||
areWeThatGentleToCloseDialogs = false
|
areWeThatGentleToCloseDialogs = false
|
||||||
|
@ -286,11 +287,17 @@ open class FinTsClient(
|
||||||
return@getAccounts
|
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 */
|
||||||
|
|
||||||
|
if (parameter.fetchBalanceAndTransactions) {
|
||||||
addAccountGetAccountBalancesAndTransactions(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod,
|
addAccountGetAccountBalancesAndTransactions(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod,
|
||||||
originalAreWeThatGentleToCloseDialogs, callback)
|
originalAreWeThatGentleToCloseDialogs, callback)
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
addAccountDone(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod, originalAreWeThatGentleToCloseDialogs,
|
||||||
|
mapOf(), callback)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,7 +313,7 @@ open class FinTsClient(
|
||||||
var countRetrievedAccounts = 0
|
var countRetrievedAccounts = 0
|
||||||
|
|
||||||
if (countAccountsSupportingRetrievingTransactions == 0) {
|
if (countAccountsSupportingRetrievingTransactions == 0) {
|
||||||
addAccountAfterRetrievingTransactions(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod,
|
addAccountDone(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod,
|
||||||
originalAreWeThatGentleToCloseDialogs, retrievedAccountData, callback)
|
originalAreWeThatGentleToCloseDialogs, retrievedAccountData, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,14 +323,14 @@ open class FinTsClient(
|
||||||
|
|
||||||
countRetrievedAccounts++
|
countRetrievedAccounts++
|
||||||
if (countRetrievedAccounts == countAccountsSupportingRetrievingTransactions) {
|
if (countRetrievedAccounts == countAccountsSupportingRetrievingTransactions) {
|
||||||
addAccountAfterRetrievingTransactions(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod, originalAreWeThatGentleToCloseDialogs,
|
addAccountDone(bank, getAccountsResponse, didOverwriteUserUnselectedTanMethod, originalAreWeThatGentleToCloseDialogs,
|
||||||
retrievedAccountData, callback)
|
retrievedAccountData, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun addAccountAfterRetrievingTransactions(bank: BankData, getAccountsResponse: BankResponse,
|
protected open fun addAccountDone(bank: BankData, getAccountsResponse: BankResponse,
|
||||||
didOverwriteUserUnselectedTanMethod: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean,
|
didOverwriteUserUnselectedTanMethod: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean,
|
||||||
retrievedAccountData: Map<AccountData, RetrievedAccountData>,
|
retrievedAccountData: Map<AccountData, RetrievedAccountData>,
|
||||||
callback: (AddAccountResponse) -> Unit) {
|
callback: (AddAccountResponse) -> Unit) {
|
||||||
|
|
|
@ -34,7 +34,11 @@ open class FinTsClientForCustomer(
|
||||||
|
|
||||||
|
|
||||||
open fun addAccountAsync(callback: (AddAccountResponse) -> Unit) {
|
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
|
// when
|
||||||
underTest.addAccountAsync(Bank) {
|
underTest.addAccountAsync(Bank.toAddAccountParameter()) {
|
||||||
response.set(it)
|
response.set(it)
|
||||||
countDownLatch.countDown()
|
countDownLatch.countDown()
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ open class FinTsClientTestBase {
|
||||||
val response = AtomicReference<GetTransactionsResponse>()
|
val response = AtomicReference<GetTransactionsResponse>()
|
||||||
val countDownLatch = CountDownLatch(1)
|
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) }
|
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()
|
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 response = AtomicReference<FinTsClientResponse>()
|
||||||
val countDownLatch = CountDownLatch(1)
|
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
|
// we need at least one account that supports cash transfer
|
||||||
val account = Bank.accounts.firstOrNull { it.supportsFeature(AccountFeature.TransferMoney) }
|
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()
|
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
|
override val successful: Boolean
|
||||||
get() = super.successful && bank.accounts.isNotEmpty()
|
get() = noErrorOccurred
|
||||||
|
&& bank.accounts.isNotEmpty()
|
||||||
|
|
||||||
open val supportsRetrievingTransactionsOfLast90DaysWithoutTan: Boolean
|
open val supportsRetrievingTransactionsOfLast90DaysWithoutTan: Boolean
|
||||||
get() = retrievedData.isNotEmpty() && retrievedData.any { it.successfullyRetrievedData }
|
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 {
|
override fun toString(): String {
|
||||||
return if (successful) {
|
return if (successful) {
|
||||||
"Successful"
|
"Successful"
|
||||||
|
|
|
@ -23,8 +23,7 @@ open class GetTransactionsResponse(
|
||||||
|
|
||||||
|
|
||||||
override val successful: Boolean
|
override val successful: Boolean
|
||||||
get() = errorToShowToUser == null
|
get() = noErrorOccurred
|
||||||
&& wrongCredentialsEntered == false
|
|
||||||
&& retrievedData.isNotEmpty()
|
&& retrievedData.isNotEmpty()
|
||||||
&& retrievedData.none { it.account.supportsRetrievingAccountTransactions && it.successfullyRetrievedData == false }
|
&& retrievedData.none { it.account.supportsRetrievingAccountTransactions && it.successfullyRetrievedData == false }
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,11 @@ open class fints4kBankingClient(
|
||||||
|
|
||||||
|
|
||||||
override fun addAccountAsync(callback: (AddAccountResponse) -> Unit) {
|
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)
|
handleAddAccountResponse(response, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +171,7 @@ open class fints4kBankingClient(
|
||||||
findAccountResult(mappedAccount, null)
|
findAccountResult(mappedAccount, null)
|
||||||
}
|
}
|
||||||
else { // then try to get account data by fetching data from bank
|
else { // then try to get account data by fetching data from bank
|
||||||
addAccountAsync { response ->
|
addAccountAsync(AddAccountParameter(fintsBank, false)) { response ->
|
||||||
if (response.successful) {
|
if (response.successful) {
|
||||||
findAccountResult(mapper.findMatchingAccount(fintsBank, account), response)
|
findAccountResult(mapper.findMatchingAccount(fintsBank, account), response)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue