libeufin

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

commit 3172664f1e0df86e576ade5f940886c7e01c2cd1
parent f54bd1bc9f106d18ed5b562729f701bfd50eb372
Author: Florian Dold <florian.dold@gmail.com>
Date:   Fri, 19 Jun 2020 00:10:52 +0530

terminology

Diffstat:
Mintegration-tests/start-testenv.py | 4++--
Mintegration-tests/test-ebics-highlevel.py | 6+++---
Mintegration-tests/test-ebics.py | 4++--
Mnexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt | 4++--
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 43+++++++++++++++++++++----------------------
Mnexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt | 13++++++-------
Mnexus/src/main/kotlin/tech/libeufin/nexus/taler.kt | 4++--
7 files changed, 38 insertions(+), 40 deletions(-)

diff --git a/integration-tests/start-testenv.py b/integration-tests/start-testenv.py @@ -402,7 +402,7 @@ assertResponse( # # 5.a, prepare a payment # resp = assertResponse( # post( -# "http://localhost:5001/bank-accounts/{}/prepared-payments".format( +# "http://localhost:5001/bank-accounts/{}/payment-initiations".format( # BC1_SUBSCRIBER1_BANK_ACCOUNT_LABEL # ), # json=dict( @@ -422,7 +422,7 @@ assertResponse( # # 5.b, submit prepared statement # assertResponse( # post( -# f"http://localhost:5001/bank-accounts/{BC1_SUBSCRIBER1_BANK_ACCOUNT_LABEL}/prepared-payments/{PREPARED_PAYMENT_UUID}/submit", +# f"http://localhost:5001/bank-accounts/{BC1_SUBSCRIBER1_BANK_ACCOUNT_LABEL}/payment-initiations/{PREPARED_PAYMENT_UUID}/submit", # json=dict(), # headers=dict(Authorization=USER_AUTHORIZATION_HEADER), # ) diff --git a/integration-tests/test-ebics-highlevel.py b/integration-tests/test-ebics-highlevel.py @@ -179,7 +179,7 @@ if len(resp.json().get("transactions")) != 0: # 5.a, prepare a payment resp = assertResponse( post( - "http://localhost:5001/bank-accounts/{}/prepared-payments".format( + "http://localhost:5001/bank-accounts/{}/payment-initiations".format( BANK_ACCOUNT_LABEL ), json=dict( @@ -196,10 +196,10 @@ PREPARED_PAYMENT_UUID = resp.json().get("uuid") if PREPARED_PAYMENT_UUID == None: fail("Payment UUID not received") -# 5.b, submit prepared statement +# 5.b, submit payment initiation assertResponse( post( - f"http://localhost:5001/bank-accounts/{BANK_ACCOUNT_LABEL}/prepared-payments/{PREPARED_PAYMENT_UUID}/submit", + f"http://localhost:5001/bank-accounts/{BANK_ACCOUNT_LABEL}/payment-initiations/{PREPARED_PAYMENT_UUID}/submit", json=dict(), headers=dict(Authorization=USER_AUTHORIZATION_HEADER), ) diff --git a/integration-tests/test-ebics.py b/integration-tests/test-ebics.py @@ -207,7 +207,7 @@ if len(resp.json().get("transactions")) != 0: # 5.a, prepare a payment resp = assertResponse( post( - "http://localhost:5001/bank-accounts/{}/prepared-payments".format( + "http://localhost:5001/bank-accounts/{}/payment-initiations".format( BANK_ACCOUNT_LABEL ), json=dict( @@ -227,7 +227,7 @@ if PREPARED_PAYMENT_UUID == None: # 5.b, submit prepared statement assertResponse( post( - f"http://localhost:5001/bank-accounts/{BANK_ACCOUNT_LABEL}/prepared-payments/{PREPARED_PAYMENT_UUID}/submit", + f"http://localhost:5001/bank-accounts/{BANK_ACCOUNT_LABEL}/payment-initiations/{PREPARED_PAYMENT_UUID}/submit", json=dict(), headers=dict(Authorization=USER_AUTHORIZATION_HEADER), ) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt @@ -210,7 +210,7 @@ data class BankProtocolsResponse( ) /** Request type of "POST /prepared-payments" */ -data class PreparedPaymentRequest( +data class CreatePaymentInitiationRequest( val iban: String, val bic: String?, val name: String, @@ -219,7 +219,7 @@ data class PreparedPaymentRequest( ) /** Response type of "POST /prepared-payments" */ -data class PreparedPaymentResponse( +data class PaymentInitiationResponse( val uuid: String ) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -246,7 +246,7 @@ fun moreFrequentBackgroundTasks(httpClient: HttpClient) { } // FIXME: should be done automatically after raw ingestion reportAndIgnoreErrors { ingestTalerTransactions() } - reportAndIgnoreErrors { submitAllPreparedPayments(httpClient) } + reportAndIgnoreErrors { submitAllPaymentInitiations(httpClient) } logger.debug("More frequent background jobs done") delay(Duration.ofSeconds(1)) } @@ -548,53 +548,52 @@ fun serverMain(dbName: String) { /** * Submit one particular payment to the bank. */ - post("/bank-accounts/{accountid}/prepared-payments/{uuid}/submit") { + post("/bank-accounts/{accountid}/payment-initiations/{uuid}/submit") { val uuid = ensureLong(call.parameters["uuid"]) val accountId = ensureNonNull(call.parameters["accountid"]) val res = transaction { authenticateRequest(call.request) } - submitPreparedPayment(client, uuid) + submitPaymentInitiation(client, uuid) call.respondText("Payment ${uuid} submitted") return@post } /** - * Shows information about one particular prepared payment. + * Shows information about one particular payment initiation. */ - get("/bank-accounts/{accountid}/prepared-payments/{uuid}") { + get("/bank-accounts/{accountid}/payment-initiations/{uuid}") { val res = transaction { val user = authenticateRequest(call.request) - val preparedPayment = getPreparedPayment(ensureLong(call.parameters["uuid"])) + val paymentInitiation = getPaymentInitiation(ensureLong(call.parameters["uuid"])) return@transaction object { - val preparedPayment = preparedPayment + val paymentInitiation = paymentInitiation } } - val sd = res.preparedPayment.submissionDate + val sd = res.paymentInitiation.submissionDate call.respond( PaymentStatus( - paymentInitiationId = res.preparedPayment.id.value.toString(), - submitted = res.preparedPayment.submitted, - creditorName = res.preparedPayment.creditorName, - creditorBic = res.preparedPayment.creditorBic, - creditorIban = res.preparedPayment.creditorIban, - amount = "${res.preparedPayment.currency}:${res.preparedPayment.sum}", - subject = res.preparedPayment.subject, + paymentInitiationId = res.paymentInitiation.id.value.toString(), + submitted = res.paymentInitiation.submitted, + creditorName = res.paymentInitiation.creditorName, + creditorBic = res.paymentInitiation.creditorBic, + creditorIban = res.paymentInitiation.creditorIban, + amount = "${res.paymentInitiation.currency}:${res.paymentInitiation.sum}", + subject = res.paymentInitiation.subject, submissionDate = if (sd != null) { importDateFromMillis(sd).toDashedDate() } else null, - preparationDate = importDateFromMillis(res.preparedPayment.preparationDate).toDashedDate() + preparationDate = importDateFromMillis(res.paymentInitiation.preparationDate).toDashedDate() ) ) return@get } - /** - * Adds a new prepared payment. + * Adds a new payment initiation. */ - post("/bank-accounts/{accountid}/prepared-payments") { - val body = call.receive<PreparedPaymentRequest>() + post("/bank-accounts/{accountid}/payment-initiations") { + val body = call.receive<CreatePaymentInitiationRequest>() val accountId = ensureNonNull(call.parameters["accountid"]) val res = transaction { authenticateRequest(call.request) @@ -603,7 +602,7 @@ fun serverMain(dbName: String) { throw NexusError(HttpStatusCode.NotFound, "unknown bank account") } val amount = parseAmount(body.amount) - val paymentEntity = addPreparedPayment( + val paymentEntity = addPaymentInitiation( Pain001Data( creditorIban = body.iban, creditorBic = body.bic, @@ -620,7 +619,7 @@ fun serverMain(dbName: String) { } call.respond( HttpStatusCode.OK, - PreparedPaymentResponse(uuid = res.uuid.toString()) + PaymentInitiationResponse(uuid = res.uuid.toString()) ) return@post } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt @@ -32,7 +32,7 @@ import tech.libeufin.util.XMLUtil import java.time.Instant -suspend fun submitPreparedPayment(httpClient: HttpClient, paymentInitiationId: Long) { +suspend fun submitPaymentInitiation(httpClient: HttpClient, paymentInitiationId: Long) { val r = transaction { val paymentInitiation = PaymentInitiationEntity.findById(paymentInitiationId) if (paymentInitiation == null) { @@ -55,7 +55,7 @@ suspend fun submitPreparedPayment(httpClient: HttpClient, paymentInitiationId: L /** * Submit all pending prepared payments. */ -suspend fun submitAllPreparedPayments(httpClient: HttpClient) { +suspend fun submitAllPaymentInitiations(httpClient: HttpClient) { data class Submission( val id: Long ) @@ -81,7 +81,7 @@ suspend fun submitAllPreparedPayments(httpClient: HttpClient) { } } workQueue.forEach { - submitPreparedPayment(httpClient, it.id) + submitPaymentInitiation(httpClient, it.id) } } @@ -188,10 +188,9 @@ fun ingestBankMessagesIntoAccount( } /** - * Retrieve prepared payment from database, raising exception - * if not found. + * Retrieve payment initiation from database, raising exception if not found. */ -fun getPreparedPayment(uuid: Long): PaymentInitiationEntity { +fun getPaymentInitiation(uuid: Long): PaymentInitiationEntity { return transaction { PaymentInitiationEntity.findById(uuid) } ?: throw NexusError( @@ -208,7 +207,7 @@ fun getPreparedPayment(uuid: Long): PaymentInitiationEntity { * it will be the account whose money will pay the wire transfer being defined * by this pain document. */ -fun addPreparedPayment(paymentData: Pain001Data, debitorAccount: NexusBankAccountEntity): PaymentInitiationEntity { +fun addPaymentInitiation(paymentData: Pain001Data, debitorAccount: NexusBankAccountEntity): PaymentInitiationEntity { return transaction { val now = Instant.now().toEpochMilli() val nowHex = now.toString(16) diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt @@ -38,7 +38,7 @@ import org.jetbrains.exposed.dao.Entity import org.jetbrains.exposed.dao.id.IdTable import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.transactions.transaction -import tech.libeufin.nexus.bankaccount.addPreparedPayment +import tech.libeufin.nexus.bankaccount.addPaymentInitiation import tech.libeufin.util.* import kotlin.math.abs import kotlin.math.min @@ -256,7 +256,7 @@ private suspend fun talerTransfer(call: ApplicationCall) { } } val exchangeBankAccount = getTalerFacadeBankAccount(expectNonNull(call.parameters["fcid"])) - val pain001 = addPreparedPayment( + val pain001 = addPaymentInitiation( Pain001Data( creditorIban = creditorData.iban, creditorBic = creditorData.bic,