commit 26c237198c053efb21fc29bf2e422fa1726a47ee
parent aa9d92d3a10505c3eeba2c0068b40f5aa4917ae2
Author: MS <ms@taler.net>
Date: Thu, 9 Nov 2023 11:48:39 +0100
storing pain.001 as log file
Diffstat:
1 file changed, 34 insertions(+), 0 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt
@@ -29,10 +29,19 @@ import tech.libeufin.nexus.ebics.EbicsEarlyException
import tech.libeufin.nexus.ebics.EbicsUploadException
import tech.libeufin.nexus.ebics.submitPain001
import tech.libeufin.util.parsePayto
+import tech.libeufin.util.toDbMicros
+import java.io.File
+import java.nio.file.Path
+import java.text.DateFormat
import java.time.Instant
+import java.time.LocalDate
+import java.time.ZoneId
import java.util.*
import javax.xml.crypto.Data
import kotlin.concurrent.fixedRateTimer
+import kotlin.io.path.createDirectories
+import kotlin.io.path.createParentDirectories
+import kotlin.math.log
import kotlin.system.exitProcess
/**
@@ -127,6 +136,31 @@ private suspend fun submitInitiatedPayment(
cause = permanent
)
}
+ // Submission succeeded, storing the pain.001 to file.
+ val logDir: String? = cfg.config.lookupString(
+ "[neuxs-submit]",
+ "SUBMISSIONS_LOG_DIRECTORY"
+ )
+ if (logDir != null) {
+ try { Path.of(logDir).createDirectories() }
+ catch (e: Exception) {
+ logger.error("Could not create log directory of path: $logDir")
+ exitProcess(1)
+ }
+ val now = Instant.now()
+ val asUtcDate = LocalDate.ofInstant(now, ZoneId.of("UTC"))
+ val f = Path.of(
+ "${asUtcDate.year}-${asUtcDate.monthValue}-${asUtcDate.dayOfMonth}",
+ "${now.toDbMicros()}_requestUid_${initiatedPayment.requestUid}_pain.001.xml"
+ ).toFile()
+ val completePath = Path.of(logDir, f.path)
+ // Very rare: same pain.001 should not be submitted twice in the same microsecond.
+ if (f.exists()) {
+ logger.error("pain.001 log file exists already at: $completePath")
+ exitProcess(1)
+ }
+ completePath.toFile().writeText(xml)
+ }
}
/**