commit 9d120e7b77960452a2ada3249bafd5891a8197fc
parent e1e7997a52755917c2ce1e9a7250e6b3c0cd6196
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 13 Feb 2020 14:03:16 +0100
First steps in payment preparation.
Diffstat:
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
@@ -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
@@ -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
}