[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] 05/07: Constants definition.
From: |
gnunet |
Subject: |
[libeufin] 05/07: Constants definition. |
Date: |
Fri, 31 Mar 2023 14:28:09 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository libeufin.
commit 9832b269d5fbe14ce6c7421d47f3ee6868c87c3f
Author: MS <ms@taler.net>
AuthorDate: Fri Mar 31 14:12:44 2023 +0200
Constants definition.
Providing enum class for transaction directions.
---
util/src/main/kotlin/JSON.kt | 49 ++++++++++++++++++++++--------
util/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
index e54cdd77..96ee1e05 100644
--- 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
index 758292e3..e60b4015 100644
--- 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),
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libeufin] branch master updated (71aa5ab6 -> 4f152510), gnunet, 2023/03/31
- [libeufin] 01/07: matching /cashout/estimates to the API, gnunet, 2023/03/31
- [libeufin] 02/07: Polishing Sandbox., gnunet, 2023/03/31
- [libeufin] 03/07: tests, gnunet, 2023/03/31
- [libeufin] 05/07: Constants definition.,
gnunet <=
- [libeufin] 06/07: Taler facade., gnunet, 2023/03/31
- [libeufin] 04/07: Postgres notifications., gnunet, 2023/03/31
- [libeufin] 07/07: Nexus x-libeufin-bank connection., gnunet, 2023/03/31