From 61eb739613ae08cc92f945d0437d4cc656774c8f Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 25 Feb 2022 20:45:33 +0100 Subject: [PATCH] Added convenience methods for getAccountData() and transferMony() --- .../net/dankito/banking/fints/FinTsClient.kt | 5 +++ .../dankito/banking/fints/iOSFinTsClient.kt | 34 +++++++++++++++++-- .../banking/fints/FinTsClientExtensions.kt | 13 +++++++ .../FinTsClientExtensions.kt | 6 ++++ 4 files changed, 56 insertions(+), 2 deletions(-) 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 6211f4ba..18cec50e 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt @@ -116,6 +116,11 @@ open class FinTsClient @JvmOverloads constructor( } + open suspend fun transferMoneyAsync(bankCode: String, loginName: String, password: String, recipientName: String, recipientAccountIdentifier: String, + amount: Money, reference: String? = null): TransferMoneyResponse { + return transferMoneyAsync(TransferMoneyParameter(bankCode, loginName, password, null, recipientName, recipientAccountIdentifier, null, amount, reference)) + } + open suspend fun transferMoneyAsync(param: TransferMoneyParameter): TransferMoneyResponse { val finTsServerAddress = finTsServerAddressFinder.findFinTsServerAddress(param.bankCode) if (finTsServerAddress.isNullOrBlank()) { 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 7e46f1ad..dc270ccf 100644 --- a/fints4k/src/iosMain/kotlin/net/dankito/banking/fints/iOSFinTsClient.kt +++ b/fints4k/src/iosMain/kotlin/net/dankito/banking/fints/iOSFinTsClient.kt @@ -2,8 +2,11 @@ package net.dankito.banking.fints import kotlinx.coroutines.* import net.dankito.banking.client.model.parameter.GetAccountDataParameter +import net.dankito.banking.client.model.parameter.TransferMoneyParameter import net.dankito.banking.client.model.response.GetAccountDataResponse +import net.dankito.banking.client.model.response.TransferMoneyResponse import net.dankito.banking.fints.callback.FinTsClientCallback +import net.dankito.banking.fints.model.Money import net.dankito.banking.fints.webclient.IWebClient open class iOSFinTsClient( @@ -20,9 +23,36 @@ open class iOSFinTsClient( } - open fun getAccountDataAsync(parameter: GetAccountDataParameter, callback: (GetAccountDataResponse) -> Unit) { + open fun getAccountDataAsync(bankCode: String, loginName: String, password: String, callback: (GetAccountDataResponse) -> Unit) { + dispatchToCoroutine { + callback(fintsClient.getAccountDataAsync(bankCode, loginName, password)) + } + } + + open fun getAccountDataAsync(param: GetAccountDataParameter, callback: (GetAccountDataResponse) -> Unit) { + dispatchToCoroutine { + callback(fintsClient.getAccountDataAsync(param)) + } + } + + + open suspend fun transferMoneyAsync(bankCode: String, loginName: String, password: String, recipientName: String, recipientAccountIdentifier: String, + amount: Money, reference: String? = null, callback: (TransferMoneyResponse) -> Unit) { + dispatchToCoroutine { + callback(fintsClient.transferMoneyAsync(bankCode, loginName, password, recipientName, recipientAccountIdentifier, amount)) + } + } + + open fun transferMoneyAsync(param: TransferMoneyParameter, callback: (TransferMoneyResponse) -> Unit) { + dispatchToCoroutine { + callback(fintsClient.transferMoneyAsync(param)) + } + } + + + protected open fun dispatchToCoroutine(action: suspend () -> 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.getAccountDataAsync(parameter)) + action() } } diff --git a/fints4k/src/jvmMain/kotlin/net/dankito/banking/fints/FinTsClientExtensions.kt b/fints4k/src/jvmMain/kotlin/net/dankito/banking/fints/FinTsClientExtensions.kt index 18a01138..f86e3c54 100644 --- a/fints4k/src/jvmMain/kotlin/net/dankito/banking/fints/FinTsClientExtensions.kt +++ b/fints4k/src/jvmMain/kotlin/net/dankito/banking/fints/FinTsClientExtensions.kt @@ -2,7 +2,10 @@ package net.dankito.banking.fints import kotlinx.coroutines.runBlocking import net.dankito.banking.client.model.parameter.GetAccountDataParameter +import net.dankito.banking.client.model.parameter.TransferMoneyParameter import net.dankito.banking.client.model.response.GetAccountDataResponse +import net.dankito.banking.client.model.response.TransferMoneyResponse +import net.dankito.banking.fints.model.Money fun FinTsClient.getAccountData(bankCode: String, loginName: String, password: String): GetAccountDataResponse { @@ -11,4 +14,14 @@ fun FinTsClient.getAccountData(bankCode: String, loginName: String, password: St fun FinTsClient.getAccountData(param: GetAccountDataParameter): GetAccountDataResponse { return runBlocking { getAccountDataAsync(param) } +} + + +fun FinTsClient.transferMoney(bankCode: String, loginName: String, password: String, recipientName: String, recipientAccountIdentifier: String, + amount: Money, reference: String? = null): TransferMoneyResponse { + return runBlocking { transferMoneyAsync(bankCode, loginName, password, recipientName, recipientAccountIdentifier, amount, reference) } +} + +fun FinTsClient.transferMoney(param: TransferMoneyParameter): TransferMoneyResponse { + return runBlocking { transferMoneyAsync(param) } } \ No newline at end of file diff --git a/fints4k/src/nativeMain/kotlin/net.dankito.banking.fints/FinTsClientExtensions.kt b/fints4k/src/nativeMain/kotlin/net.dankito.banking.fints/FinTsClientExtensions.kt index f196d057..c272cb4b 100644 --- a/fints4k/src/nativeMain/kotlin/net.dankito.banking.fints/FinTsClientExtensions.kt +++ b/fints4k/src/nativeMain/kotlin/net.dankito.banking.fints/FinTsClientExtensions.kt @@ -5,6 +5,7 @@ import net.dankito.banking.client.model.parameter.GetAccountDataParameter import net.dankito.banking.client.model.parameter.TransferMoneyParameter import net.dankito.banking.client.model.response.GetAccountDataResponse import net.dankito.banking.client.model.response.TransferMoneyResponse +import net.dankito.banking.fints.model.Money fun FinTsClient.getAccountData(bankCode: String, loginName: String, password: String): GetAccountDataResponse { @@ -16,6 +17,11 @@ fun FinTsClient.getAccountData(param: GetAccountDataParameter): GetAccountDataRe } +fun FinTsClient.transferMoney(bankCode: String, loginName: String, password: String, recipientName: String, recipientAccountIdentifier: String, + amount: Money, reference: String? = null): TransferMoneyResponse { + return runBlocking { transferMoneyAsync(bankCode, loginName, password, recipientName, recipientAccountIdentifier, amount, reference) } +} + fun FinTsClient.transferMoney(param: TransferMoneyParameter): TransferMoneyResponse { return runBlocking { transferMoneyAsync(param) } } \ No newline at end of file