libeufin

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

commit e61efb3a0f48d315ec2b4d2d162ab48b3e3b9052
parent b50d1893a9622583361b5ea843f105fe7fc058e5
Author: MS <ms@taler.net>
Date:   Sat, 20 Jun 2020 23:56:49 +0200

importing accounts using custom label

Diffstat:
Mcli/libeufin-cli-new | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcli/setup-template.sh | 15---------------
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 3++-
Mnexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt | 28+++++++++++++++++++++++++++-
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt | 5+++++
5 files changed, 87 insertions(+), 17 deletions(-)

diff --git a/cli/libeufin-cli-new b/cli/libeufin-cli-new @@ -138,6 +138,59 @@ def bootstrap_bank_connection(obj, connection_name, nexus_user_id, nexus_passwor return print(resp.content.decode("utf-8")) +@bank_connection.command(help="import one bank account, chosen from the downloaded ones") +@click.option("--connection-name", help="Connection ID", required=True) +@click.option("--nexus-user-id", help="Nexus user ID", required=True) +@click.option("--nexus-password", help="Nexus password", required=True) +@click.option("--account-id", help="Name of the account to import", required=True) +@click.option("--local-name", help="Name to give to the imported account", required=True) +@click.argument("nexus-base-url") +@click.pass_obj +def import_bank_account(obj, connection_name, nexus_user_id, nexus_password, nexus_base_url, account_id, local_name): + # FIXME/NOTE: the 'ebics' part will soon go away. + url = urljoin(nexus_base_url, "/bank-connections/{}/ebics/accounts/import".format(connection_name)) + print("going {}".format(url)) + try: + resp = post(url, json=dict(accountId=account_id, localName=local_name), auth = auth.HTTPBasicAuth(nexus_user_id, nexus_password)) + except Exception as ee: + print(ee) + print("Could not reach nexus") + return + print(resp.content.decode("utf-8")) + +@bank_connection.command(help="download bank accounts in raw format WITHOUT importing them") +@click.option("--connection-name", help="Connection ID", required=True) +@click.option("--nexus-user-id", help="Nexus user ID", required=True) +@click.option("--nexus-password", help="Nexus password", required=True) +@click.argument("nexus-base-url") +@click.pass_obj +def download_bank_accounts(obj, connection_name, nexus_user_id, nexus_password, nexus_base_url): + # FIXME/NOTE: the 'ebics' part will soon go away. + url = urljoin(nexus_base_url, "/bank-connections/{}/ebics/accounts/fetch".format(connection_name)) + try: + resp = post(url, json=dict(), auth = auth.HTTPBasicAuth(nexus_user_id, nexus_password)) + except Exception: + print("Could not reach nexus") + return + print(resp.content.decode("utf-8")) + + +@bank_connection.command(help="list raw bank account information locally stored") +@click.option("--connection-name", help="Connection ID", required=True) +@click.option("--nexus-user-id", help="Nexus user ID", required=True) +@click.option("--nexus-password", help="Nexus password", required=True) +@click.argument("nexus-base-url") +@click.pass_obj +def list_bank_accounts(obj, connection_name, nexus_user_id, nexus_password, nexus_base_url): + # FIXME/NOTE: the 'ebics' part will soon go away. + url = urljoin(nexus_base_url, "/bank-connections/{}/ebics/accounts".format(connection_name)) + try: + resp = get(url, json=dict(), auth = auth.HTTPBasicAuth(nexus_user_id, nexus_password)) + except Exception: + print("Could not reach nexus") + return + print(resp.content.decode("utf-8")) + @bank_connection.command(help="import related bank accounts of 'connection-name'") @click.option("--connection-name", help="Connection ID", required=True) @click.option("--nexus-user-id", help="Nexus user ID", required=True) diff --git a/cli/setup-template.sh b/cli/setup-template.sh @@ -90,18 +90,3 @@ echo Bootstrapping the bank connection --nexus-user-id $NEXUS_USER \ --nexus-password $NEXUS_PASSWORD \ $NEXUS_URL -sleep 2 - -# Fetching the bank accounts -echo Fetching the bank accounts -./libeufin-cli-new \ - bank-connection \ - import-bank-accounts \ - --connection-name $NEXUS_BANK_CONNECTION_NAME \ - --nexus-user-id $NEXUS_USER \ - --nexus-password $NEXUS_PASSWORD \ - $NEXUS_URL -sleep 2 - -echo User is setup, history can be requested, and \ - new payments can be prepared and submitted. diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -402,7 +402,8 @@ fun dbCreateTables(dbName: String) { NexusBankMessagesTable, FacadesTable, TalerFacadeStateTable, - NexusScheduledTasksTable + NexusScheduledTasksTable, + RawHTDResponsesTable ) } } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt @@ -35,6 +35,7 @@ import io.ktor.application.call import io.ktor.client.HttpClient import io.ktor.http.ContentType import io.ktor.http.HttpStatusCode +import io.ktor.request.receive import io.ktor.request.receiveOrNull import io.ktor.response.respond import io.ktor.response.respondText @@ -449,7 +450,32 @@ fun Route.ebicsBankConnectionRoutes(client: HttpClient) { } call.respond(ret) } - post("/account/import") { + post("/accounts/import") { + val body = call.receive<ImportBankAccount>() + transaction { + val conn = requireBankConnection(call, "callid") + val hasXml = RawHTDResponseEntity.findById(conn.id.value) ?: throw NexusError( + HttpStatusCode.NotFound, "Could not found raw bank account data for connection '${conn.id.value}'" + ) + XMLUtil.convertStringToJaxb<HTDResponseOrderData>(hasXml.htdResponse).value.partnerInfo.accountInfoList?.forEach { + if (it.id == body.accountId) { + NexusBankAccountEntity.new(body.localName) { + iban = it.accountNumberList?.filterIsInstance<EbicsTypes.GeneralAccountNumber>() + ?.find { it.international }?.value + ?: throw NexusError(HttpStatusCode.NotFound, reason = "bank gave no IBAN") + bankCode = it.bankCodeList?.filterIsInstance<EbicsTypes.GeneralBankCode>() + ?.find { it.international }?.value + ?: throw NexusError( + HttpStatusCode.NotFound, + reason = "bank gave no BIC" + ) + defaultBankConnection = conn + highestSeenBankMessageId = 0 + accountHolder = it.accountHolder ?: "NOT GIVEN" + } + } + } + } call.respond(object {}) } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/JSON.kt @@ -318,4 +318,9 @@ data class CreateAccountTaskRequest( val cronspec: String, val type: String, val params: JsonNode +) + +data class ImportBankAccount( + val accountId: String, + val localName: String ) \ No newline at end of file