libeufin

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

commit d3d3a521b9b5af7f4279d368e51c0cd8c4bf5781
parent 3843f67b2806231ffc0911055179bb013531de20
Author: MS <ms@taler.net>
Date:   Tue, 16 Jun 2020 14:24:20 +0200

Fixing #6251,

Initiated payments should simply have a incremental numeric id.

Diffstat:
Mcli/libeufin-cli-new | 4++--
Mnexus/src/main/kotlin/tech/libeufin/nexus/DB.kt | 24+++---------------------
Mnexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt | 18+++++++++++-------
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 8++++----
4 files changed, 20 insertions(+), 34 deletions(-)

diff --git a/cli/libeufin-cli-new b/cli/libeufin-cli-new @@ -167,8 +167,8 @@ def import_bank_accounts(obj, connection_name, nexus_user_id, nexus_password, ne @click.argument("nexus-base-url") @click.pass_obj def prepare_payment(obj, account_name, credit_iban, credit_bic, credit_name, - nexus_user_id, nexus_password, nexus_base_url): - url = urljoin(nexus_basd_url, "/bank-accounts/{}/prepared-payments".format(account_name)) + nexus_user_id, nexus_password, nexus_base_url, payment_amount, payment_subject): + url = urljoin(nexus_base_url, "/bank-accounts/{}/prepared-payments".format(account_name)) body = dict( iban=credit_iban, bic=credit_bic, diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt @@ -170,19 +170,8 @@ class RawBankTransactionEntity(id: EntityID<Long>) : LongEntity(id) { /** * Represents a prepared payment. */ -object PreparedPaymentsTable : IdTable<String>() { - /** the UUID representing this payment in the system */ - override val id = text("id").entityId() - val paymentId = long("paymentId") - - /** - * Time when the payment initiation was created. - */ +object PreparedPaymentsTable : LongIdTable() { val preparationDate = long("preparationDate") - - /** - * First time that this payment request has been submitted successfully. - */ val submissionDate = long("submissionDate").nullable() val sum = amount("sum") val currency = varchar("currency", length = 3).default("EUR") @@ -194,18 +183,11 @@ object PreparedPaymentsTable : IdTable<String>() { val debitorIban = text("debitorIban") val debitorBic = text("debitorBic") val debitorName = text("debitorName").nullable() - - /** - * Indicates whether the PAIN message was sent to the bank. - * FIXME(dold): Overlap with submissionDate?! - */ val submitted = bool("submitted").default(false) } -class PreparedPaymentEntity(id: EntityID<String>) : Entity<String>(id) { - companion object : EntityClass<String, PreparedPaymentEntity>(PreparedPaymentsTable) - - var paymentId by PreparedPaymentsTable.paymentId +class PreparedPaymentEntity(id: EntityID<Long>) : LongEntity(id) { + companion object : LongEntityClass<PreparedPaymentEntity>(PreparedPaymentsTable) var preparationDate by PreparedPaymentsTable.preparationDate var submissionDate by PreparedPaymentsTable.submissionDate var sum by PreparedPaymentsTable.sum diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt @@ -181,7 +181,6 @@ fun ingestBankMessagesIntoAccount( } } - /** * Create a PAIN.001 XML document according to the input data. * Needs to be called within a transaction block. @@ -312,7 +311,7 @@ fun createPain001document(paymentData: PreparedPaymentEntity): String { * Retrieve prepared payment from database, raising exception * if not found. */ -fun getPreparedPayment(uuid: String): PreparedPaymentEntity { +fun getPreparedPayment(uuid: Long): PreparedPaymentEntity { return transaction { PreparedPaymentEntity.findById(uuid) } ?: throw NexusError( @@ -330,9 +329,8 @@ fun getPreparedPayment(uuid: String): PreparedPaymentEntity { * by this pain document. */ fun addPreparedPayment(paymentData: Pain001Data, debitorAccount: NexusBankAccountEntity): PreparedPaymentEntity { - val randomId = Random().nextLong() return transaction { - PreparedPaymentEntity.new(randomId.toString()) { + PreparedPaymentEntity.new { subject = paymentData.subject sum = paymentData.sum debitorIban = debitorAccount.iban @@ -342,15 +340,21 @@ fun addPreparedPayment(paymentData: Pain001Data, debitorAccount: NexusBankAccoun creditorBic = paymentData.creditorBic creditorIban = paymentData.creditorIban preparationDate = Instant.now().toEpochMilli() - paymentId = randomId - endToEndId = randomId + endToEndId = 0 } } } fun ensureNonNull(param: String?): String { return param ?: throw NexusError( - HttpStatusCode.BadRequest, "Bad ID given" + HttpStatusCode.BadRequest, "Bad ID given: ${param}" + ) +} + +fun ensureLong(param: String?): Long { + val asString = ensureNonNull(param) + return asString.toLongOrNull() ?: throw NexusError( + HttpStatusCode.BadRequest, "Parameter is not a number: ${param}" ) } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -521,7 +521,7 @@ fun serverMain(dbName: String) { * Submit one particular payment to the bank. */ post("/bank-accounts/{accountid}/prepared-payments/{uuid}/submit") { - val uuid = ensureNonNull(call.parameters["uuid"]) + val uuid = ensureLong(call.parameters["uuid"]) val accountId = ensureNonNull(call.parameters["accountid"]) val res = transaction { val user = authenticateRequest(call.request) @@ -568,7 +568,7 @@ fun serverMain(dbName: String) { get("/bank-accounts/{accountid}/prepared-payments/{uuid}") { val res = transaction { val user = authenticateRequest(call.request) - val preparedPayment = getPreparedPayment(ensureNonNull(call.parameters["uuid"])) + val preparedPayment = getPreparedPayment(ensureLong(call.parameters["uuid"])) return@transaction object { val preparedPayment = preparedPayment } @@ -576,7 +576,7 @@ fun serverMain(dbName: String) { val sd = res.preparedPayment.submissionDate call.respond( PaymentStatus( - uuid = res.preparedPayment.id.value, + uuid = res.preparedPayment.id.value.toString(), submitted = res.preparedPayment.submitted, creditorName = res.preparedPayment.creditorName, creditorBic = res.preparedPayment.creditorBic, @@ -621,7 +621,7 @@ fun serverMain(dbName: String) { } call.respond( HttpStatusCode.OK, - PreparedPaymentResponse(uuid = res.uuid) + PreparedPaymentResponse(uuid = res.uuid.toString()) ) return@post }