libeufin

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

commit 9832b269d5fbe14ce6c7421d47f3ee6868c87c3f
parent 2d45653e2ceaca856e678987b1f8c5501fc29c82
Author: MS <ms@taler.net>
Date:   Fri, 31 Mar 2023 14:12:44 +0200

Constants definition.

Providing enum class for transaction directions.

Diffstat:
Mutil/src/main/kotlin/JSON.kt | 49+++++++++++++++++++++++++++++++++++++------------
Mutil/src/main/kotlin/LibeufinErrorCodes.kt | 2+-
2 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/util/src/main/kotlin/JSON.kt b/util/src/main/kotlin/JSON.kt @@ -19,14 +19,40 @@ package tech.libeufin.util -/** - * (Very) generic information about one payment. Can be - * derived from a CAMT response, or from a prepared PAIN - * document. - * - * Note: - */ -data class RawPayment( +enum class XLibeufinBankDirection(val direction: String) { + DEBIT("debit"), + CREDIT("credit"); + companion object { + fun parseXLibeufinDirection(direction: String): XLibeufinBankDirection { + return when(direction) { + "credit" -> CREDIT + "debit" -> DEBIT + else -> throw internalServerError( + "Cannot extract ${this::class.java.typeName}' instance from value: $direction'" + ) + } + } + + /** + * Sandbox uses _some_ CaMt terminology even for its internal + * data model. This function helps to bridge such CaMt terminology + * to the Sandbox simplified JSON format (XLibeufinBankTransaction). + * + * Ideally, the terminology should be made more abstract to serve + * both (and probably more) data formats. + */ + fun convertCamtDirectionToXLibeufin(camtDirection: String): XLibeufinBankDirection { + return when(camtDirection) { + "CRDT" -> CREDIT + "DBIT" -> DEBIT + else -> throw internalServerError( + "Cannot extract ${this::class.java.typeName}' instance from value: $camtDirection'" + ) + } + } + } +} +data class XLibeufinBankTransaction( val creditorIban: String, val creditorBic: String?, val creditorName: String, @@ -36,17 +62,16 @@ data class RawPayment( val amount: String, val currency: String, val subject: String, + // Milliseconds since the Epoch. val date: String, - val uid: String, // FIXME: explain this value. - val direction: String, // FIXME: this following value should be restricted to only DBIT/CRDT. - + val uid: String, + val direction: XLibeufinBankDirection, // The following two values are rather CAMT/PAIN // specific, therefore do not need to be returned // along every API call using this object. val pmtInfId: String? = null, val msgId: String? = null ) - data class IncomingPaymentInfo( val debtorIban: String, val debtorBic: String?, diff --git a/util/src/main/kotlin/LibeufinErrorCodes.kt b/util/src/main/kotlin/LibeufinErrorCodes.kt @@ -51,7 +51,7 @@ enum class LibeufinErrorCode(val code: Int) { LIBEUFIN_EC_INCONSISTENT_STATE(3), /** - * An access was forbidden due to wrong credentials. + * Access was forbidden due to wrong credentials. */ LIBEUFIN_EC_AUTHENTICATION_FAILED(4),