libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 3118c928e7543907c49720f55fa84dd70c32be7a
parent 9d9fade34a9b77db182ea8252686332953af2cf9
Author: MS <ms@taler.net>
Date:   Fri, 17 Nov 2023 20:13:19 +0100

nexus fetch: debug

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt | 40++++++++++++++++++++++++++++++----------
1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt @@ -209,12 +209,25 @@ fun getTalerAmount( ) } +class WrongPaymentDirection(val msg: String) : Exception(msg) + +/** + * Parses a camt.054 document looking for outgoing payments. + * + * @param notifXml input document. + * @param acceptedCurrency currency accepted by Nexus + * @return the list of outgoing payments. + */ private fun parseOutgoingTxNotif( notifXml: String, acceptedCurrency: String, ): List<OutgoingPayment> { val ret = mutableListOf<OutgoingPayment>() notificationForEachTx(notifXml) { bookDate -> + requireUniqueChildNamed("CdtDbtInd") { + if (focusElement.textContent != "DBIT") + throw WrongPaymentDirection("The payment is not outgoing, won't parse it") + } // Obtaining the amount. val amount: TalerAmount = requireUniqueChildNamed("Amt") { val currency = focusElement.getAttribute("Ccy") @@ -236,14 +249,15 @@ private fun parseOutgoingTxNotif( uidFromBank.append(focusElement.textContent) } } + // Obtaining payment subject. val subject = StringBuilder() - requireUniqueChildNamed("RmtInf") { - this.mapEachChildNamed("Ustrd") { - val piece = this.focusElement.textContent - subject.append(piece) + requireUniqueChildNamed("RmtInf") { + this.mapEachChildNamed("Ustrd") { + val piece = this.focusElement.textContent + subject.append(piece) + } } - } // Obtaining the payer's details val creditorPayto = StringBuilder("payto://iban/") @@ -291,7 +305,7 @@ private fun parseIncomingTxNotif( // Check the direction first. requireUniqueChildNamed("CdtDbtInd") { if (focusElement.textContent != "CRDT") - throw Exception("The payment is not incoming, won't parse it") + throw WrongPaymentDirection("The payment is not incoming, won't parse it") } val amount: TalerAmount = requireUniqueChildNamed("Amt") { val currency = focusElement.getAttribute("Ccy") @@ -700,10 +714,16 @@ class EbicsFetch: CliktCommand("Fetches bank records. Defaults to camt.054 noti val maybeStdin = generateSequence(::readLine).joinToString("\n") when(whichDoc) { SupportedDocument.CAMT_054 -> { - val outgoing = parseOutgoingTxNotif(maybeStdin, cfg.currency) - val incoming = parseIncomingTxNotif(maybeStdin, cfg.currency) - println(incoming) - println(outgoing) + try { + println(parseIncomingTxNotif(maybeStdin, cfg.currency)) + } catch (e: WrongPaymentDirection) { + logger.info("Input doesn't contain incoming payments") + } + try { + println(parseOutgoingTxNotif(maybeStdin, cfg.currency)) + } catch (e: WrongPaymentDirection) { + logger.debug("Input doesn't contain outgoing payments") + } } else -> { logger.error("Parsing $whichDoc not supported")