diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IBankingClient.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IBankingClient.kt index 5a79cfa5..1a122888 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IBankingClient.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/IBankingClient.kt @@ -1,6 +1,7 @@ package net.dankito.banking.ui import net.dankito.banking.ui.model.BankAccount +import net.dankito.banking.ui.model.Customer import net.dankito.banking.ui.model.MessageLogEntry import net.dankito.banking.ui.model.parameters.GetTransactionsParameter import net.dankito.banking.ui.model.parameters.TransferMoneyData @@ -24,4 +25,7 @@ interface IBankingClient { fun transferMoneyAsync(data: TransferMoneyData, callback: (BankingClientResponse) -> Unit) + + fun dataChanged(customer: Customer) + } \ No newline at end of file diff --git a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt index 13633ddf..6893d2d7 100644 --- a/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/commonMain/kotlin/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -394,6 +394,8 @@ open class BankingPresenter( open fun accountUpdated(bank: Customer) { persistAccount(bank) + + getBankingClientForAccount(bank)?.dataChanged(bank) } open fun accountUpdated(account: BankAccount) { diff --git a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt index da739efc..96d6e63b 100644 --- a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt +++ b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/fints4kBankingClient.kt @@ -65,7 +65,7 @@ open class fints4kBankingClient( protected open fun handleAddAccountResponse(response: net.dankito.banking.fints.response.client.AddAccountResponse, callback: (AddAccountResponse) -> Unit) { - mapper.mapCustomer(customer, bank) + mapper.mapBank(customer, bank) val mappedResponse = mapper.mapResponse(customer, response) saveData() @@ -132,6 +132,11 @@ open class fints4kBankingClient( } + override fun dataChanged(customer: Customer) { + mapper.mapChangesFromUiToClientModel(customer, bank) + } + + protected open fun findAccountForBankAccount(bankAccount: BankAccount, findAccountResult: (AccountData?, error: String?) -> Unit) { val mappedAccount = mapper.findAccountForBankAccount(bank, bankAccount) diff --git a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt index f30c0f8d..157bf45b 100644 --- a/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt +++ b/ui/fints4kBankingClient/src/commonMain/kotlin/net/dankito/banking/mapper/fints4kModelMapper.kt @@ -60,7 +60,7 @@ open class fints4kModelMapper { } - open fun mapCustomer(customer: Customer, bank: BankData) { + open fun mapBank(customer: Customer, bank: BankData) { customer.bankCode = bank.bankCode customer.customerId = bank.customerId customer.password = bank.pin @@ -75,6 +75,18 @@ open class fints4kModelMapper { updateTanMediaAndProcedures(customer, bank) } + /** + * In UI only customerId, password, (bankCode,) and selected TAN procedure can be set + */ + open fun mapChangesFromUiToClientModel(customer: Customer, bank: BankData) { + bank.customerId = customer.customerId + bank.pin = customer.password + + bank.bankCode = customer.bankCode + + bank.selectedTanProcedure = findTanProcedure(bank, customer.selectedTanProcedure) ?: bank.selectedTanProcedure + } + // TODO: move to a fints4k internal mapper open fun updateCustomer(bank: BankData, updatedBank: BankData) { bank.pin = updatedBank.pin @@ -284,6 +296,14 @@ open class fints4kModelMapper { return customer.supportedTanProcedures.firstOrNull { it.bankInternalProcedureCode == tanProcedure.securityFunction.code } } + protected open fun findTanProcedure(bank: BankData, tanProcedure: TanProcedure?): net.dankito.banking.fints.model.TanProcedure? { + if (tanProcedure == null) { + return null + } + + return bank.tanProceduresAvailableForUser.firstOrNull { it.securityFunction.code == tanProcedure.bankInternalProcedureCode } + } + open fun mapTanMediums(tanMediums: List): List { return tanMediums.map { mapTanMedium(it) } diff --git a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt index a7a0f417..4ce97fbc 100644 --- a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt +++ b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt @@ -48,7 +48,7 @@ open class hbci4jBankingClient( } - protected val credentials = AccountCredentials(customer.bankCode, customer.customerId, customer.password) + protected val credentials = AccountCredentials(customer) protected val mapper = hbci4jModelMapper() @@ -271,6 +271,17 @@ open class hbci4jBankingClient( } + override fun dataChanged(customer: Customer) { + if (customer.bankCode != credentials.bankCode || customer.customerId != credentials.customerId || customer.password != credentials.password) { + getPassportFile(credentials).delete() + } + + credentials.bankCode = customer.bankCode + credentials.customerId = customer.customerId + credentials.password = customer.password + } + + protected open fun connect(): ConnectResult { return connect(credentials, HBCIVersion.HBCI_300) } @@ -286,10 +297,7 @@ open class hbci4jBankingClient( // Die Datei kann problemlos geloescht werden. Sie wird beim naechsten mal automatisch neu erzeugt, // wenn der Parameter "client.passport.PinTan.init" den Wert "1" hat (siehe unten). // Wir speichern die Datei der Einfachheit halber im aktuellen Verzeichnis. - val hbciClientFolder = File(dataFolder, "hbci4j-client") - hbciClientFolder.mkdirs() - - val passportFile = File(hbciClientFolder, "passport_${credentials.bankCode}_${credentials.customerId}.dat") + val passportFile = getPassportFile(credentials) // Wir setzen die Kernel-Parameter zur Laufzeit. Wir koennten sie alternativ // auch oben in "props" setzen. @@ -336,6 +344,13 @@ open class hbci4jBankingClient( return ConnectResult(true, null, handle, passport) } + protected open fun getPassportFile(credentials: AccountCredentials): File { + val hbciClientFolder = File(dataFolder, "hbci4j-client") + hbciClientFolder.mkdirs() + + return File(hbciClientFolder, "passport_${credentials.bankCode}_${credentials.customerId}.dat") + } + protected open fun closeConnection(connection: ConnectResult) { closeConnection(connection.handle, connection.passport) } diff --git a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/model/AccountCredentials.kt b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/model/AccountCredentials.kt index 5e1f1d26..88b21eb6 100644 --- a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/model/AccountCredentials.kt +++ b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/model/AccountCredentials.kt @@ -1,8 +1,14 @@ package net.dankito.banking.model +import net.dankito.banking.ui.model.Customer + open class AccountCredentials( - val bankCode: String, - val customerId: String, + var bankCode: String, + var customerId: String, var password: String -) \ No newline at end of file +) { + + constructor(bank: Customer) : this(bank.bankCode, bank.customerId, bank.password) + +} \ No newline at end of file