Implemented that if retrieving account transactions is not supported but retrieving balances, at least balances get retrieved
This commit is contained in:
parent
c442d02e97
commit
392c473056
|
@ -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 */
|
/* Second dialgo: some banks require that in order to initialize a dialog with strong customer authorization TAN media is required */
|
||||||
|
|
||||||
|
|
||||||
/* Third dialog: Get customer TAN media list - last step that can and must be done without strong customer authorization */
|
|
||||||
|
|
||||||
getTanMediaList(bank, customer, TanMedienArtVersion.Alle, TanMediumKlasse.AlleMedien) {
|
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 ->
|
getAccounts(bank, customer) { getAccountsResponse ->
|
||||||
|
|
||||||
if (getAccountsResponse.isSuccessful == false) {
|
if (getAccountsResponse.isSuccessful == false) {
|
||||||
|
@ -273,34 +272,37 @@ open class FinTsClient(
|
||||||
return@getAccounts
|
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,
|
||||||
val transactionsOfLast90DaysResponses = mutableListOf<GetTransactionsResponse>()
|
originalAreWeThatGentleToCloseDialogs, callback)
|
||||||
val balances = mutableMapOf<AccountData, Money>()
|
}
|
||||||
val countAccountSupportingRetrievingTransactions = customer.accounts.filter { it.supportsFeature(AccountFeature.RetrieveAccountTransactions) }.size
|
}
|
||||||
var countRetrievedAccounts = 0
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (countAccountSupportingRetrievingTransactions == 0) {
|
protected open fun addAccountGetAccountBalancesAndTransactions(customer: CustomerData, bank: BankData, newUserInfoResponse: AddAccountResponse, didOverwriteUserUnselectedTanProcedure: Boolean, originalAreWeThatGentleToCloseDialogs: Boolean, callback: (AddAccountResponse) -> Unit) {
|
||||||
addAccountAfterRetrievingTransactions(bank, customer, newUserInfoResponse, didOverwriteUserUnselectedTanProcedure,
|
val transactionsOfLast90DaysResponses = mutableListOf<GetTransactionsResponse>()
|
||||||
originalAreWeThatGentleToCloseDialogs, transactionsOfLast90DaysResponses, balances, callback)
|
val balances = mutableMapOf<AccountData, Money>()
|
||||||
}
|
|
||||||
|
|
||||||
customer.accounts.forEach { account ->
|
val accountSupportingRetrievingTransactions = customer.accounts.filter { it.supportsFeature(AccountFeature.RetrieveBalance) || it.supportsFeature(AccountFeature.RetrieveAccountTransactions) }
|
||||||
if (account.supportsFeature(AccountFeature.RetrieveAccountTransactions)) {
|
val countAccountSupportingRetrievingTransactions = accountSupportingRetrievingTransactions.size
|
||||||
tryGetTransactionsOfLast90DaysWithoutTan(bank, customer, account, false) { response ->
|
var countRetrievedAccounts = 0
|
||||||
transactionsOfLast90DaysResponses.add(response)
|
|
||||||
response.balance?.let { balances.put(account, it) }
|
|
||||||
|
|
||||||
countRetrievedAccounts++
|
if (countAccountSupportingRetrievingTransactions == 0) {
|
||||||
if (countRetrievedAccounts == countAccountSupportingRetrievingTransactions) {
|
addAccountAfterRetrievingTransactions(bank, customer, newUserInfoResponse, didOverwriteUserUnselectedTanProcedure,
|
||||||
addAccountAfterRetrievingTransactions(bank, customer, newUserInfoResponse, didOverwriteUserUnselectedTanProcedure, originalAreWeThatGentleToCloseDialogs,
|
originalAreWeThatGentleToCloseDialogs, transactionsOfLast90DaysResponses, balances, callback)
|
||||||
transactionsOfLast90DaysResponses, balances, callback)
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
accountSupportingRetrievingTransactions.forEach { account ->
|
||||||
|
tryGetTransactionsOfLast90DaysWithoutTan(bank, customer, account, false) { response ->
|
||||||
|
transactionsOfLast90DaysResponses.add(response)
|
||||||
|
response.balance?.let { balances.put(account, it) }
|
||||||
|
|
||||||
|
countRetrievedAccounts++
|
||||||
|
if (countRetrievedAccounts == countAccountSupportingRetrievingTransactions) {
|
||||||
|
addAccountAfterRetrievingTransactions(bank, customer, newUserInfoResponse, didOverwriteUserUnselectedTanProcedure, originalAreWeThatGentleToCloseDialogs,
|
||||||
|
transactionsOfLast90DaysResponses, balances, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
findIconForBankAsync(account)
|
||||||
}
|
}
|
||||||
|
@ -358,13 +363,19 @@ open class BankingPresenter(
|
||||||
bankAccount.addUnbookedTransactions(response.unbookedTransactions)
|
bankAccount.addUnbookedTransactions(response.unbookedTransactions)
|
||||||
|
|
||||||
response.balance?.let {
|
response.balance?.let {
|
||||||
bankAccount.balance = it
|
updateBalance(bankAccount, it)
|
||||||
}
|
}
|
||||||
|
|
||||||
persistAccount(bankAccount.customer) // only needed because of balance
|
|
||||||
persistAccountTransactions(bankAccount, response.bookedTransactions, response.unbookedTransactions)
|
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 {
|
open fun formatAmount(amount: BigDecimal): String {
|
||||||
return amount.format(2)
|
return amount.format(2)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue