commit 47070ef9e1fa32703203447abb772d638b1191be
parent ce91844da940b21187b13b5db08b1a19b4e536a5
Author: MS <ms@taler.net>
Date: Wed, 25 Oct 2023 15:41:28 +0200
nexus: helper to submit EBICS 3 payments.
Diffstat:
1 file changed, 44 insertions(+), 0 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/Ebics3.kt
@@ -1,8 +1,10 @@
package tech.libeufin.nexus.ebics
+import io.ktor.client.*
import tech.libeufin.nexus.BankPublicKeysFile
import tech.libeufin.nexus.ClientPrivateKeysFile
import tech.libeufin.nexus.EbicsSetupConfig
+import tech.libeufin.nexus.logger
import tech.libeufin.util.PreparedUploadData
import tech.libeufin.util.XMLUtil
import tech.libeufin.util.ebics_h005.Ebics3Request
@@ -90,4 +92,46 @@ fun createEbics3RequestForUploadTransferPhase(
withEbics3 = true
)
return XMLUtil.convertDomToString(doc)
+}
+
+/**
+ * Collects all the steps to prepare the submission of a pain.001
+ * document to the bank, and finally send it.
+ *
+ * @param pain001xml pain.001 document in XML. The caller should
+ * ensure its validity.
+ * @param cfg configuration handle.
+ * @param clientKeys client private keys.
+ * @param bankkeys bank public keys.
+ * @param httpClient HTTP client to connect to the bank.
+ * @return true on success, false otherwise.
+ */
+suspend fun submitPayment(
+ pain001xml: String,
+ cfg: EbicsSetupConfig,
+ clientKeys: ClientPrivateKeysFile,
+ bankkeys: BankPublicKeysFile,
+ httpClient: HttpClient
+): Boolean {
+ val orderService: Ebics3Request.OrderDetails.Service = Ebics3Request.OrderDetails.Service().apply {
+ serviceName = "MCT"
+ scope = "CH"
+ messageName = Ebics3Request.OrderDetails.Service.MessageName().apply {
+ value = "pain.001"
+ version = "09"
+ }
+ }
+ val maybeUploaded = doEbicsUpload(
+ httpClient,
+ cfg,
+ clientKeys,
+ bankkeys,
+ orderService,
+ pain001xml.toByteArray(Charsets.UTF_8)
+ )
+ if (maybeUploaded == null) {
+ logger.error("Could not send the pain.001 document to the bank.")
+ return false
+ }
+ return true
}
\ No newline at end of file