Added optional method messageLogAdded() to BankingClientCallback and enabled passing FinTsClientConfiguration on to FinTsClient

This commit is contained in:
dankito 2024-08-23 17:36:10 +02:00
parent 1abf4bc389
commit 1a484e78b8
5 changed files with 34 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package net.codinux.banking.client
import net.codinux.banking.client.model.MessageLogEntry
import net.codinux.banking.client.model.tan.EnterTanResult
import net.codinux.banking.client.model.tan.TanChallenge
@ -7,4 +8,11 @@ interface BankingClientCallback {
fun enterTan(tanChallenge: TanChallenge, callback: (EnterTanResult) -> Unit)
/**
* An optional method, for sure not available for all client implementations (currently only for FinTs4kBankingClient).
*
* Gets fired when a FinTS message get sent to bank server, a FinTS message is received from bank server or an error occurred.
*/
fun messageLogAdded(messageLogEntry: MessageLogEntry)
}

View File

@ -1,9 +1,11 @@
package net.codinux.banking.client
import net.codinux.banking.client.model.MessageLogEntry
import net.codinux.banking.client.model.tan.EnterTanResult
import net.codinux.banking.client.model.tan.TanChallenge
open class SimpleBankingClientCallback(
protected val messageLogAdded: ((MessageLogEntry) -> Unit)? = null,
protected val enterTan: ((tanChallenge: TanChallenge, callback: (EnterTanResult) -> Unit) -> Unit)? = null
) : BankingClientCallback {
@ -15,4 +17,8 @@ open class SimpleBankingClientCallback(
}
}
override fun messageLogAdded(messageLogEntry: MessageLogEntry) {
messageLogAdded?.invoke(messageLogEntry)
}
}

View File

@ -1,6 +1,7 @@
package net.codinux.banking.client.fints4k
import net.codinux.banking.client.BankingClientCallback
import net.codinux.banking.client.model.MessageLogEntryType
import net.codinux.banking.fints.callback.FinTsClientCallback
import net.codinux.banking.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium
import net.codinux.banking.fints.model.BankData
@ -32,6 +33,12 @@ open class BridgeFintTsToBankingClientCallback(
}
override fun messageLogAdded(messageLogEntry: MessageLogEntry) {
val mapped = net.codinux.banking.client.model.MessageLogEntry(
MessageLogEntryType.valueOf(messageLogEntry.type.name),
messageLogEntry.message, messageLogEntry.messageTrace,
messageLogEntry.error, messageLogEntry.time
)
bankingClientCallback.messageLogAdded(mapped)
}
}

View File

@ -7,14 +7,19 @@ import net.codinux.banking.client.model.request.GetAccountDataRequest
import net.codinux.banking.client.model.response.GetAccountDataResponse
import net.codinux.banking.client.model.response.Response
import net.codinux.banking.fints.FinTsClient
import net.codinux.banking.fints.config.FinTsClientConfiguration
open class FinTs4kBankingClient(
config: FinTsClientConfiguration = FinTsClientConfiguration(),
callback: BankingClientCallback
) : BankingClient {
constructor(callback: BankingClientCallback) : this(FinTsClientConfiguration(), callback)
private val mapper = FinTs4kMapper()
private val client = FinTsClient(BridgeFintTsToBankingClientCallback(callback, mapper))
private val client = FinTsClient(config, BridgeFintTsToBankingClientCallback(callback, mapper))
override suspend fun getAccountDataAsync(request: GetAccountDataRequest): Response<GetAccountDataResponse> {

View File

@ -3,11 +3,15 @@ package net.codinux.banking.client.fints4k
import net.codinux.banking.client.BankingClientCallback
import net.codinux.banking.client.BankingClientForCustomerBase
import net.codinux.banking.client.model.AccountCredentials
import net.codinux.banking.fints.config.FinTsClientConfiguration
open class FinTs4kBankingClientForCustomer(credentials: AccountCredentials, callback: BankingClientCallback)
: BankingClientForCustomerBase(credentials, FinTs4kBankingClient(callback)) {
open class FinTs4kBankingClientForCustomer(credentials: AccountCredentials, config: FinTsClientConfiguration = FinTsClientConfiguration(), callback: BankingClientCallback)
: BankingClientForCustomerBase(credentials, FinTs4kBankingClient(config, callback)) {
constructor(bankCode: String, loginName: String, password: String, callback: BankingClientCallback)
: this(AccountCredentials(bankCode, loginName, password), callback)
: this(bankCode, loginName, password, FinTsClientConfiguration(), callback)
constructor(bankCode: String, loginName: String, password: String, config: FinTsClientConfiguration = FinTsClientConfiguration(), callback: BankingClientCallback)
: this(AccountCredentials(bankCode, loginName, password), config, callback)
}