libeufin

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

commit 0d85f0a155b9dbbd24352e4051767380d6604d0e
parent 7614a3d502ded4ac8c6d491faee7e6c5533e5334
Author: Florian Dold <florian@dold.me>
Date:   Thu, 21 Jan 2021 01:45:32 +0100

don't confuse account servicer reference with payment information id

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/DB.kt | 12+++++++++++-
Msandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt | 1+
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Helpers.kt | 7+++++++
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 40+++++++---------------------------------
Mutil/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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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