Added convenience methods for getAccountData() and transferMony()
This commit is contained in:
parent
8d9855efe8
commit
61eb739613
|
@ -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()) {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) }
|
||||
}
|
|
@ -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) }
|
||||
}
|
Loading…
Reference in New Issue