libeufin

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

commit 70609437afe1e2f928ecd18a043556195f02623b
parent 9d8d30a59c38f2aa6cc1395739640ca6317df726
Author: Florian Dold <florian@dold.me>
Date:   Fri,  6 Aug 2021 00:07:56 +0200

implement simulate-incoming-transactions cli command

Diffstat:
Mcli/bin/libeufin-cli | 37++++++++-----------------------------
Msandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt | 6+++---
Msandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt | 41-----------------------------------------
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 35++---------------------------------
Msandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt | 9+++------
Msandbox/src/test/kotlin/CamtTest.kt | 6+++---
Mutil/src/main/kotlin/JSON.kt | 7+++----
Mutil/src/main/kotlin/Payto.kt | 3++-
8 files changed, 24 insertions(+), 120 deletions(-)

diff --git a/cli/bin/libeufin-cli b/cli/bin/libeufin-cli @@ -1054,54 +1054,33 @@ def bankaccount_generate_transactions(obj, account_label): check_response_status(resp) -@sandbox_bankaccount.command(help="Book a payment in the sandbox") -@click.option("--creditor-iban", help="IBAN receiving the payment", prompt=True) -@click.option("--creditor-bic", help="BIC receiving the payment", prompt=True) -@click.option( - "--creditor-name", - help="Name of the person who is receiving the payment", - prompt=True, -) +@sandbox_bankaccount.command(help="Book an incoming payment in the sandbox") +@click.argument("account-name") @click.option("--debtor-iban", help="IBAN sending the payment", prompt=True) @click.option("--debtor-bic", help="BIC sending the payment", prompt=True) @click.option( "--debtor-name", help="name of the person who is sending the payment", prompt=True ) @click.option("--amount", help="amount, no currency", prompt=True) -@click.option("--currency", help="currency", prompt=True) @click.option("--subject", help="payment subject", prompt=True) -@click.option( - "--direction", - help="direction respect to the bank account hosted at Sandbox: allows DBIT/CRDT values.", - prompt=True, -) @click.pass_obj -def book_payment( +def simulate_incoming_transaction( obj, - creditor_iban, - creditor_bic, - creditor_name, + account_name, debtor_iban, debtor_bic, debtor_name, amount, - currency, subject, - direction, ): sandbox_base_url = obj.require_sandbox_base_url() - url = urljoin(sandbox_base_url, "/admin/payments") + url = urljoin(sandbox_base_url, f"/admin/bank-accounts/{account_name}/simulate-incoming-transaction") body = dict( - creditorIban=creditor_iban, - creditorBic=creditor_bic, - creditorName=creditor_name, - debitorIban=debtor_iban, - debitorBic=debtor_bic, - debitorName=debtor_name, + debtorIban=debtor_iban, + debtorBic=debtor_bic, + debtorName=debtor_name, amount=amount, - currency=currency, subject=subject, - direction=direction, ) try: resp = post(url, json=body) diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt @@ -171,11 +171,11 @@ private fun getRelatedParty(branch: XmlElementBuilder, payment: RawPayment) { var bic = payment.creditorBic } if (payment.direction == "CRDT") { - otherParty.iban = payment.debitorIban + otherParty.iban = payment.debtorIban otherParty.ibanPath = "DbtrAcct/Id/IBAN" otherParty.namePath = "Dbtr/Nm" - otherParty.name = payment.debitorName - otherParty.bic = payment.debitorBic + otherParty.name = payment.debtorName + otherParty.bic = payment.debtorBic otherParty.bicPath = "DbtrAgt/FinInstnId/BIC" } branch.element("RltdPties") { diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/JSON.kt @@ -30,15 +30,6 @@ data class EbicsHostsResponse( val ebicsHosts: List<String> ) -/** - * Used to show information about ONE particular - * Ebics host that is active in the system. - */ -data class EbicsHostResponse( - val hostID: String, - val ebicsVersion: String -) - data class EbicsHostCreateRequest( val hostID: String, val ebicsVersion: String @@ -47,13 +38,6 @@ data class EbicsHostCreateRequest( /** * List type that show all the payments existing in the system. */ -data class PaymentsResponse( - val payments: MutableList<RawPayment> = mutableListOf() -) - -/** - * List type that show all the payments existing in the system. - */ data class AccountTransactions( val payments: MutableList<PaymentInfo> = mutableListOf() ) @@ -81,32 +65,7 @@ data class BankAccountRequest( val currency: String ) -data class DateRange( - val startDate: Long, - val endDate: Long -) - data class CamtParams( val iban: String, val type: Int ) - -data class BankAccountStatements( - var bankAccountStatements: MutableList<BankAccountStatement> = mutableListOf() -) - -data class BankAccountReports( - var bankAccountReports: MutableList<BankAccountReport> = mutableListOf() -) - -data class BankAccountStatement( - var statementId: String, - var creationTime: Long, - var message: MutableList<String> = mutableListOf() -) - -data class BankAccountReport( - var reportId: String, - var creationTime: Long, - val message: String -) diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -66,7 +66,6 @@ import com.github.ajalt.clikt.parameters.options.flag import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.versionOption import com.github.ajalt.clikt.parameters.types.int -import com.google.common.collect.Maps import com.google.common.io.Resources import execThrowableOrTerminate import io.ktor.application.ApplicationCall @@ -87,14 +86,12 @@ import tech.libeufin.sandbox.BankAccountTransactionsTable.debtorIban import tech.libeufin.sandbox.BankAccountTransactionsTable.debtorName import tech.libeufin.sandbox.BankAccountTransactionsTable.direction import tech.libeufin.sandbox.BankAccountTransactionsTable.pmtInfId -import tech.libeufin.sandbox.SandboxConfigEntity import tech.libeufin.util.* import tech.libeufin.util.ebics_h004.EbicsResponse import tech.libeufin.util.ebics_h004.EbicsTypes import java.net.BindException import java.util.* import kotlin.random.Random -import kotlin.reflect.jvm.internal.impl.load.kotlin.JvmType import kotlin.system.exitProcess const val SANDBOX_DB_ENV_VAR_NAME = "LIBEUFIN_SANDBOX_DB_CONNECTION" @@ -435,34 +432,6 @@ fun serverMain(dbName: String, port: Int) { return@post } - /** - * Adds a new payment to the book. - */ - post("/admin/payments") { - val body = call.receiveJson<RawPayment>() - val randId = getRandomString(16) - transaction { - val localIban = if (body.direction == "DBIT") body.debitorIban else body.creditorIban - BankAccountTransactionsTable.insert { - it[creditorIban] = body.creditorIban - it[creditorBic] = body.creditorBic - it[creditorName] = body.creditorName - it[debtorIban] = body.debitorIban - it[debtorBic] = body.debitorBic - it[debtorName] = body.debitorName - it[subject] = body.subject - it[amount] = body.amount - it[currency] = body.currency - it[date] = Instant.now().toEpochMilli() - it[accountServicerReference] = "sandbox-$randId" - it[account] = getBankAccountFromIban(localIban).id - it[direction] = body.direction - } - } - call.respondText("Payment created") - return@post - } - post("/admin/bank-accounts/{label}/simulate-incoming-transaction") { val body = call.receiveJson<IncomingPaymentInfo>() // FIXME: generate nicer UUID! @@ -494,7 +463,7 @@ fun serverMain(dbName: String, port: Int) { post("/admin/ebics/bank-accounts") { val body = call.receiveJson<BankAccountRequest>() transaction { - var subscriber = getEbicsSubscriberFromDetails( + val subscriber = getEbicsSubscriberFromDetails( body.subscriber.userID, body.subscriber.partnerID, body.subscriber.hostID @@ -504,7 +473,7 @@ fun serverMain(dbName: String, port: Int) { bic = body.bic name = body.name label = body.label - currency = body.currency.toUpperCase(Locale.ROOT) + currency = body.currency.uppercase(Locale.ROOT) } } call.respondText("Bank account created") diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt @@ -9,7 +9,6 @@ import tech.libeufin.sandbox.BankAccountTransactionsTable.amount import tech.libeufin.util.RawPayment import tech.libeufin.util.importDateFromMillis import tech.libeufin.util.toDashedDate -import java.math.BigInteger private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.sandbox") @@ -54,7 +53,6 @@ fun historyForAccount(iban: String): List<RawPayment> { FIXME: add the following condition too: and (BankAccountTransactionsTable.date.between(start.millis, end.millis)) */ - }.forEach { history.add( RawPayment( @@ -62,9 +60,9 @@ fun historyForAccount(iban: String): List<RawPayment> { creditorIban = it[BankAccountTransactionsTable.creditorIban], creditorBic = it[BankAccountTransactionsTable.creditorBic], creditorName = it[BankAccountTransactionsTable.creditorName], - debitorIban = it[BankAccountTransactionsTable.debtorIban], - debitorBic = it[BankAccountTransactionsTable.debtorBic], - debitorName = it[BankAccountTransactionsTable.debtorName], + debtorIban = it[BankAccountTransactionsTable.debtorIban], + debtorBic = it[BankAccountTransactionsTable.debtorBic], + debtorName = it[BankAccountTransactionsTable.debtorName], date = importDateFromMillis(it[BankAccountTransactionsTable.date]).toDashedDate(), amount = it[BankAccountTransactionsTable.amount], currency = it[BankAccountTransactionsTable.currency], @@ -77,7 +75,6 @@ fun historyForAccount(iban: String): List<RawPayment> { ) ) } - } return history } diff --git a/sandbox/src/test/kotlin/CamtTest.kt b/sandbox/src/test/kotlin/CamtTest.kt @@ -12,9 +12,9 @@ class CamtTest { creditorIban = "GB33BUKB20201222222222", creditorName = "Oliver Smith", creditorBic = "BUKBGB33", - debitorIban = "GB33BUKB20201333333333", - debitorName = "John Doe", - debitorBic = "BUKBGB33", + debtorIban = "GB33BUKB20201333333333", + debtorName = "John Doe", + debtorBic = "BUKBGB33", amount = "2", currency = "EUR", subject = "reimbursement", diff --git a/util/src/main/kotlin/JSON.kt b/util/src/main/kotlin/JSON.kt @@ -28,9 +28,9 @@ data class RawPayment( val creditorIban: String, val creditorBic: String?, val creditorName: String, - val debitorIban: String, - val debitorBic: String?, - val debitorName: String, + val debtorIban: String, + val debtorBic: String?, + val debtorName: String, val amount: String, val currency: String, val subject: String, @@ -50,7 +50,6 @@ data class IncomingPaymentInfo( val debtorBic: String?, val debtorName: String, val amount: String, - val currency: String, val subject: String ) diff --git a/util/src/main/kotlin/Payto.kt b/util/src/main/kotlin/Payto.kt @@ -13,7 +13,8 @@ data class Payto( class InvalidPaytoError(msg: String) : Exception(msg) fun parsePayto(paytoLine: String): Payto { - if (!"^payto://".toRegex().containsMatchIn(paytoLine)) throw InvalidPaytoError("Invalid payto line: $paytoLine") + if (!paytoLine.startsWith("payto://")) + throw InvalidPaytoError("Invalid payto URI: $paytoLine") val javaParsedUri = try { URI(paytoLine) } catch (e: java.lang.Exception) {