diff --git a/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClient.kt b/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClient.kt index 655f73f7..fb58a6cb 100644 --- a/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClient.kt +++ b/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClient.kt @@ -34,8 +34,8 @@ interface BankingClient { /** * Convenience wrapper around [getAccountDataAsync]. - * Updates account's transactions beginning from [BankAccount.lastTransactionRetrievalTime]. - * This may requires TAN if [BankAccount.lastTransactionRetrievalTime] is older than 90 days. + * Updates account's transactions beginning from [BankAccount.lastTransactionsRetrievalTime]. + * This may requires TAN if [BankAccount.lastTransactionsRetrievalTime] is older than 90 days. */ suspend fun updateAccountTransactionsAsync(user: UserAccount, accounts: List? = null): Response> diff --git a/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClientForUser.kt b/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClientForUser.kt index f7a6a6a2..407793d1 100644 --- a/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClientForUser.kt +++ b/BankingClient/src/commonMain/kotlin/net/codinux/banking/client/BankingClientForUser.kt @@ -34,8 +34,8 @@ interface BankingClientForUser { /** * Convenience wrapper around [getAccountDataAsync]. - * Updates account's transactions beginning from [BankAccount.lastTransactionRetrievalTime]. - * This may requires TAN if [BankAccount.lastTransactionRetrievalTime] is older than 90 days. + * Updates account's transactions beginning from [BankAccount.lastTransactionsRetrievalTime]. + * This may requires TAN if [BankAccount.lastTransactionsRetrievalTime] is older than 90 days. */ suspend fun updateAccountTransactionsAsync(): Response> diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/BankAccount.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/BankAccount.kt index f9d06c5c..d469aecf 100644 --- a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/BankAccount.kt +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/BankAccount.kt @@ -1,7 +1,7 @@ package net.codinux.banking.client.model +import kotlinx.datetime.Instant import kotlinx.datetime.LocalDate -import kotlinx.datetime.LocalDateTime import net.codinux.banking.client.model.config.JsonIgnore import net.codinux.banking.client.model.config.NoArgConstructor @@ -21,8 +21,9 @@ open class BankAccount( // var balance: BigDecimal = BigDecimal.ZERO, var balance: Amount = Amount.Zero, // TODO: add a BigDecimal library + + open var lastTransactionsRetrievalTime: Instant? = null, var retrievedTransactionsFrom: LocalDate? = null, - open var lastTransactionRetrievalTime: LocalDateTime? = null, var haveAllTransactionsBeenRetrieved: Boolean = false, val countDaysForWhichTransactionsAreKept: Int? = null, diff --git a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/GetTransactionsResponse.kt b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/GetTransactionsResponse.kt index 5f054c55..8dbc109e 100644 --- a/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/GetTransactionsResponse.kt +++ b/BankingClientModel/src/commonMain/kotlin/net/codinux/banking/client/model/response/GetTransactionsResponse.kt @@ -1,7 +1,7 @@ package net.codinux.banking.client.model.response +import kotlinx.datetime.Instant import kotlinx.datetime.LocalDate -import kotlinx.datetime.LocalDateTime import net.codinux.banking.client.model.AccountTransaction import net.codinux.banking.client.model.Amount import net.codinux.banking.client.model.BankAccount @@ -14,7 +14,7 @@ open class GetTransactionsResponse( val balance: Amount? = null, val bookedTransactions: List, val unbookedTransactions: List, - val transactionRetrievalTime: LocalDateTime, + val transactionsRetrievalTime: Instant, val retrievedTransactionsFrom: LocalDate? = null, val retrievedTransactionsTo: LocalDate? = null ) { diff --git a/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kMapper.kt b/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kMapper.kt index c7806d8c..92933592 100644 --- a/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kMapper.kt +++ b/FinTs4jBankingClient/src/commonMain/kotlin/net/codinux/banking/client/fints4k/FinTs4kMapper.kt @@ -1,6 +1,8 @@ package net.codinux.banking.client.fints4k -import kotlinx.datetime.LocalDateTime +import kotlinx.datetime.Clock +import kotlinx.datetime.TimeZone +import kotlinx.datetime.toLocalDateTime import net.codinux.banking.client.model.* import net.codinux.banking.client.model.AccountTransaction import net.codinux.banking.client.model.Amount @@ -12,7 +14,7 @@ import net.codinux.banking.client.model.tan.TanChallenge import net.codinux.banking.client.model.tan.TanImage import net.codinux.banking.client.model.tan.TanMethod import net.codinux.banking.client.model.tan.TanMethodType -import net.codinux.banking.fints.extensions.nowAtEuropeBerlin +import net.codinux.banking.fints.extensions.EuropeBerlin import net.dankito.banking.client.model.BankAccountIdentifierImpl import net.dankito.banking.client.model.parameter.GetAccountDataParameter import net.dankito.banking.client.model.parameter.RetrieveTransactions @@ -45,7 +47,7 @@ open class FinTs4kMapper { open fun mapToUpdateAccountTransactionsParameter(user: UserAccount, account: BankAccount, finTsModel: BankData?): GetAccountDataParameter { val accountIdentifier = BankAccountIdentifierImpl(account.identifier, account.subAccountNumber, account.iban) - val from = account.lastTransactionRetrievalTime?.date + val from = account.lastTransactionsRetrievalTime?.toLocalDateTime(TimeZone.EuropeBerlin)?.date // TODO: in case lastTransactionsUpdateTime is not set, this would retrieve all transactions (and require a TAN im most cases) val retrieveTransactions = if (from != null) RetrieveTransactions.AccordingToRetrieveFromAndTo else RetrieveTransactions.OfLast90Days // val preferredTanMethods = listOf(mapTanMethodType(user.selectedTanMethod.type)) // TODO: currently we aren't saving TanMethods in database, re-enable as soon as TanMethods get saved val preferredTanMethods = emptyList() @@ -79,8 +81,12 @@ open class FinTs4kMapper { val finTsBankAccount = user?.accounts?.firstOrNull { it.identifier == account.identifier && it.subAccountNumber == account.subAccountNumber } if (getAccountDataResponse.successful && user != null && finTsBankAccount != null) { + if (finTsBankAccount.lastTransactionsRetrievalTime != null) { + account.lastTransactionsRetrievalTime = finTsBankAccount.lastTransactionsRetrievalTime + } + Response.success(GetTransactionsResponse(account, mapAmount(finTsBankAccount.balance), mapBookedTransactions(finTsBankAccount), emptyList(), - finTsBankAccount.lastTransactionRetrievalTime ?: LocalDateTime.nowAtEuropeBerlin(), param.retrieveTransactionsFrom, param.retrieveTransactionsTo)) + finTsBankAccount.lastTransactionsRetrievalTime ?: Clock.System.now(), param.retrieveTransactionsFrom, param.retrieveTransactionsTo)) } else { mapError(getAccountDataResponse) } @@ -122,7 +128,7 @@ open class FinTs4kMapper { account.identifier, account.accountHolderName, mapAccountType(account.type), account.iban, account.subAccountNumber, account.productName, account.currency, account.accountLimit, account.isAccountTypeSupportedByApplication, mapFeatures(account), - mapAmount(account.balance), account.retrievedTransactionsFrom, account.lastTransactionRetrievalTime, + mapAmount(account.balance), account.lastTransactionsRetrievalTime, account.retrievedTransactionsFrom, // TODO: map haveAllTransactionsBeenRetrieved countDaysForWhichTransactionsAreKept = account.countDaysForWhichTransactionsAreKept, bookedTransactions = mapBookedTransactions(account).toMutableList() diff --git a/FinTs4jBankingClient/src/commonTest/kotlin/net/codinux/banking/client/fints4k/FinTs4kBankingClientTest.kt b/FinTs4jBankingClient/src/commonTest/kotlin/net/codinux/banking/client/fints4k/FinTs4kBankingClientTest.kt index b4865f29..6796eae8 100644 --- a/FinTs4jBankingClient/src/commonTest/kotlin/net/codinux/banking/client/fints4k/FinTs4kBankingClientTest.kt +++ b/FinTs4jBankingClient/src/commonTest/kotlin/net/codinux/banking/client/fints4k/FinTs4kBankingClientTest.kt @@ -19,7 +19,7 @@ class FinTs4kBankingClientTest { } - private val underTest = FinTs4KBankingClientForUser(bankCode, loginName, password, SimpleBankingClientCallback { tanChallenge, callback -> + private val underTest = FinTs4kBankingClientForUser(bankCode, loginName, password, SimpleBankingClientCallback { tanChallenge, callback -> })