From ae37442d86fc3492f7a3816d610cbdb807707d18 Mon Sep 17 00:00:00 2001 From: dankito Date: Sun, 6 Dec 2020 17:02:44 +0100 Subject: [PATCH] Added parsing transactionDescriptionSupplement --- .../net/dankito/banking/fints/FinTsClient.kt | 2 +- .../fints/model/CreditCardTransaction.kt | 28 +++++++++++++++---- .../banking/fints/response/ResponseParser.kt | 5 ++-- 3 files changed, 26 insertions(+), 9 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 0e4601d0..af9ad260 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/FinTsClient.kt @@ -399,7 +399,7 @@ open class FinTsClient( response.getFirstSegmentById(InstituteSegmentId.CreditCardTransactions)?.let { transactionsSegment -> balance = Money(transactionsSegment.balance.amount, transactionsSegment.balance.currency ?: "EUR") - bookedTransactions.addAll(transactionsSegment.transactions.map { AccountTransaction(parameter.account, it.amount, it.otherPartyName, it.bookingDate, it.otherPartyName, null, null, "", it.valueDate) }) + bookedTransactions.addAll(transactionsSegment.transactions.map { AccountTransaction(parameter.account, it.amount, it.description, it.bookingDate, it.transactionDescriptionBase ?: "", null, null, "", it.valueDate) }) } } diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/CreditCardTransaction.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/CreditCardTransaction.kt index d29a70bd..9f355d5b 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/CreditCardTransaction.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/model/CreditCardTransaction.kt @@ -5,15 +5,31 @@ import net.dankito.utils.multiplatform.format open class CreditCardTransaction( - val amount: Money, - val otherPartyName: String, - val bookingDate: Date, - val valueDate: Date, - val isCleared: Boolean + open val amount: Money, + open val transactionDescriptionBase: String?, + open val transactionDescriptionSupplement: String?, + open val bookingDate: Date, + open val valueDate: Date, + open val isCleared: Boolean ) { + + open val description: String + get() { + transactionDescriptionBase?.let { transactionDescriptionBase -> + if (transactionDescriptionSupplement != null) { + return transactionDescriptionBase + " " + transactionDescriptionSupplement + } + + return transactionDescriptionBase + } + + return "" + } + + override fun toString(): String { - return "${valueDate.format("dd.MM.yy")} $amount $otherPartyName" + return "${valueDate.format("dd.MM.yy")} $amount $description" } } \ No newline at end of file diff --git a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt index 5e20e202..68afb1a2 100644 --- a/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt +++ b/fints4k/src/commonMain/kotlin/net/dankito/banking/fints/response/ResponseParser.kt @@ -702,10 +702,11 @@ open class ResponseParser( val bookingDate = parseDate(dataElements[1]) val valueDate = parseDate(dataElements[2]) val amount = parseCreditCardAmount(dataElements.subList(8, 11)) - val otherPartyName = parseString(dataElements[11]) + val transactionDescriptionBase = parseStringToNullIfEmpty(dataElements[11]) + val transactionDescriptionSupplement = parseStringToNullIfEmpty(dataElements[12]) val isCleared = parseBoolean(dataElements[20]) - return CreditCardTransaction(amount, otherPartyName, bookingDate, valueDate, isCleared) + return CreditCardTransaction(amount, transactionDescriptionBase, transactionDescriptionSupplement, bookingDate, valueDate, isCleared) } catch (e: Exception) { log.error("Could not parse Credit card transaction '$transactionDataElementGroup'", e) }