diff --git a/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/Presenter.kt b/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/Presenter.kt index 17ec11c2..53dfc3a1 100644 --- a/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/Presenter.kt +++ b/SampleApplications/AndroidApp/src/main/java/net/codinux/banking/fints4k/android/Presenter.kt @@ -36,7 +36,7 @@ open class Presenter { open fun retrieveAccountData(bankCode: String, loginName: String, password: String, retrievedResult: (GetAccountDataResponse) -> Unit) { GlobalScope.launch(Dispatchers.IO) { - val response = fintsClient.getAccountData(GetAccountDataParameter(bankCode, loginName, password)) + val response = fintsClient.getAccountDataAsync(GetAccountDataParameter(bankCode, loginName, password)) log.info("Retrieved response from ${response.customerAccount?.bankName} for ${response.customerAccount?.customerName}") withContext(Dispatchers.Main) { diff --git a/SampleApplications/WebApp/src/main/kotlin/Presenter.kt b/SampleApplications/WebApp/src/main/kotlin/Presenter.kt index 9557c4fd..687ad197 100644 --- a/SampleApplications/WebApp/src/main/kotlin/Presenter.kt +++ b/SampleApplications/WebApp/src/main/kotlin/Presenter.kt @@ -34,7 +34,7 @@ open class Presenter { open fun retrieveAccountData(bankCode: String, loginName: String, password: String, retrievedResult: (GetAccountDataResponse) -> Unit) { GlobalScope.launch(Dispatchers.Unconfined) { - val response = fintsClient.getAccountData(GetAccountDataParameter(bankCode, loginName, password)) + val response = fintsClient.getAccountDataAsync(GetAccountDataParameter(bankCode, loginName, password)) log.info("Retrieved response from ${response.customerAccount?.bankName} for ${response.customerAccount?.customerName}") diff --git a/SampleApplications/iOSApp/fints4k iOS/fints4k iOS/Presenter.swift b/SampleApplications/iOSApp/fints4k iOS/fints4k iOS/Presenter.swift index 327819c5..92b23780 100644 --- a/SampleApplications/iOSApp/fints4k iOS/fints4k iOS/Presenter.swift +++ b/SampleApplications/iOSApp/fints4k iOS/fints4k iOS/Presenter.swift @@ -19,7 +19,7 @@ class Presenter : ObservableObject { func getAccountData(_ bankCode: String, _ customerId: String, _ pin: String, _ finTs3ServerAddress: String, _ callback: @escaping (GetAccountDataResponse) -> Void) { - self.fintsClient.getAccountData(parameter: GetAccountDataParameter(bankCode: bankCode, customerId: customerId, pin: pin, finTs3ServerAddress: finTs3ServerAddress), callback: callback) + self.fintsClient.getAccountDataAsync(parameter: GetAccountDataParameter(bankCode: bankCode, customerId: customerId, pin: pin, finTs3ServerAddress: finTs3ServerAddress), callback: callback) } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt index 3b3364a8..ca8af7e3 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt @@ -37,11 +37,11 @@ open class FinTsClient @JvmOverloads constructor( protected open val mapper = FinTsModelMapper() - open suspend fun getAccountData(bankCode: String, loginName: String, password: String): GetAccountDataResponse { - return getAccountData(GetAccountDataParameter(bankCode, loginName, password)) + open suspend fun getAccountDataAsync(bankCode: String, loginName: String, password: String): GetAccountDataResponse { + return getAccountDataAsync(GetAccountDataParameter(bankCode, loginName, password)) } - open suspend fun getAccountData(param: GetAccountDataParameter): GetAccountDataResponse { + open suspend fun getAccountDataAsync(param: GetAccountDataParameter): GetAccountDataResponse { val finTsServerAddress = finTsServerAddressFinder.findFinTsServerAddress(param.bankCode) if (finTsServerAddress.isNullOrBlank()) { return GetAccountDataResponse(ErrorCode.BankDoesNotSupportFinTs3, "Either bank does not FinTS 3.0 or we don't know its FinTS server address", null, listOf()) diff --git a/fints4k/src/iosMain/kotlin/net/dankito/banking/fints/iOSFinTsClient.kt b/fints4k/src/iosMain/kotlin/net/dankito/banking/fints/iOSFinTsClient.kt index 0723dfd8..7e46f1ad 100644 --- a/fints4k/src/iosMain/kotlin/net/dankito/banking/fints/iOSFinTsClient.kt +++ b/fints4k/src/iosMain/kotlin/net/dankito/banking/fints/iOSFinTsClient.kt @@ -20,9 +20,9 @@ open class iOSFinTsClient( } - open fun getAccountData(parameter: GetAccountDataParameter, callback: (GetAccountDataResponse) -> Unit) { + open fun getAccountDataAsync(parameter: GetAccountDataParameter, callback: (GetAccountDataResponse) -> Unit) { GlobalScope.launch(Dispatchers.Main) { // do not block UI thread as with runBlocking { } but stay on UI thread as passing mutable state between threads currently doesn't work in Kotlin/Native - callback(fintsClient.getAccountData(parameter)) + callback(fintsClient.getAccountDataAsync(parameter)) } } diff --git a/fints4k/src/jvmMain/kotlin/net/dankito/banking/fints/FinTsClientExtensions.kt b/fints4k/src/jvmMain/kotlin/net/dankito/banking/fints/FinTsClientExtensions.kt new file mode 100644 index 00000000..18a01138 --- /dev/null +++ b/fints4k/src/jvmMain/kotlin/net/dankito/banking/fints/FinTsClientExtensions.kt @@ -0,0 +1,14 @@ +package net.dankito.banking.fints + +import kotlinx.coroutines.runBlocking +import net.dankito.banking.client.model.parameter.GetAccountDataParameter +import net.dankito.banking.client.model.response.GetAccountDataResponse + + +fun FinTsClient.getAccountData(bankCode: String, loginName: String, password: String): GetAccountDataResponse { + return runBlocking { getAccountDataAsync(bankCode, loginName, password) } +} + +fun FinTsClient.getAccountData(param: GetAccountDataParameter): GetAccountDataResponse { + return runBlocking { getAccountDataAsync(param) } +} \ No newline at end of file diff --git a/fints4k/src/nativeMain/kotlin/Application.kt b/fints4k/src/nativeMain/kotlin/Application.kt index 979853ac..07c2c955 100644 --- a/fints4k/src/nativeMain/kotlin/Application.kt +++ b/fints4k/src/nativeMain/kotlin/Application.kt @@ -5,6 +5,7 @@ import net.dankito.banking.client.model.CustomerAccount import net.dankito.banking.client.model.parameter.GetAccountDataParameter import net.dankito.banking.fints.FinTsClient import net.dankito.banking.fints.callback.SimpleFinTsClientCallback +import net.dankito.banking.fints.getAccountData import net.dankito.banking.fints.model.TanChallenge import net.dankito.utils.multiplatform.extensions.* import platform.posix.exit @@ -22,20 +23,18 @@ fun main(args: Array) { class Application { fun retrieveAccountData(bankCode: String, loginName: String, password: String) { - runBlocking { - val client = FinTsClient(SimpleFinTsClientCallback { tanChallenge -> enterTan(tanChallenge) }) + val client = FinTsClient(SimpleFinTsClientCallback { tanChallenge -> enterTan(tanChallenge) }) - val response = client.getAccountData(GetAccountDataParameter(bankCode, loginName, password)) + val response = client.getAccountData(GetAccountDataParameter(bankCode, loginName, password)) - if (response.error != null) { - println("An error occurred: ${response.error}${response.errorMessage?.let { " $it" }}") - } + if (response.error != null) { + println("An error occurred: ${response.error}${response.errorMessage?.let { " $it" }}") + } - response.customerAccount?.let { account -> - println("Retrieved response from ${account.bankName} for ${account.customerName}") + response.customerAccount?.let { account -> + println("Retrieved response from ${account.bankName} for ${account.customerName}") - displayRetrievedAccountData(account) - } + displayRetrievedAccountData(account) } } diff --git a/fints4k/src/nativeMain/kotlin/net.dankito.banking.fints/FinTsClientExtensions.kt b/fints4k/src/nativeMain/kotlin/net.dankito.banking.fints/FinTsClientExtensions.kt new file mode 100644 index 00000000..18a01138 --- /dev/null +++ b/fints4k/src/nativeMain/kotlin/net.dankito.banking.fints/FinTsClientExtensions.kt @@ -0,0 +1,14 @@ +package net.dankito.banking.fints + +import kotlinx.coroutines.runBlocking +import net.dankito.banking.client.model.parameter.GetAccountDataParameter +import net.dankito.banking.client.model.response.GetAccountDataResponse + + +fun FinTsClient.getAccountData(bankCode: String, loginName: String, password: String): GetAccountDataResponse { + return runBlocking { getAccountDataAsync(bankCode, loginName, password) } +} + +fun FinTsClient.getAccountData(param: GetAccountDataParameter): GetAccountDataResponse { + return runBlocking { getAccountDataAsync(param) } +} \ No newline at end of file