[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] 02/02: First steps in payment preparation.
From: |
gnunet |
Subject: |
[libeufin] 02/02: First steps in payment preparation. |
Date: |
Thu, 13 Feb 2020 15:53:54 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository libeufin.
commit 9d120e7b77960452a2ada3249bafd5891a8197fc
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Feb 13 14:03:16 2020 +0100
First steps in payment preparation.
---
nexus/src/main/kotlin/tech/libeufin/nexus/Db.kt | 2 +-
nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 29 ++++++++++++++++++++++-
2 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Db.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/Db.kt
index e2591d2..e49f8ef 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Db.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Db.kt
@@ -58,7 +58,7 @@ const val ID_MAX_LENGTH = 50
object EbicsAccountsInfoTable : IntIdTable() {
val accountId = text("accountId")
- val subscriber = reference("subscriberId", EbicsSubscribersTable)
+ val subscriber = reference("subscriber", EbicsSubscribersTable)
val accountHolder = text("accountHolder").nullable()
val iban = text("iban")
val bankCode = text("bankCode")
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 7f1dcc1..b795584 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -86,6 +86,7 @@ fun testData() {
data class NotAnIdError(val statusCode: HttpStatusCode) : Exception("String ID
not convertible in number")
data class BankKeyMissing(val statusCode: HttpStatusCode) :
Exception("Impossible operation: bank keys are missing")
data class SubscriberNotFoundError(val statusCode: HttpStatusCode) :
Exception("Subscriber not found in database")
+data class BankAccountNotFoundError(val statusCode: HttpStatusCode) :
Exception("Subscriber doesn't have bank account claimed by given 'acctid'")
data class UnreachableBankError(val statusCode: HttpStatusCode) :
Exception("Could not reach the bank")
data class UnparsableResponse(val statusCode: HttpStatusCode, val rawResponse:
String) :
Exception("bank responded: ${rawResponse}")
@@ -107,6 +108,20 @@ fun getSubscriberEntityFromId(id: String):
EbicsSubscriberEntity {
}
}
+fun getBankAccountDetailsFromAcctid(id: String): EbicsAccountInfoElement {
+ return transaction {
+ val bankAccount = EbicsAccountInfoEntity.find {
+ EbicsAccountsInfoTable.accountId eq id
+ }.firstOrNull() ?: throw
BankAccountNotFoundError(HttpStatusCode.NotFound)
+ EbicsAccountInfoElement(
+ accountId = id,
+ accountHolderName = bankAccount.accountHolder,
+ iban = bankAccount.iban,
+ bankCode = bankAccount.bankCode
+ )
+ }
+}
+
fun getSubscriberDetailsFromId(id: String): EbicsClientSubscriberDetails {
return transaction {
val subscriber = EbicsSubscriberEntity.findById(
@@ -306,7 +321,7 @@ fun main() {
val ret = EbicsAccountsInfoResponse()
transaction {
EbicsAccountInfoEntity.find {
- EbicsAccountsInfoTable.subscriberId eq id
+ EbicsAccountsInfoTable.subscriber eq id
}.forEach {
ret.accounts.add(
EbicsAccountInfoElement(
@@ -326,6 +341,18 @@ fun main() {
}
post("/ebics/subscribers/{id}/accounts/{acctid}/prepare-payment") {
+ val acctid = expectId(call.parameters["acctid"])
+ val subscriberId = expectId(call.parameters["id"])
+ val accountDetails: EbicsAccountInfoElement =
getBankAccountDetailsFromAcctid(acctid)
+ val subscriberDetails =
getSubscriberDetailsFromId(subscriberId)
+
+ /**
+ * Payment preparation logic goes here!
+ */
+
+ call.respond(NexusErrorJson("Work in progress"))
+ return@post
+
// FIXME(marcello): Put transaction in the database, generate
PAIN.001 document
}
--
To stop receiving notification emails like this one, please contact
address@hidden.