commit b1732c28fd7e41b50442090d3cd0be6241dc81f5
parent 9d120e7b77960452a2ada3249bafd5891a8197fc
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Thu, 13 Feb 2020 16:41:01 +0100
Fetching bank accounts goes in a dedicated function.
Diffstat:
2 files changed, 40 insertions(+), 16 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -468,20 +468,6 @@ fun main() {
val response = doEbicsDownloadTransaction(client, subscriberData, "HTD", orderParams)
when (response) {
is EbicsDownloadSuccessResult -> {
- val payload = XMLUtil.convertStringToJaxb<HTDResponseOrderData>(response.orderData.toString(Charsets.UTF_8))
- transaction {
- payload.value.partnerInfo.accountInfoList?.forEach {
- EbicsAccountInfoEntity.new {
- this.subscriber = getSubscriberEntityFromId(customerIdAtNexus)
- accountId = it.id
- accountHolder = it.accountHolder
- /* 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
- }
- }
- }
call.respondText(
response.orderData.toString(Charsets.UTF_8),
ContentType.Text.Plain,
@@ -966,6 +952,44 @@ fun main() {
)
}
+ post("/ebics/subscribers/{id}/fetch-accounts") {
+ val customerIdAtNexus = expectId(call.parameters["id"])
+ val paramsJson = call.receive<EbicsStandardOrderParamsJson>()
+ val orderParams = paramsJson.toOrderParams()
+ val subscriberData = getSubscriberDetailsFromId(customerIdAtNexus)
+ val response = doEbicsDownloadTransaction(client, subscriberData, "HTD", orderParams)
+ when (response) {
+ is EbicsDownloadSuccessResult -> {
+ val payload = XMLUtil.convertStringToJaxb<HTDResponseOrderData>(response.orderData.toString(Charsets.UTF_8))
+ transaction {
+ payload.value.partnerInfo.accountInfoList?.forEach {
+ EbicsAccountInfoEntity.new {
+ this.subscriber = getSubscriberEntityFromId(customerIdAtNexus)
+ accountId = it.id
+ accountHolder = it.accountHolder
+ /* 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
+ }
+ }
+ }
+ call.respondText(
+ response.orderData.toString(Charsets.UTF_8),
+ ContentType.Text.Plain,
+ HttpStatusCode.OK
+ )
+ }
+ is EbicsDownloadBankErrorResult -> {
+ call.respond(
+ HttpStatusCode.BadGateway,
+ EbicsErrorJson(EbicsErrorDetailJson("bankError", response.returnCode.errorCode))
+ )
+ }
+ }
+ return@post
+ }
+
/* performs a keys backup */
post("/ebics/subscribers/{id}/backup") {
val id = expectId(call.parameters["id"])
diff --git a/sandbox/src/main/python/libeufin-cli b/sandbox/src/main/python/libeufin-cli
@@ -585,12 +585,12 @@ def prepare(ctx, account_id, nexus_base_url):
@click.argument(
"nexus-base-url"
)
-def htd(ctx, account_id, prepare, nexus_base_url):
+def fetch_accounts(ctx, account_id, prepare, nexus_base_url):
if prepare:
ctx.invoke(ini)
ctx.invoke(hia)
ctx.invoke(sync)
- url = urljoin(nexus_base_url, "/ebics/subscribers/{}/sendHtd".format(account_id))
+ url = urljoin(nexus_base_url, "/ebics/subscribers/{}/fetch-accounts".format(account_id))
try:
resp = post(url, json=dict())
except Exception: