Implemented setting preferredTanMethods for updateAccountTransactionsAsync() and transferMoneyAsync()
This commit is contained in:
parent
d1cc7b0eb0
commit
f8dd296b47
|
@ -8,6 +8,7 @@ import net.codinux.banking.client.model.response.GetAccountDataResponse
|
||||||
import net.codinux.banking.client.model.response.GetTransactionsResponse
|
import net.codinux.banking.client.model.response.GetTransactionsResponse
|
||||||
import net.codinux.banking.client.model.response.Response
|
import net.codinux.banking.client.model.response.Response
|
||||||
import net.codinux.banking.client.model.response.TransferMoneyResponse
|
import net.codinux.banking.client.model.response.TransferMoneyResponse
|
||||||
|
import net.codinux.banking.client.model.tan.TanMethodType
|
||||||
|
|
||||||
interface BankingClient {
|
interface BankingClient {
|
||||||
|
|
||||||
|
@ -41,7 +42,10 @@ interface BankingClient {
|
||||||
*
|
*
|
||||||
* Optionally specify which [accounts] should be updated. If not specified all accounts will be updated.
|
* Optionally specify which [accounts] should be updated. If not specified all accounts will be updated.
|
||||||
*/
|
*/
|
||||||
suspend fun updateAccountTransactionsAsync(bank: BankAccess, accounts: List<BankAccount>? = null): Response<List<GetTransactionsResponse>>
|
suspend fun updateAccountTransactionsAsync(
|
||||||
|
bank: BankAccess, accounts: List<BankAccount>? = null,
|
||||||
|
preferredTanMethodsIfSelectedTanMethodIsNotAvailable: List<TanMethodType>? = TanMethodType.TanMethodsPreferredByMostApplications
|
||||||
|
): Response<List<GetTransactionsResponse>>
|
||||||
|
|
||||||
|
|
||||||
suspend fun transferMoneyAsync(bankCode: String, loginName: String, password: String, recipientName: String,
|
suspend fun transferMoneyAsync(bankCode: String, loginName: String, password: String, recipientName: String,
|
||||||
|
|
|
@ -9,6 +9,7 @@ import net.codinux.banking.client.model.response.GetAccountDataResponse
|
||||||
import net.codinux.banking.client.model.response.GetTransactionsResponse
|
import net.codinux.banking.client.model.response.GetTransactionsResponse
|
||||||
import net.codinux.banking.client.model.response.Response
|
import net.codinux.banking.client.model.response.Response
|
||||||
import net.codinux.banking.client.model.response.TransferMoneyResponse
|
import net.codinux.banking.client.model.response.TransferMoneyResponse
|
||||||
|
import net.codinux.banking.client.model.tan.TanMethodType
|
||||||
|
|
||||||
interface BankingClientForUser {
|
interface BankingClientForUser {
|
||||||
|
|
||||||
|
@ -40,7 +41,10 @@ interface BankingClientForUser {
|
||||||
* Updates account's transactions beginning from [BankAccount.lastAccountUpdateTime].
|
* Updates account's transactions beginning from [BankAccount.lastAccountUpdateTime].
|
||||||
* This may requires TAN if [BankAccount.lastAccountUpdateTime] is older than 90 days.
|
* This may requires TAN if [BankAccount.lastAccountUpdateTime] is older than 90 days.
|
||||||
*/
|
*/
|
||||||
suspend fun updateAccountTransactionsAsync(accounts: List<BankAccount>? = null): Response<List<GetTransactionsResponse>>
|
suspend fun updateAccountTransactionsAsync(
|
||||||
|
accounts: List<BankAccount>? = null,
|
||||||
|
preferredTanMethodsIfSelectedTanMethodIsNotAvailable: List<TanMethodType>? = TanMethodType.TanMethodsPreferredByMostApplications
|
||||||
|
): Response<List<GetTransactionsResponse>>
|
||||||
|
|
||||||
|
|
||||||
suspend fun transferMoneyAsync(recipientName: String, recipientAccountIdentifier: String, amount: Amount, paymentReference: String? = null): Response<TransferMoneyResponse>
|
suspend fun transferMoneyAsync(recipientName: String, recipientAccountIdentifier: String, amount: Amount, paymentReference: String? = null): Response<TransferMoneyResponse>
|
||||||
|
|
|
@ -10,6 +10,7 @@ import net.codinux.banking.client.model.request.TransferMoneyRequest
|
||||||
import net.codinux.banking.client.model.request.TransferMoneyRequestForUser
|
import net.codinux.banking.client.model.request.TransferMoneyRequestForUser
|
||||||
import net.codinux.banking.client.model.response.GetTransactionsResponse
|
import net.codinux.banking.client.model.response.GetTransactionsResponse
|
||||||
import net.codinux.banking.client.model.response.Response
|
import net.codinux.banking.client.model.response.Response
|
||||||
|
import net.codinux.banking.client.model.tan.TanMethodType
|
||||||
|
|
||||||
abstract class BankingClientForUserBase(
|
abstract class BankingClientForUserBase(
|
||||||
protected val credentials: AccountCredentials,
|
protected val credentials: AccountCredentials,
|
||||||
|
@ -25,7 +26,7 @@ abstract class BankingClientForUserBase(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updateAccountTransactionsAsync(accounts: List<BankAccount>?): Response<List<GetTransactionsResponse>> =
|
override suspend fun updateAccountTransactionsAsync(accounts: List<BankAccount>?, preferredTanMethodsIfSelectedTanMethodIsNotAvailable: List<TanMethodType>?): Response<List<GetTransactionsResponse>> =
|
||||||
client.updateAccountTransactionsAsync(bank, accounts)
|
client.updateAccountTransactionsAsync(bank, accounts)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import net.codinux.banking.client.model.options.GetAccountDataOptions
|
||||||
import net.codinux.banking.client.model.request.GetAccountDataRequest
|
import net.codinux.banking.client.model.request.GetAccountDataRequest
|
||||||
import net.codinux.banking.client.model.request.TransferMoneyRequest
|
import net.codinux.banking.client.model.request.TransferMoneyRequest
|
||||||
import net.codinux.banking.client.model.request.TransferMoneyRequestForUser
|
import net.codinux.banking.client.model.request.TransferMoneyRequestForUser
|
||||||
|
import net.codinux.banking.client.model.tan.TanMethodType
|
||||||
|
|
||||||
/* BankingClient */
|
/* BankingClient */
|
||||||
|
|
||||||
|
@ -19,8 +20,8 @@ fun BankingClient.getAccountData(request: GetAccountDataRequest) = runBlocking {
|
||||||
getAccountDataAsync(request)
|
getAccountDataAsync(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BankingClient.updateAccountTransactions(bank: BankAccess, accounts: List<BankAccount>? = null) = runBlocking {
|
fun BankingClient.updateAccountTransactions(bank: BankAccess, accounts: List<BankAccount>? = null, preferredTanMethodsIfSelectedTanMethodIsNotAvailable: List<TanMethodType>? = TanMethodType.TanMethodsPreferredByMostApplications) = runBlocking {
|
||||||
updateAccountTransactionsAsync(bank, accounts)
|
updateAccountTransactionsAsync(bank, accounts, preferredTanMethodsIfSelectedTanMethodIsNotAvailable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,8 +45,8 @@ fun BankingClientForUser.getAccountData(options: GetAccountDataOptions) = runBlo
|
||||||
getAccountDataAsync(options)
|
getAccountDataAsync(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BankingClientForUser.updateAccountTransactions() = runBlocking {
|
fun BankingClientForUser.updateAccountTransactions(accounts: List<BankAccount>? = null, preferredTanMethodsIfSelectedTanMethodIsNotAvailable: List<TanMethodType>? = TanMethodType.TanMethodsPreferredByMostApplications) = runBlocking {
|
||||||
updateAccountTransactionsAsync()
|
updateAccountTransactionsAsync(accounts, preferredTanMethodsIfSelectedTanMethodIsNotAvailable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,9 @@ import net.codinux.banking.client.model.options.GetAccountDataOptions
|
||||||
import net.codinux.banking.client.model.request.GetAccountDataRequest
|
import net.codinux.banking.client.model.request.GetAccountDataRequest
|
||||||
import net.codinux.banking.client.model.request.TransferMoneyRequestForUser
|
import net.codinux.banking.client.model.request.TransferMoneyRequestForUser
|
||||||
import net.codinux.banking.client.model.response.*
|
import net.codinux.banking.client.model.response.*
|
||||||
|
import net.codinux.banking.client.model.tan.TanMethodType
|
||||||
import net.codinux.banking.fints.FinTsClient
|
import net.codinux.banking.fints.FinTsClient
|
||||||
import net.codinux.banking.fints.config.FinTsClientConfiguration
|
import net.codinux.banking.fints.config.FinTsClientConfiguration
|
||||||
import net.codinux.banking.fints.model.BankData
|
|
||||||
|
|
||||||
open class FinTs4kBankingClient(
|
open class FinTs4kBankingClient(
|
||||||
config: FinTsClientConfiguration = FinTsClientConfiguration(),
|
config: FinTsClientConfiguration = FinTsClientConfiguration(),
|
||||||
|
@ -35,12 +35,14 @@ open class FinTs4kBankingClient(
|
||||||
return mapper.map(response, request.bankInfo)
|
return mapper.map(response, request.bankInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun updateAccountTransactionsAsync(bank: BankAccess, accounts: List<BankAccount>?): Response<List<GetTransactionsResponse>> {
|
override suspend fun updateAccountTransactionsAsync(bank: BankAccess, accounts: List<BankAccount>?, preferredTanMethodsIfSelectedTanMethodIsNotAvailable: List<TanMethodType>?): Response<List<GetTransactionsResponse>> {
|
||||||
val accountsToRequest = (accounts ?: bank.accounts).filter { it.supportsAnyFeature(BankAccountFeatures.RetrieveBalance, BankAccountFeatures.RetrieveTransactions) }
|
val accountsToRequest = (accounts ?: bank.accounts).filter { it.supportsAnyFeature(BankAccountFeatures.RetrieveBalance, BankAccountFeatures.RetrieveTransactions) }
|
||||||
|
|
||||||
if (accountsToRequest.isNotEmpty()) {
|
if (accountsToRequest.isNotEmpty()) {
|
||||||
val responses = accountsToRequest.map { account ->
|
val responses = accountsToRequest.map { account ->
|
||||||
val parameter = mapper.mapToUpdateAccountTransactionsParameter(bank, account)
|
val preferredTanMethods = listOf(bank.selectedTanMethod.type) + (preferredTanMethodsIfSelectedTanMethodIsNotAvailable ?: emptyList())
|
||||||
|
|
||||||
|
val parameter = mapper.mapToUpdateAccountTransactionsParameter(bank, account, preferredTanMethods)
|
||||||
|
|
||||||
val response = client.getAccountDataAsync(parameter)
|
val response = client.getAccountDataAsync(parameter)
|
||||||
|
|
||||||
|
|
|
@ -62,18 +62,16 @@ open class FinTs4kMapper {
|
||||||
bank.serverAddress, bank.bic, bank.name
|
bank.serverAddress, bank.bic, bank.name
|
||||||
)
|
)
|
||||||
|
|
||||||
open fun mapToUpdateAccountTransactionsParameter(bank: BankAccess, account: BankAccount): GetAccountDataParameter {
|
open fun mapToUpdateAccountTransactionsParameter(bank: BankAccess, account: BankAccount, preferredTanMethods: List<TanMethodType>? = null): GetAccountDataParameter {
|
||||||
val defaults = GetAccountDataOptions()
|
val defaults = GetAccountDataOptions()
|
||||||
|
|
||||||
val accountIdentifier = BankAccountIdentifierImpl(account.identifier, account.subAccountNumber, account.iban)
|
val accountIdentifier = BankAccountIdentifierImpl(account.identifier, account.subAccountNumber, account.iban)
|
||||||
val from = account.lastAccountUpdateTime?.toLocalDateTime(TimeZone.EuropeBerlin)?.date // TODO: in case lastTransactionsUpdateTime is not set, this would retrieve all transactions (and require a TAN im most cases)
|
val from = account.lastAccountUpdateTime?.toLocalDateTime(TimeZone.EuropeBerlin)?.date // TODO: in case lastTransactionsUpdateTime is not set, this would retrieve all transactions (and require a TAN im most cases)
|
||||||
val retrieveTransactions = if (from != null) RetrieveTransactions.AccordingToRetrieveFromAndTo else RetrieveTransactions.valueOf(defaults.retrieveTransactions.name)
|
val retrieveTransactions = if (from != null) RetrieveTransactions.AccordingToRetrieveFromAndTo else RetrieveTransactions.valueOf(defaults.retrieveTransactions.name)
|
||||||
// val preferredTanMethods = listOf(mapTanMethodType(bank.selectedTanMethod.type)) // TODO: currently we aren't saving TanMethods in database, re-enable as soon as TanMethods get saved
|
|
||||||
val preferredTanMethods = defaults.preferredTanMethods?.map { mapTanMethodType(it) }
|
|
||||||
|
|
||||||
return GetAccountDataParameter(bank.domesticBankCode, bank.loginName, bank.password!!, listOf(accountIdentifier), true,
|
return GetAccountDataParameter(bank.domesticBankCode, bank.loginName, bank.password!!, listOf(accountIdentifier), true,
|
||||||
retrieveTransactions, from,
|
retrieveTransactions, from,
|
||||||
preferredTanMethods = preferredTanMethods,
|
preferredTanMethods = preferredTanMethods?.map { mapTanMethodType(it) },
|
||||||
preferredTanMedium = bank.selectedTanMediumIdentifier,
|
preferredTanMedium = bank.selectedTanMediumIdentifier,
|
||||||
finTsModel = bank.clientData as? BankData,
|
finTsModel = bank.clientData as? BankData,
|
||||||
serializedFinTsModel = bank.serializedClientData
|
serializedFinTsModel = bank.serializedClientData
|
||||||
|
|
Loading…
Reference in New Issue