gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: don't confuse account servicer referen


From: gnunet
Subject: [libeufin] branch master updated: don't confuse account servicer reference with payment information id
Date: Thu, 21 Jan 2021 01:45:37 +0100

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 0d85f0a  don't confuse account servicer reference with payment 
information id
0d85f0a is described below

commit 0d85f0a155b9dbbd24352e4051767380d6604d0e
Author: Florian Dold <florian@dold.me>
AuthorDate: Thu Jan 21 01:45:32 2021 +0100

    don't confuse account servicer reference with payment information id
---
 .../src/main/kotlin/tech/libeufin/sandbox/DB.kt    | 12 ++++++-
 .../tech/libeufin/sandbox/EbicsProtocolBackend.kt  |  1 +
 .../main/kotlin/tech/libeufin/sandbox/Helpers.kt   |  7 ++++
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  | 40 ++++------------------
 util/src/main/kotlin/JSON.kt                       |  3 +-
 5 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
index d9e75ae..d0b024b 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt
@@ -257,7 +257,17 @@ object BankAccountTransactionsTable : Table() {
     val amount = text("amount")
     val currency = text("currency")
     val date = long("date")
-    val pmtInfId = text("pmtInfId")
+
+    /**
+     * Unique ID for this payment within the bank account.
+     */
+    val accountServicerReference = text("accountServicerReference")
+
+    /**
+     * Payment information ID, which is a reference to the payment initiation
+     * that triggered this transaction.  Typically only available with 
outgoing transactions.
+     */
+    val pmtInfId = text("pmtInfId").nullable()
     val direction = text("direction")
     val account = reference("account", BankAccountsTable)
 
diff --git 
a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index 328ec7c..0e26871 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -566,6 +566,7 @@ private fun handleCct(paymentRequest: String, 
initiatorName: String) {
                 it[currency] = parseResult.currency
                 it[date] = Instant.now().toEpochMilli()
                 it[pmtInfId] = parseResult.pmtInfId
+                it[accountServicerReference] = "sandboxref-getRandomString(16)"
                 it[direction] = "DBIT"
             }
         } catch (e: ExposedSQLException) {
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
index bc9c908..d3e3752 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt
@@ -82,4 +82,11 @@ fun getEbicsSubscriberFromDetails(userID: String, partnerID: 
String, hostID: Str
             "Ebics subscriber not found"
         )
     }
+}
+
+fun getRandomString(length: Int) : String {
+    val allowedChars = ('A'..'Z') + ('0'..'9')
+    return (1..length)
+        .map { allowedChars.random() }
+        .joinToString("")
 }
\ No newline at end of file
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt 
b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index dcc110f..87ad474 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -66,6 +66,7 @@ import com.github.ajalt.clikt.parameters.options.versionOption
 import com.github.ajalt.clikt.parameters.types.int
 import execThrowableOrTerminate
 import io.ktor.request.*
+import 
tech.libeufin.sandbox.BankAccountTransactionsTable.accountServicerReference
 import tech.libeufin.sandbox.BankAccountTransactionsTable.amount
 import tech.libeufin.sandbox.BankAccountTransactionsTable.creditorBic
 import tech.libeufin.sandbox.BankAccountTransactionsTable.creditorIban
@@ -303,42 +304,13 @@ fun serverMain(dbName: String, port: Int) {
                 call.respondText(camt53, ContentType.Text.Xml, 
HttpStatusCode.OK)
                 return@post
             }
-            // FIXME:  This returns *all* payments for all accounts.  Is that 
really useful/required?
-            get("/admin/payments") {
-                val ret = PaymentsResponse()
-                transaction {
-                    BankAccountTransactionsTable.selectAll().forEach {
-                        ret.payments.add(
-                            RawPayment(
-                                creditorIban = it[creditorIban],
-                                debitorIban = it[debtorIban],
-                                subject = 
it[BankAccountTransactionsTable.subject],
-                                date = it[date].toHttpDateString(),
-                                amount = it[amount],
-                                creditorBic = it[creditorBic],
-                                creditorName = it[creditorName],
-                                debitorBic = it[debtorBic],
-                                debitorName = it[debtorName],
-                                currency = it[currency],
-                                direction = it[direction]
-                            )
-                        )
-                    }
-                }
-                call.respond(
-                    object {
-                        val payments = ret
-                    }
-                )
-                return@get
-            }
 
             /**
              * Adds a new payment to the book.
              */
             post("/admin/payments") {
                 val body = call.receive<RawPayment>()
-                val random = Random.nextLong(0, Long.MAX_VALUE)
+                val randId = getRandomString(16)
                 transaction {
                     val localIban = if (body.direction == "DBIT") 
body.debitorIban else body.creditorIban
                     BankAccountTransactionsTable.insert {
@@ -352,7 +324,7 @@ fun serverMain(dbName: String, port: Int) {
                         it[amount] = body.amount
                         it[currency] = body.currency
                         it[date] = Instant.now().toEpochMilli()
-                        it[pmtInfId] = random.toString()
+                        it[accountServicerReference] = "sandbox-$randId"
                         it[account] = getBankAccountFromIban(localIban).id
                         it[direction] = body.direction
                     }
@@ -368,6 +340,7 @@ fun serverMain(dbName: String, port: Int) {
                 val accountLabel = ensureNonNull(call.parameters["label"])
                 transaction {
                     val account = getBankAccountFromLabel(accountLabel)
+                    val randId = getRandomString(16)
                     BankAccountTransactionsTable.insert {
                         it[creditorIban] = account.iban
                         it[creditorBic] = account.bic
@@ -379,7 +352,7 @@ fun serverMain(dbName: String, port: Int) {
                         it[amount] = body.amount
                         it[currency] = account.currency
                         it[date] = Instant.now().toEpochMilli()
-                        it[pmtInfId] = random.toString()
+                        it[accountServicerReference] = "sandbox-$randId"
                         it[BankAccountTransactionsTable.account] = account.id
                         it[direction] = "CRDT"
                     }
@@ -439,7 +412,8 @@ fun serverMain(dbName: String, port: Int) {
                                         creditorIban = it[creditorIban],
                                         // FIXME: We need to modify the 
transactions table to have an actual
                                         // account servicer reference here.
-                                        accountServicerReference = 
it[pmtInfId],
+                                        accountServicerReference = 
it[accountServicerReference],
+                                        paymentInformationId = it[pmtInfId],
                                         debtorIban = it[debtorIban],
                                         subject = 
it[BankAccountTransactionsTable.subject],
                                         date = it[date].toHttpDateString(),
diff --git a/util/src/main/kotlin/JSON.kt b/util/src/main/kotlin/JSON.kt
index 1b9cb03..f8cc240 100644
--- a/util/src/main/kotlin/JSON.kt
+++ b/util/src/main/kotlin/JSON.kt
@@ -67,5 +67,6 @@ data class PaymentInfo(
     val subject: String,
     val date: String? = null,
     val creditDebitIndicator: String,
-    val accountServicerReference: String
+    val accountServicerReference: String,
+    val paymentInformationId: String?,
 )
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]