summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine A <>2024-03-06 15:53:05 +0100
committerAntoine A <>2024-03-06 15:53:05 +0100
commitc5f106ddc3335ef63080ab4ebe4868f1f8917520 (patch)
treea13aa1c94cce4c82de6006db445bf39ac86a1c95
parent4d90ca8d61974ff8cda5c829a9f0a5d25a98bbeb (diff)
downloadlibeufin-c5f106ddc3335ef63080ab4ebe4868f1f8917520.tar.gz
libeufin-c5f106ddc3335ef63080ab4ebe4868f1f8917520.tar.bz2
libeufin-c5f106ddc3335ef63080ab4ebe4868f1f8917520.zip
Simplify ebics mess
-rw-r--r--ebics/src/main/kotlin/Ebics.kt27
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt8
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt161
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt224
4 files changed, 61 insertions, 359 deletions
diff --git a/ebics/src/main/kotlin/Ebics.kt b/ebics/src/main/kotlin/Ebics.kt
index e335e502..5588ee7f 100644
--- a/ebics/src/main/kotlin/Ebics.kt
+++ b/ebics/src/main/kotlin/Ebics.kt
@@ -123,33 +123,6 @@ fun getXmlDate(d: ZonedDateTime): XMLGregorianCalendar {
)
}
-fun makeOrderParams(orderParams: EbicsOrderParams): EbicsRequest.OrderParams {
- return when (orderParams) {
- is EbicsStandardOrderParams -> {
- EbicsRequest.StandardOrderParams().apply {
- val r = orderParams.dateRange
- if (r != null) {
- this.dateRange = EbicsRequest.DateRange().apply {
- this.start = getXmlDate(r.start)
- this.end = getXmlDate(r.end)
- }
- }
- }
- }
- is EbicsGenericOrderParams -> {
- EbicsRequest.GenericOrderParams().apply {
- this.parameterList = orderParams.params.map { entry ->
- EbicsTypes.Parameter().apply {
- this.name = entry.key
- this.value = entry.value
- this.type = "string"
- }
- }
- }
- }
- }
-}
-
fun signOrder(
orderBlob: ByteArray,
signKey: RSAPrivateCrtKey,
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
index 6b88362c..f66e77a7 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
@@ -90,16 +90,16 @@ private suspend fun downloadHelper(
ctx.cfg,
ctx.bankKeys,
ctx.clientKeys,
- prepEbics3Document(doc, lastExecutionTime)
+ doc,
+ lastExecutionTime
)
} else {
- val ebics2Req = prepEbics2Document(doc, lastExecutionTime)
createEbics25DownloadInit(
ctx.cfg,
ctx.clientKeys,
ctx.bankKeys,
- ebics2Req.messageType,
- ebics2Req.orderParams
+ doc,
+ lastExecutionTime
)
}
return ebicsDownload(
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt
index dd2cd67b..b561be8d 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics2.kt
@@ -50,9 +50,17 @@ fun createEbics25DownloadInit(
cfg: EbicsSetupConfig,
clientKeys: ClientPrivateKeysFile,
bankKeys: BankPublicKeysFile,
- orderType: String,
- orderParams: EbicsOrderParams = EbicsStandardOrderParams()
+ whichDoc: SupportedDocument,
+ startDate: Instant? = null,
+ endDate: Instant? = null,
): ByteArray {
+ val orderType = when(whichDoc) {
+ SupportedDocument.PAIN_002 -> "Z01"
+ SupportedDocument.CAMT_052 -> "Z52"
+ SupportedDocument.CAMT_053 -> "Z53"
+ SupportedDocument.CAMT_054 -> "Z54"
+ SupportedDocument.PAIN_002_LOGS -> "HAC"
+ }
val nonce = getNonce(128)
val req = EbicsRequest.createForDownloadInitializationPhase(
cfg.ebicsUserId,
@@ -67,7 +75,15 @@ fun createEbics25DownloadInit(
bankKeys.bank_encryption_public_key,
bankKeys.bank_authentication_public_key,
orderType,
- makeOrderParams(orderParams)
+ EbicsRequest.StandardOrderParams().apply {
+ if (startDate != null) {
+ val r = EbicsDateRange(startDate, endDate ?: Instant.now())
+ dateRange = EbicsRequest.DateRange().apply {
+ start = getXmlDate(r.start)
+ end = getXmlDate(r.end)
+ }
+ }
+ }
)
val doc = XMLUtil.convertJaxbToDocument(req)
XMLUtil.signEbicsDocument(
@@ -239,141 +255,4 @@ fun generateHpbMessage(cfg: EbicsSetupConfig, clientKeys: ClientPrivateKeysFile)
val doc = XMLUtil.convertJaxbToDocument(hpbRequest)
XMLUtil.signEbicsDocument(doc, clientKeys.authentication_private_key)
return XMLUtil.convertDomToBytes(doc)
-}
-
-/**
- * Collects message type and date range of an EBICS 2 request.
- */
-data class Ebics2Request(
- val messageType: String,
- val orderParams: EbicsOrderParams
-)
-
-/**
- * Prepares an EBICS 2 request to get pain.002 acknowledgements
- * about submitted pain.001 documents.
- *
- * @param startDate earliest timestamp of the returned document(s). If
- * null, it defaults to download the unseen documents.
- * @param endDate latest timestamp of the returned document(s). If
- * null, it defaults to the current time.
- * @return [Ebics2Request] object to be first converted in XML and
- * then be passed to the EBICS downloader.
- */
-private fun prepAckRequest2(
- startDate: Instant? = null,
- endDate: Instant? = null
-): Ebics2Request {
- val maybeDateRange = if (startDate != null) EbicsDateRange(startDate, endDate ?: Instant.now()) else null
- return Ebics2Request(
- messageType = "Z01",
- orderParams = EbicsStandardOrderParams(dateRange = maybeDateRange)
- )
-}
-
-/**
- * Prepares an EBICS 2 request to get intraday camt.052 reports.
- *
- * @param startDate earliest timestamp of the returned document(s). If
- * null, it defaults to download the unseen documents.
- * @param endDate latest timestamp of the returned document(s). If
- * null, it defaults to the current time.
- * @return [Ebics2Request] object to be first converted in XML and
- * then be passed to the EBICS downloader.
- */
-private fun prepReportRequest2(
- startDate: Instant? = null,
- endDate: Instant? = null
-): Ebics2Request {
- val maybeDateRange = if (startDate != null) EbicsDateRange(startDate, endDate ?: Instant.now()) else null
- return Ebics2Request(
- messageType = "Z52",
- orderParams = EbicsStandardOrderParams(dateRange = maybeDateRange)
- )
-}
-
-/**
- * Prepares an EBICS 2 request to get daily camt.053 statements.
- *
- * @param startDate earliest timestamp of the returned document(s). If
- * null, it defaults to download the unseen documents.
- * @param endDate latest timestamp of the returned document(s). If
- * null, it defaults to the current time.
- * @return [Ebics2Request] object to be first converted in XML and
- * then be passed to the EBICS downloader.
- */
-private fun prepStatementRequest2(
- startDate: Instant? = null,
- endDate: Instant? = null
-): Ebics2Request {
- val maybeDateRange = if (startDate != null) EbicsDateRange(startDate, endDate ?: Instant.now()) else null
- return Ebics2Request(
- messageType = "Z53",
- orderParams = EbicsStandardOrderParams(dateRange = maybeDateRange)
- )
-}
-
-/**
- * Prepares an EBICS 2 request to get camt.054 notifications.
- *
- * @param startDate earliest timestamp of the returned document(s). If
- * null, it defaults to download the unseen documents.
- * @param endDate latest timestamp of the returned document(s). If
- * null, it defaults to the current time.
- * @return [Ebics2Request] object to be first converted in XML and
- * then be passed to the EBICS downloader.
- */
-private fun prepNotificationRequest2(
- startDate: Instant? = null,
- endDate: Instant? = null
-): Ebics2Request {
- val maybeDateRange = if (startDate != null) EbicsDateRange(startDate, endDate ?: Instant.now()) else null
- return Ebics2Request(
- messageType = "Z54", // ZS2 is the non-appendix type
- orderParams = EbicsStandardOrderParams(dateRange = maybeDateRange)
- )
-}
-
-/**
- * Prepares an EBICS 2 request to get logs from the bank about any
- * uploaded or downloaded document.
- *
- * @param startDate earliest timestamp of the returned document(s). If
- * null, it defaults to download the unseen documents.
- * @param endDate latest timestamp of the returned document(s). If
- * null, it defaults to the current time.
- * @return [Ebics2Request] object to be first converted in XML and
- * then be passed to the EBICS downloader.
- */
-private fun prepLogsRequest2(
- startDate: Instant? = null,
- endDate: Instant? = null
-): Ebics2Request {
- val maybeDateRange = if (startDate != null) EbicsDateRange(startDate, endDate ?: Instant.now()) else null
- return Ebics2Request(
- messageType = "HAC",
- orderParams = EbicsStandardOrderParams(dateRange = maybeDateRange)
- )
-}
-
-/**
- * Abstracts EBICS 2 request creation of a download init phase.
- *
- * @param whichDoc type of wanted document.
- * @param startDate earliest timestamp of the document(s) to download.
- * If null, it gets the unseen documents. If defined,
- * the latest timestamp defaults to the current time.
- * @return [Ebics2Request] to be converted to XML string and passed to
- * the EBICS downloader.
- */
-fun prepEbics2Document(
- whichDoc: SupportedDocument,
- startDate: Instant? = null
-): Ebics2Request =
- when(whichDoc) {
- SupportedDocument.PAIN_002 -> prepAckRequest2(startDate)
- SupportedDocument.CAMT_052 -> prepReportRequest2(startDate)
- SupportedDocument.CAMT_053 -> prepStatementRequest2(startDate)
- SupportedDocument.CAMT_054 -> prepNotificationRequest2(startDate)
- SupportedDocument.PAIN_002_LOGS -> prepLogsRequest2(startDate)
- } \ No newline at end of file
+} \ No newline at end of file
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt
index 09aac3df..e1b17699 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt
@@ -97,6 +97,7 @@ fun createEbics3DownloadTransferPhase(
return XMLUtil.convertDomToBytes(doc)
}
+
/**
* Creates the EBICS 3 document for the init phase of a download
* transaction.
@@ -110,7 +111,9 @@ fun createEbics3DownloadInitialization(
cfg: EbicsSetupConfig,
bankkeys: BankPublicKeysFile,
clientKeys: ClientPrivateKeysFile,
- orderParams: Ebics3Request.OrderDetails.BTDOrderParams
+ whichDoc: SupportedDocument,
+ startDate: Instant? = null,
+ endDate: Instant? = null
): ByteArray {
val nonce = getNonce(128)
val req = Ebics3Request.createForDownloadInitializationPhase(
@@ -121,7 +124,38 @@ fun createEbics3DownloadInitialization(
DatatypeFactory.newInstance().newXMLGregorianCalendar(GregorianCalendar()),
bankAuthPub = bankkeys.bank_authentication_public_key,
bankEncPub = bankkeys.bank_encryption_public_key,
- myOrderParams = orderParams
+ myOrderParams = Ebics3Request.OrderDetails.BTDOrderParams().apply {
+ service = Ebics3Request.OrderDetails.Service().apply {
+ serviceName = when(whichDoc) {
+ SupportedDocument.PAIN_002 -> "PSR"
+ SupportedDocument.CAMT_052 -> "STM"
+ SupportedDocument.CAMT_053 -> "EOP"
+ SupportedDocument.CAMT_054 -> "REP"
+ SupportedDocument.PAIN_002_LOGS -> throw Exception("HAC (--only-logs) not available in EBICS 3")
+ }
+ scope = "CH"
+ container = Ebics3Request.OrderDetails.Service.Container().apply {
+ containerType = "ZIP"
+ }
+ messageName = Ebics3Request.OrderDetails.Service.MessageName().apply {
+ val (msg_value, msg_version) = when(whichDoc) {
+ SupportedDocument.PAIN_002 -> Pair("pain.002", "10")
+ SupportedDocument.CAMT_052 -> Pair("pain.052", "08")
+ SupportedDocument.CAMT_053 -> Pair("pain.053", "08")
+ SupportedDocument.CAMT_054 -> Pair("camt.054", "08")
+ SupportedDocument.PAIN_002_LOGS -> throw Exception("HAC (--only-logs) not available in EBICS 3")
+ }
+ value = msg_value
+ version = msg_version
+ }
+ }
+ if (startDate != null) {
+ Ebics3Request.DateRange().apply {
+ start = getXmlDate(startDate)
+ end = getXmlDate(endDate ?: Instant.now())
+ }
+ }
+ }
)
val doc = XMLUtil.convertJaxbToDocument(
req,
@@ -256,188 +290,4 @@ suspend fun submitPain001(
" bank technical return code is: ${maybeUploaded.bankReturnCode}"
)
return maybeUploaded.orderID!!
-}
-
-/**
- * Crafts a date range object, when the caller needs a time range.
- *
- * @param startDate inclusive starting date for the returned banking events.
- * @param endDate inclusive ending date for the returned banking events.
- * @return [Ebics3Request.DateRange]
- */
-private fun getEbics3DateRange(
- startDate: Instant,
- endDate: Instant
-): Ebics3Request.DateRange {
- return Ebics3Request.DateRange().apply {
- start = getXmlDate(startDate)
- end = getXmlDate(endDate)
- }
-}
-
-/**
- * Prepares the request for a camt.054 notification from the bank,
- * via EBICS 3.
- * Notifications inform the subscriber that some new events occurred
- * on their account. One main difference with reports/statements is
- * that notifications - according to the ISO20022 documentation - do
- * NOT contain any balance.
- *
- * @param startDate inclusive starting date for the returned notification(s).
- * @param endDate inclusive ending date for the returned notification(s). NOTE:
- * if startDate is NOT null and endDate IS null, endDate gets defaulted
- * to the current UTC time.
- * @param isAppendix if true, the responded camt.054 will be an appendix of
- * another camt.053 document, not therefore strictly acting as a notification.
- * For example, camt.053 may omit wire transfer subjects and its related
- * camt.054 appendix would instead contain those.
- *
- * @return [Ebics3Request.OrderDetails.BTOrderParams]
- */
-fun prepNotificationRequest3(
- startDate: Instant? = null,
- endDate: Instant? = null,
- isAppendix: Boolean
-): Ebics3Request.OrderDetails.BTDOrderParams {
- val service = Ebics3Request.OrderDetails.Service().apply {
- serviceName = "REP"
- scope = "CH"
- container = Ebics3Request.OrderDetails.Service.Container().apply {
- containerType = "ZIP"
- }
- messageName = Ebics3Request.OrderDetails.Service.MessageName().apply {
- value = "camt.054"
- version = "08"
- }
- if (!isAppendix)
- serviceOption = "XDCI"
- }
- return Ebics3Request.OrderDetails.BTDOrderParams().apply {
- this.service = service
- this.dateRange = if (startDate != null)
- getEbics3DateRange(startDate, endDate ?: Instant.now())
- else null
- }
-}
-
-/**
- * Prepares the request for a pain.002 acknowledgement from the bank, via
- * EBICS 3.
- *
- * @param startDate inclusive starting date for the returned acknowledgements.
- * @param endDate inclusive ending date for the returned acknowledgements. NOTE:
- * if startDate is NOT null and endDate IS null, endDate gets defaulted
- * to the current UTC time.
- *
- * @return [Ebics3Request.OrderDetails.BTOrderParams]
- */
-fun prepAckRequest3(
- startDate: Instant? = null,
- endDate: Instant? = null
-): Ebics3Request.OrderDetails.BTDOrderParams {
- val service = Ebics3Request.OrderDetails.Service().apply {
- serviceName = "PSR"
- scope = "CH"
- container = Ebics3Request.OrderDetails.Service.Container().apply {
- containerType = "ZIP"
- }
- messageName = Ebics3Request.OrderDetails.Service.MessageName().apply {
- value = "pain.002"
- version = "10"
- }
- }
- return Ebics3Request.OrderDetails.BTDOrderParams().apply {
- this.service = service
- this.dateRange = if (startDate != null)
- getEbics3DateRange(startDate, endDate ?: Instant.now())
- else null
- }
-}
-
-/**
- * Prepares the request for (a) camt.053/statement(s) via EBICS 3.
- *
- * @param startDate inclusive starting date for the returned banking events.
- * @param endDate inclusive ending date for the returned banking events. NOTE:
- * if startDate is NOT null and endDate IS null, endDate gets defaulted
- * to the current UTC time.
- *
- * @return [Ebics3Request.OrderDetails.BTOrderParams]
- */
-fun prepStatementRequest3(
- startDate: Instant? = null,
- endDate: Instant? = null
-): Ebics3Request.OrderDetails.BTDOrderParams {
- val service = Ebics3Request.OrderDetails.Service().apply {
- serviceName = "EOP"
- scope = "CH"
- container = Ebics3Request.OrderDetails.Service.Container().apply {
- containerType = "ZIP"
- }
- messageName = Ebics3Request.OrderDetails.Service.MessageName().apply {
- value = "camt.053"
- version = "08"
- }
- }
- return Ebics3Request.OrderDetails.BTDOrderParams().apply {
- this.service = service
- this.dateRange = if (startDate != null)
- getEbics3DateRange(startDate, endDate ?: Instant.now())
- else null
- }
-}
-
-/**
- * Prepares the request for camt.052/intraday records via EBICS 3.
- *
- * @param startDate inclusive starting date for the returned banking events.
- * @param endDate inclusive ending date for the returned banking events. NOTE:
- * if startDate is NOT null and endDate IS null, endDate gets defaulted
- * to the current UTC time.
- *
- * @return [Ebics3Request.OrderDetails.BTOrderParams]
- */
-fun prepReportRequest3(
- startDate: Instant? = null,
- endDate: Instant? = null
-): Ebics3Request.OrderDetails.BTDOrderParams {
- val service = Ebics3Request.OrderDetails.Service().apply {
- serviceName = "STM"
- scope = "CH"
- container = Ebics3Request.OrderDetails.Service.Container().apply {
- containerType = "ZIP"
- }
- messageName = Ebics3Request.OrderDetails.Service.MessageName().apply {
- value = "camt.052"
- version = "08"
- }
- }
- return Ebics3Request.OrderDetails.BTDOrderParams().apply {
- this.service = service
- this.dateRange = if (startDate != null)
- getEbics3DateRange(startDate, endDate ?: Instant.now())
- else null
- }
-}
-
-/**
- * Abstracts EBICS 3 request creation of a download init phase.
- *
- * @param whichDoc type of wanted document.
- * @param startDate earliest timestamp of the document(s) to download.
- * If null, it gets the unseen documents. If defined,
- * the latest timestamp defaults to the current time.
- * @return [Ebics2Request] to be converted to XML string and passed to
- * the EBICS downloader.
- */
-fun prepEbics3Document(
- whichDoc: SupportedDocument,
- startDate: Instant? = null
-): Ebics3Request.OrderDetails.BTDOrderParams =
- when(whichDoc) {
- SupportedDocument.PAIN_002 -> prepAckRequest3(startDate)
- SupportedDocument.CAMT_052 -> prepReportRequest3(startDate)
- SupportedDocument.CAMT_053 -> prepStatementRequest3(startDate)
- SupportedDocument.CAMT_054 -> prepNotificationRequest3(startDate, isAppendix = true)
- SupportedDocument.PAIN_002_LOGS -> throw Exception("HAC (--only-logs) not available in EBICS 3")
- } \ No newline at end of file
+} \ No newline at end of file