summaryrefslogtreecommitdiff
path: root/nexus/src/main/kotlin/tech/libeufin/nexus/server
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-03-31 14:22:46 +0200
committerMS <ms@taler.net>2023-03-31 14:22:46 +0200
commit4f1525107159cd7f92c18e8060f0333a9c3055b4 (patch)
treecddc21785fa296a417963802961429c553826f98 /nexus/src/main/kotlin/tech/libeufin/nexus/server
parent59a20971438391fb22a536080b27b4db50ea5d31 (diff)
downloadlibeufin-4f1525107159cd7f92c18e8060f0333a9c3055b4.tar.gz
libeufin-4f1525107159cd7f92c18e8060f0333a9c3055b4.tar.bz2
libeufin-4f1525107159cd7f92c18e8060f0333a9c3055b4.zip
Nexus x-libeufin-bank connection.
Introducing the operation to download transactions from the bank. More helpers were added, and some CaMt specific code got moved from BankAccount.kt to Iso20022.kt.
Diffstat (limited to 'nexus/src/main/kotlin/tech/libeufin/nexus/server')
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/server/Helpers.kt85
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt23
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt3
3 files changed, 102 insertions, 9 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/Helpers.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/Helpers.kt
new file mode 100644
index 00000000..8c01705a
--- /dev/null
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/Helpers.kt
@@ -0,0 +1,85 @@
+package tech.libeufin.nexus.server
+
+import org.jetbrains.exposed.sql.transactions.transaction
+import tech.libeufin.nexus.NexusBankConnectionEntity
+import tech.libeufin.nexus.NexusBankConnectionsTable
+import tech.libeufin.util.internalServerError
+import tech.libeufin.util.notFound
+
+/**
+ * FIXME:
+ * enum type names were introduced after 0.9.2 and need to
+ * be employed wherever now type names are passed as plain
+ * strings.
+ */
+
+// Valid connection types.
+enum class BankConnectionType(val typeName: String) {
+ EBICS("ebics"),
+ X_LIBEUFIN_BANK("x-taler-bank");
+ companion object {
+ /**
+ * This method takes legacy bank connection type names as input
+ * and _tries_ to return the correspondent enum type. This
+ * fixes the cases where bank connection types are passed as
+ * easy-to-break arbitrary strings; eventually this method should
+ * be discarded and only enum types be passed as connection type names.
+ */
+ fun parseBankConnectionType(typeName: String): BankConnectionType {
+ return when(typeName) {
+ "ebics" -> EBICS
+ "x-libeufin-bank" -> X_LIBEUFIN_BANK
+ else -> throw internalServerError(
+ "Cannot extract ${this::class.java.typeName}' instance from name: $typeName'"
+ )
+ }
+ }
+ }
+}
+// Valid facade types
+enum class NexusFacadeType(val facadeType: String) {
+ TALER("taler-wire-gateway"),
+ ANASTASIS("anastasis")
+}
+
+/**
+ * These types point at the _content_ brought by bank connections.
+ * The following stack depicts the layering of banking communication
+ * as modeled here in Nexus. On top the most inner layer.
+ *
+ * --------------------
+ * Banking data type
+ * --------------------
+ * Bank connection type
+ * --------------------
+ * HTTP
+ * --------------------
+ *
+ * Once the banking data type arrives to the local database, facades
+ * types MAY apply further processing to it.
+ *
+ * For example, a Taler facade WILL look for Taler-meaningful wire
+ * subjects and act accordingly. Even without a facade, the Nexus
+ * native HTTP API picks instances of banking data and extracts its
+ * details to serve to the client.
+ *
+ * NOTE: this type MAY help but is NOT essential, as each connection
+ * is USUALLY tied with the same banking data type. For example, EBICS
+ * brings CaMt, and x-libeufin-bank bring its own (same-named x-libeufin-bank)
+ * banking data type.
+ */
+enum class BankingDataType {
+ X_LIBEUFIN_BANK,
+ CAMT
+}
+
+// Gets connection or throws.
+fun getBankConnection(connId: String): NexusBankConnectionEntity {
+ val maybeConn = transaction {
+ NexusBankConnectionEntity.find {
+ NexusBankConnectionsTable.connectionId eq connId
+ }.firstOrNull()
+ }
+ if (maybeConn == null) throw notFound("Bank connection $connId not found")
+ return maybeConn
+} \ No newline at end of file
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
index 38ab4236..7fdfd526 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt
@@ -32,10 +32,9 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
import com.fasterxml.jackson.databind.ser.std.StdSerializer
+import tech.libeufin.nexus.EntryStatus
import tech.libeufin.nexus.iso20022.CamtBankAccountEntry
-import tech.libeufin.nexus.iso20022.EntryStatus
import tech.libeufin.util.*
-import java.math.BigDecimal
import java.time.Instant
import java.time.ZoneId
import java.time.ZonedDateTime
@@ -251,6 +250,17 @@ data class EbicsNewTransport(
val systemID: String?
)
+/**
+ * Credentials and URL to access Sandbox and talk JSON to it.
+ * See https://docs.taler.net/design-documents/038-demobanks-protocol-suppliers.html#static-x-libeufin-bank-with-dynamic-demobank
+ * for an introduction on x-libeufin-bank.
+ */
+data class XLibeufinBankTransport(
+ val username: String,
+ val password: String,
+ val baseUrl: String
+)
+
/** Response type of "GET /prepared-payments/{uuid}" */
data class PaymentStatus(
val paymentInitiationId: String,
@@ -262,10 +272,6 @@ data class PaymentStatus(
val subject: String,
val submissionDate: String?,
val preparationDate: String,
- // null when the payment was never acknowledged by
- // the bank. For example, it was submitted but never
- // seen in any report; or only created and not even
- // submitted.
val status: EntryStatus?
)
@@ -346,8 +352,9 @@ data class BankMessageList(
)
data class BankMessageInfo(
- val messageId: String,
- val code: String,
+ // x-libeufin-bank messages do not have any ID or code.
+ val messageId: String?,
+ val code: String?,
val length: Long
)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
index ebe002fc..fb864d3b 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -53,6 +53,7 @@ import tech.libeufin.nexus.*
import tech.libeufin.nexus.bankaccount.*
import tech.libeufin.nexus.ebics.*
import tech.libeufin.nexus.iso20022.CamtBankAccountEntry
+import tech.libeufin.nexus.iso20022.processCamtMessage
import tech.libeufin.util.*
import java.net.BindException
import java.net.URLEncoder
@@ -739,7 +740,7 @@ val nexusApp: Application.() -> Unit = {
var statusCode = HttpStatusCode.OK
/**
* Client errors are unlikely here, because authentication
- * and JSON validity fail earlier. Hence either Nexus or the
+ * and JSON validity fail earlier. Hence, either Nexus or the
* bank had a problem. NOTE: because this handler triggers multiple
* fetches, it is ALSO possible that although one error is reported,
* SOME transactions made it to the database!