libeufin

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

commit 3cb47562212364162a82c83fd73074573d9f883e
parent ce82d2aea3a2919d019bd37c89e4d4346811fc17
Author: MS <ms@taler.net>
Date:   Fri, 19 Jun 2020 16:11:38 +0200

fetching accounts, store raw data into database

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 18+++++++++++++++++-
Mnexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt | 40++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -30,6 +30,7 @@ import org.jetbrains.exposed.sql.StdOutSqlLogger import org.jetbrains.exposed.sql.addLogger import org.jetbrains.exposed.sql.transactions.TransactionManager import org.jetbrains.exposed.sql.transactions.transaction +import tech.libeufin.nexus.NexusBankAccountsTable.entityId import tech.libeufin.util.EbicsInitState import tech.libeufin.util.amount import java.sql.Connection @@ -210,6 +211,22 @@ class PaymentInitiationEntity(id: EntityID<Long>) : LongEntity(id) { } /** + * This table associates a bank connection with the raw XML response + * coming from a HTD message. The main purpose here is to store (possibly + * temporarily) the bank accounts belonging to one subscriber, in order + * to allow this latter to import them using more meaningful labels. + */ +object RawHTDResponsesTable : IdTable<String>() { + // the bank-connection that was used to download this data. + override val id = text("id").entityId() + val htdResponse = text("htdResponse") +} +class RawHTDResponseEntity(id: EntityID<String>) : Entity<String>(id) { + companion object : EntityClass<String, RawHTDResponseEntity>(RawHTDResponsesTable) + var htdResponse by RawHTDResponsesTable.htdResponse +} + +/** * This table holds triples of <iban, bic, holder name>. * FIXME(dold): Allow other account and bank identifications than IBAN and BIC */ @@ -234,7 +251,6 @@ object NexusBankAccountsTable : IdTable<String>() { class NexusBankAccountEntity(id: EntityID<String>) : Entity<String>(id) { companion object : EntityClass<String, NexusBankAccountEntity>(NexusBankAccountsTable) - var accountHolder by NexusBankAccountsTable.accountHolder var iban by NexusBankAccountsTable.iban var bankCode by NexusBankAccountsTable.bankCode diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt @@ -39,6 +39,7 @@ import io.ktor.request.receiveOrNull import io.ktor.response.respond import io.ktor.response.respondText import io.ktor.routing.Route +import io.ktor.routing.get import io.ktor.routing.post import org.jetbrains.exposed.sql.statements.api.ExposedBlob import org.jetbrains.exposed.sql.transactions.transaction @@ -388,6 +389,45 @@ fun Route.ebicsBankConnectionRoutes(client: HttpClient) { } call.respond(object {}) } + post("/accounts/fetch") { + val res = transaction { + authenticateRequest(call.request) + val conn = requireBankConnection(call, "connid") + if (conn.type != "ebics") { + throw NexusError(HttpStatusCode.BadRequest, "bank connection is not of type 'ebics'") + } + object { + val subscriberDetails = getEbicsSubscriberDetails(conn.id.value) + val connid = conn.id.value + } + } + val response = doEbicsDownloadTransaction( + client, res.subscriberDetails, "HTD", EbicsStandardOrderParams() + ) + when (response) { + is EbicsDownloadBankErrorResult -> { + throw NexusError( + HttpStatusCode.BadGateway, + response.returnCode.errorCode + ) + } + is EbicsDownloadSuccessResult -> { + transaction { + RawHTDResponseEntity.new(res.connid) { + htdResponse = response.orderData.toString(Charsets.UTF_8) + } + } + } + } + call.respond(object {}) + } + get("/accounts") { + val ret = BankAccounts() + call.respond(object {}) + } + post("/account/import") { + call.respond(object {}) + } /** * Directly import accounts. Used for testing.