Implemented automatically fetching account transactions after a successful cash transfer

This commit is contained in:
dankito 2020-05-25 01:03:51 +02:00
parent 614074b9b9
commit a8eb748f57
1 changed files with 14 additions and 4 deletions

View File

@ -297,14 +297,18 @@ open class BankingPresenter(
clientsForAccounts.keys.forEach { account ->
account.bankAccounts.forEach { bankAccount ->
if (bankAccount.supportsRetrievingAccountTransactions) {
val fromDate = bankAccount.lastRetrievedTransactionsTimestamp?.let { Date(it.time - OneDayMillis) } // one day before last received transactions
fetchAccountTransactionsAsync(bankAccount, fromDate, abortIfTanIsRequired, callback)
updateBankAccountTransactionsAsync(bankAccount, abortIfTanIsRequired, callback)
}
}
}
}
protected open fun updateBankAccountTransactionsAsync(bankAccount: BankAccount, abortIfTanIsRequired: Boolean, callback: (GetTransactionsResponse) -> Unit) {
val fromDate = bankAccount.lastRetrievedTransactionsTimestamp?.let { Date(it.time - OneDayMillis) } // one day before last received transactions
fetchAccountTransactionsAsync(bankAccount, fromDate, abortIfTanIsRequired, callback)
}
protected open fun retrievedAccountTransactions(bankAccount: BankAccount, startDate: Date, response: GetTransactionsResponse) {
if (response.isSuccessful) {
bankAccount.lastRetrievedTransactionsTimestamp = startDate
@ -361,7 +365,13 @@ open class BankingPresenter(
open fun transferMoneyAsync(bankAccount: BankAccount, data: TransferMoneyData, callback: (BankingClientResponse) -> Unit) {
getClientForAccount(bankAccount.account)?.let { client ->
client.transferMoneyAsync(data, bankAccount, callback)
client.transferMoneyAsync(data, bankAccount) { response ->
if (response.isSuccessful) {
updateBankAccountTransactionsAsync(bankAccount, true) { }
}
callback(response)
}
}
}