commit c868441acbfb1f3e72f5a254e97c38883afaca79 parent a3d7b777d04c44d53419a197d2466bf5c3572fe9 Author: MS <ms@taler.net> Date: Tue, 29 Nov 2022 15:16:20 +0100 logging wire transfer subjects along Pain communication Diffstat:
4 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Scheduling.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Scheduling.kt @@ -53,11 +53,17 @@ private suspend fun runTask(client: HttpClient, sched: TaskSchedule) { when (sched.resourceType) { "bank-account" -> { when (sched.type) { + /** + * Downloads and ingests the payment records from the bank. + */ "fetch" -> { @Suppress("BlockingMethodInNonBlockingContext") val fetchSpec = jacksonObjectMapper().readValue(sched.params, FetchSpecJson::class.java) fetchBankAccountTransactions(client, fetchSpec, sched.resourceId) } + /** + * Submits the payment preparations that are found in the database. + */ "submit" -> { submitAllPaymentInitiations(client, sched.resourceId) } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/bankaccount/BankAccount.kt @@ -78,7 +78,6 @@ suspend fun submitAllPaymentInitiations(httpClient: HttpClient, accountid: Strin data class Submission( val id: Long ) - logger.debug("auto-submitter started") val workQueue = mutableListOf<Submission>() transaction { val account = NexusBankAccountEntity.findByName(accountid) ?: throw NexusError( @@ -91,12 +90,14 @@ suspend fun submitAllPaymentInitiations(httpClient: HttpClient, accountid: Strin }.forEach { // Filter out non EBICS. val defaultBankConnectionId = it.bankAccount.defaultBankConnection?.id ?: throw NexusError( - HttpStatusCode.BadRequest, - "needs default bank connection" + HttpStatusCode.NotFound, + "Default bank connection not found. Can't submit Pain document" ) val bankConnection = NexusBankConnectionEntity.findById(defaultBankConnectionId) ?: throw NexusError( HttpStatusCode.InternalServerError, - "Bank account '${it.id.value}' doesn't map to any bank connection (named '${defaultBankConnectionId}')" + "Bank connection '$defaultBankConnectionId' " + + "(pointed by bank account '${it.bankAccount.bankAccountName}')" + + " not found in the database." ) if (bankConnection.type != "ebics") { logger.info("Skipping non-implemented bank connection '${bankConnection.type}'") @@ -106,7 +107,6 @@ suspend fun submitAllPaymentInitiations(httpClient: HttpClient, accountid: Strin } } workQueue.forEach { - logger.debug("Submitting payment ${it.id}") submitPaymentInitiation(httpClient, it.id) } } diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsNexus.kt @@ -501,7 +501,9 @@ class EbicsBankConnectionProtocol: BankConnectionProtocol { subscriberDetails ) } - + /** + * Submit one Pain.001 for one payment initiations. + */ override suspend fun submitPaymentInitiation(httpClient: HttpClient, paymentInitiationId: Long) { val r = transaction { val paymentInitiation = PaymentInitiationEntity.findById(paymentInitiationId) @@ -527,7 +529,8 @@ class EbicsBankConnectionProtocol: BankConnectionProtocol { messageId = paymentInitiation.messageId ) ) - logger.debug("Sending Pain.001: ${paymentInitiation.paymentInformationId}") + logger.debug("Sending Pain.001: ${paymentInitiation.paymentInformationId}," + + " for payment: '${paymentInitiation.subject}'") if (!XMLUtil.validateFromString(painMessage)) throw NexusError( HttpStatusCode.InternalServerError, "Pain.001 message is invalid." ) diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt @@ -704,14 +704,15 @@ private fun parsePain001(paymentRequest: String): PainParseResult { */ private fun handleCct(paymentRequest: String) { val parseResult = parsePain001(paymentRequest) - logger.debug("Handling Pain.001: ${parseResult.pmtInfId}") + logger.debug("Handling Pain.001: ${parseResult.pmtInfId}, " + + "for payment: ${parseResult.subject}") transaction(Connection.TRANSACTION_SERIALIZABLE, repetitionAttempts = 10) { val maybeExist = BankAccountTransactionEntity.find { BankAccountTransactionsTable.pmtInfId eq parseResult.pmtInfId }.firstOrNull() if (maybeExist != null) { logger.info( - "Nexus submitted twice the PAIN: ${maybeExist.pmtInfId}. Not taking any action." + + "Nexus submitted twice the Pain: ${maybeExist.pmtInfId}. Not taking any action." + " Sandbox gave it this reference: ${maybeExist.accountServicerReference}" ) return@transaction