libeufin

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

commit 4418c5c2f91789c6b0a56a10ff6174273a38a6ef
parent 1bd464c184a177311c399eb858a87bad1667c4cb
Author: MS <ms@taler.net>
Date:   Tue, 26 May 2020 15:15:32 +0200

add separate camt parser

Diffstat:
Autil/src/test/kotlin/ISO20022.kt | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+), 0 deletions(-)

diff --git a/util/src/test/kotlin/ISO20022.kt b/util/src/test/kotlin/ISO20022.kt @@ -0,0 +1,50 @@ +package tech.libeufin.util + +import org.w3c.dom.Document + +/* + * This file is part of LibEuFin. + * Copyright (C) 2019 Stanisci and Dold. + + * LibEuFin is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation; either version 3, or + * (at your option) any later version. + + * LibEuFin is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General + * Public License for more details. + + * You should have received a copy of the GNU Affero General Public + * License along with LibEuFin; see the file COPYING. If not, see + * <http://www.gnu.org/licenses/> + */ + +data class CamtData( + val bookingDate: Long, + val subject: String, + val txType: String, /* only "DBIT" / "CRDT" are admitted */ + val currency: String, + val amount: String, + val status: String, /* only "BOOK" is admitted */ + val counterpartIban: String, + val counterpartBic: String, + val counterpartName: String +) + +fun parseCamt(camtDoc: Document): CamtData { + val txType = camtDoc.pickString("//*[local-name()='Ntry']//*[local-name()='CdtDbtInd']") + val bd = parseDashedDate(camtDoc.pickString("//*[local-name()='BookgDt']//*[local-name()='Dt']")) + return CamtData( + txType = txType, + bookingDate = bd.millis(), + subject = camtDoc.pickString("//*[local-name()='Ntry']//*[local-name()='Ustrd']"), + currency = camtDoc.pickString("//*[local-name()='Ntry']//*[local-name()='Amt']/@Ccy"), + amount = camtDoc.pickString("//*[local-name()='Ntry']//*[local-name()='Amt']"), + status = camtDoc.pickString("//*[local-name()='Ntry']//*[local-name()='Sts']"), + counterpartBic = camtDoc.pickString("//*[local-name()='RltdAgts']//*[local-name()='BIC']"), + counterpartIban = camtDoc.pickString("//*[local-name()='${if (txType == "DBIT") "CdtrAcct" else "DbtrAcct"}']//*[local-name()='IBAN']"), + counterpartName = camtDoc.pickString("//*[local-name()='RltdPties']//*[local-name()='${if (txType == "DBIT") "Cdtr" else "Dbtr"}']//*[local-name()='Nm']") + ) +} +\ No newline at end of file