Implemented that if retrieving account transactions is not supported but retrieving balances, at least balances get retrieved

This commit is contained in:
dankito 2020-08-12 16:29:41 +02:00
parent c442d02e97
commit 392c473056
2 changed files with 42 additions and 29 deletions

View File

@ -259,13 +259,12 @@ open class FinTsClient(
}
/* Second dialog: Get customer system ID - done now in getBankAndCustomerInfoForNewUser(), we try to make it without having to open an extra dialog */
/* Third dialog: Get customer TAN media list - last step that can and must be done without strong customer authorization */
/* Second dialgo: some banks require that in order to initialize a dialog with strong customer authorization TAN media is required */
getTanMediaList(bank, customer, TanMedienArtVersion.Alle, TanMediumKlasse.AlleMedien) {
/* Third dialog: Now we can initialize our first dialog with strong customer authorization. Use it to get UPD and customer's accounts */
getAccounts(bank, customer) { getAccountsResponse ->
if (getAccountsResponse.isSuccessful == false) {
@ -273,12 +272,21 @@ open class FinTsClient(
return@getAccounts
}
/* Fourth dialog: Try to retrieve account transactions of last 90 days without TAN */
/* Fourth dialog: Try to retrieve account balances and transactions of last 90 days without TAN */
// also check if retrieving account transactions of last 90 days without tan is supported (and thereby may retrieve first account transactions)
addAccountGetAccountBalancesAndTransactions(customer, bank, newUserInfoResponse, didOverwriteUserUnselectedTanProcedure,
originalAreWeThatGentleToCloseDialogs, callback)
}
}
}
}
protected open fun addAccountGetAccountBalancesAndTransactions(customer: CustomerData, bank: BankData, newUserInfoResponse: AddAccountResponse, didOverwriteUserUnselectedTanProcedure: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean, callback: (AddAccountResponse) -> Unit) {
val transactionsOfLast90DaysResponses = mutableListOf<GetTransactionsResponse>()
val balances = mutableMapOf<AccountData, Money>()
val countAccountSupportingRetrievingTransactions = customer.accounts.filter { it.supportsFeature(AccountFeature.RetrieveAccountTransactions) }.size
val accountSupportingRetrievingTransactions = customer.accounts.filter { it.supportsFeature(AccountFeature.RetrieveBalance) || it.supportsFeature(AccountFeature.RetrieveAccountTransactions) }
val countAccountSupportingRetrievingTransactions = accountSupportingRetrievingTransactions.size
var countRetrievedAccounts = 0
if (countAccountSupportingRetrievingTransactions == 0) {
@ -286,8 +294,7 @@ open class FinTsClient(
originalAreWeThatGentleToCloseDialogs, transactionsOfLast90DaysResponses, balances, callback)
}
customer.accounts.forEach { account ->
if (account.supportsFeature(AccountFeature.RetrieveAccountTransactions)) {
accountSupportingRetrievingTransactions.forEach { account ->
tryGetTransactionsOfLast90DaysWithoutTan(bank, customer, account, false) { response ->
transactionsOfLast90DaysResponses.add(response)
response.balance?.let { balances.put(account, it) }
@ -301,11 +308,6 @@ open class FinTsClient(
}
}
}
}
}
}
protected open fun addAccountAfterRetrievingTransactions(bank: BankData, customer: CustomerData, newUserInfoResponse: AddAccountResponse,
didOverwriteUserUnselectedTanProcedure: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean,
transactionsOfLast90DaysResponses: MutableList<GetTransactionsResponse>,

View File

@ -175,6 +175,11 @@ open class BankingPresenter(
)
}
}
else { // TODO: find a better way to update balances if transactions couldn't be retrieved
response.balances.keys.forEach { bankAccount ->
updateBalance(bankAccount, response.balances[bankAccount]!!)
}
}
findIconForBankAsync(account)
}
@ -358,13 +363,19 @@ open class BankingPresenter(
bankAccount.addUnbookedTransactions(response.unbookedTransactions)
response.balance?.let {
bankAccount.balance = it
updateBalance(bankAccount, it)
}
persistAccount(bankAccount.customer) // only needed because of balance
persistAccountTransactions(bankAccount, response.bookedTransactions, response.unbookedTransactions)
}
protected open fun updateBalance(bankAccount: BankAccount, balance: BigDecimal) {
bankAccount.balance = balance
persistAccount(bankAccount.customer)
}
open fun formatAmount(amount: BigDecimal): String {
return amount.format(2)
}