commit af6b09f31537d016b45b3486e2cc815cb78e5db5 parent 3e473d71a91f0795f585e81f83add32af3aec114 Author: Antoine A <> Date: Tue, 30 Jan 2024 21:52:28 +0100 Fix notification parsing Diffstat:
4 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/ebics/src/main/kotlin/XmlCombinators.kt b/ebics/src/main/kotlin/XmlCombinators.kt @@ -125,6 +125,7 @@ class XmlDestructor internal constructor(private val el: Element) { fun <T> opt(path: String, f: XmlDestructor.() -> T): T? = opt(path)?.run(f) fun text(): String = el.textContent + fun bool(): Boolean = el.textContent.toBoolean() fun date(): LocalDate = LocalDate.parse(text(), DateTimeFormatter.ISO_DATE) fun dateTime(): LocalDateTime = LocalDateTime.parse(text(), DateTimeFormatter.ISO_DATE_TIME) inline fun <reified T : kotlin.Enum<T>> enum(): T = java.lang.Enum.valueOf(T::class.java, text()) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt @@ -236,9 +236,6 @@ suspend fun ingestIncomingPayment( ) { val reservePub = getTalerReservePub(payment) if (reservePub == null) { - logger.debug("Incoming payment with UID '${payment.bankId}'" + - " has invalid subject: ${payment.wireTransferSubject}." - ) val result = db.registerMalformedIncoming( payment, payment.amount, diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Iso20022.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Iso20022.kt @@ -326,9 +326,11 @@ private fun notificationForEachTx( directionLambda: XmlDestructor.(Instant) -> Unit ) { destructXml(xml, "Document") { - one("BkToCstmrDbtCdtNtfctn") { - each("Ntfctn") { - each("Ntry") { + opt("BkToCstmrDbtCdtNtfctn")?.each("Ntfctn") { + each("Ntry") { + if (opt("RvslInd")?.bool() ?: false) { + logger.warn("Skip reversal transaction") + } else { one("Sts") { if (text() != "BOOK") { one("Cd") { @@ -339,8 +341,8 @@ private fun notificationForEachTx( } } } - val bookDate: Instant = one("BookgDt").one("Dt").dateTime().toInstant(ZoneOffset.UTC) - one("NtryDtls").one("TxDtls") { + val bookDate: Instant = one("BookgDt").one("Dt").date().atStartOfDay().toInstant(ZoneOffset.UTC) + one("NtryDtls").each("TxDtls") { directionLambda(this, bookDate) } } diff --git a/testbench/src/test/kotlin/Iso20022Test.kt b/testbench/src/test/kotlin/Iso20022Test.kt @@ -38,11 +38,7 @@ class Iso20022Test { } else if (name.contains("pain.002")) { parseCustomerPaymentStatusReport(str) } else { - try { - parseTxNotif(str, "CHF", mutableListOf(), mutableListOf()) - } catch (e: Exception) { - println(e) // TODO import tx notif - } + parseTxNotif(str, "CHF", mutableListOf(), mutableListOf()) } } }