gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated (9632ba7 -> 9d120e7)


From: gnunet
Subject: [libeufin] branch master updated (9632ba7 -> 9d120e7)
Date: Thu, 13 Feb 2020 15:53:52 +0100

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

marcello pushed a change to branch master
in repository libeufin.

    from 9632ba7  comments
     new e1e7997  avoid git status
     new 9d120e7  First steps in payment preparation.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 50 ++++++++++++++++++-----
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
index 809bd9a..b795584 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -41,6 +41,7 @@ import io.ktor.server.netty.Netty
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
 import org.apache.commons.compress.archivers.zip.ZipFile
 import org.apache.commons.compress.utils.SeekableInMemoryByteChannel
+import org.jetbrains.exposed.dao.EntityID
 import org.jetbrains.exposed.exceptions.ExposedSQLException
 import org.jetbrains.exposed.sql.StdOutSqlLogger
 import org.jetbrains.exposed.sql.addLogger
@@ -85,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}")
@@ -98,6 +100,28 @@ data class BankInvalidResponse(val statusCode: 
HttpStatusCode) : Exception("Miss
 
 val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus")
 
+fun getSubscriberEntityFromId(id: String): EbicsSubscriberEntity {
+    return transaction {
+        EbicsSubscriberEntity.findById(id) ?: throw SubscriberNotFoundError(
+            HttpStatusCode.NotFound
+        )
+    }
+}
+
+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(
@@ -317,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
             }
 
@@ -433,20 +469,14 @@ fun main() {
                 when (response) {
                     is EbicsDownloadSuccessResult -> {
                         val payload = 
XMLUtil.convertStringToJaxb<HTDResponseOrderData>(response.orderData.toString(Charsets.UTF_8))
-                        if (null == payload.value.partnerInfo.accountInfoList) 
{
-                            throw Exception(
-                                "Inconsistent state: customers MUST have at 
least one bank account"
-                            )
-                        }
                         transaction {
-                            val subscriber = 
EbicsSubscriberEntity.findById(customerIdAtNexus)
-                            // FIXME: see if "!!" can be avoided
-                            
payload.value.partnerInfo.accountInfoList!!.forEach {
+                            payload.value.partnerInfo.accountInfoList?.forEach 
{
                                 EbicsAccountInfoEntity.new {
-                                    this.subscriber = subscriber!! /* FIXME: 
Always true here, but to be avoided */
+                                    this.subscriber = 
getSubscriberEntityFromId(customerIdAtNexus)
                                     accountId = it.id
                                     accountHolder = it.accountHolder
-                                    /* FIXME: how to figure out whether that's 
a general or national account number? */
+                                    /* FIXME: how to figure out whether that's 
a general or national account number?
+                                     * This should affect the cast below */
                                     iban = (it.accountNumberList?.get(0) as 
EbicsTypes.GeneralAccountNumber).value // FIXME: eventually get *all* of them
                                     bankCode = (it.bankCodeList?.get(0) as 
EbicsTypes.GeneralBankCode).value  // FIXME: eventually get *all* of them
                                 }

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

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