Added AccountData to CustomerData

This commit is contained in:
dankl 2019-10-13 13:12:18 +02:00 committed by dankito
parent 114836e066
commit 41a343421d
4 changed files with 58 additions and 4 deletions

View File

@ -224,11 +224,26 @@ open class FinTsClient(
}
response.getFirstSegmentById<AccountInfo>(InstituteSegmentId.AccountInfo)?.let { accountInfo ->
customer.iban = accountInfo.iban
customer.iban = accountInfo.iban // TODO: remove and use that one from AccountData
customer.name = accountInfo.accountHolderName1
var accountHolderName = accountInfo.accountHolderName1
accountInfo.accountHolderName2?.let {
customer.name = customer.name + it // TODO: add a whitespace in between?
accountHolderName += it // TODO: add a whitespace in between?
}
customer.name = accountHolderName
findExistingAccount(customer, accountInfo)?.let { account ->
// TODO: update AccountData. But can this ever happen that an account changes?
}
?: run {
val newAccount = AccountData(accountInfo.accountIdentifier, accountInfo.subAccountAttribute,
accountInfo.bankCountryCode, accountInfo.bankCode, accountInfo.iban, accountInfo.customerId,
accountInfo.accountType, accountInfo.currency, accountHolderName, accountInfo.productName,
accountInfo.accountLimit, accountInfo.allowedJobNames)
val accounts = customer.accounts.toMutableList()
accounts.add(newAccount)
customer.accounts = accounts
}
// TODO: may also make use of other info
@ -247,4 +262,17 @@ open class FinTsClient(
}
}
protected open fun findExistingAccount(customer: CustomerData, accountInfo: AccountInfo): AccountData? {
customer.accounts.forEach { account ->
if (account.accountIdentifier == accountInfo.accountIdentifier
&& account.productName == accountInfo.productName
&& account.accountType == accountInfo.accountType) {
return account
}
}
return null
}
}

View File

@ -0,0 +1,25 @@
package net.dankito.fints.model
import net.dankito.fints.response.segments.AccountType
open class AccountData(
val accountIdentifier: String,
val subAccountAttribute: String?,
val bankCountryCode: Int,
val bankCode: String,
val iban: String?,
val customerId: String,
val accountType: AccountType?,
val currency: String?, // TODO: may parse to a value object
val accountHolderName: String,
val productName: String?,
val accountLimit: String?,
val allowedJobNames: List<String>
) {
override fun toString(): String {
return "$productName $accountIdentifier $accountHolderName"
}
}

View File

@ -11,6 +11,7 @@ open class CustomerData(
val userId: String = customerId,
var name: String = "",
var iban: String? = null,
var accounts: List<AccountData> = listOf(),
var updVersion: Int = UPDVersion.VersionNotReceivedYet,
var availableTanProcedures: List<TanProcedure> = listOf(),
var selectedTanProcedure: TanProcedure? = null,

View File

@ -2,7 +2,7 @@ package net.dankito.fints.response.segments
open class AccountInfo(
val accountNumber: String,
val accountIdentifier: String,
val subAccountAttribute: String?,
val bankCountryCode: Int,
val bankCode: String,