commit d8f6cca5b0c45cbae760308d0dfcd958d59b82d1
parent ab1219f2da03b123fc509a5d3a5c8f38bd963202
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Tue, 3 Mar 2020 21:51:14 +0100
First steps to execute payments.
Diffstat:
2 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -38,6 +38,7 @@ import io.ktor.routing.post
import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
+import javafx.util.Pair
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
import org.apache.commons.compress.archivers.zip.ZipFile
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel
@@ -123,6 +124,12 @@ fun getBankAccountDetailsFromAcctid(id: String): EbicsAccountInfoElement {
)
}
}
+fun getSubscriberDetailsFromBankAccount(bankAccountId: String): EbicsClientSubscriberDetails {
+ return transaction {
+ val subscriber = EbicsAccountInfoEntity.findById(bankAccountId) ?: throw SubscriberNotFoundError(HttpStatusCode.NotFound)
+ getSubscriberDetailsFromId(subscriber.id.value)
+ }
+}
fun getSubscriberDetailsFromId(id: String): EbicsClientSubscriberDetails {
return transaction {
@@ -537,16 +544,31 @@ fun main() {
/**
* This function triggers the Nexus to perform all those un-submitted payments.
* Ideally, this logic will be moved into some more automatic mechanism.
+ * NOTE: payments are not yet marked as "done" after this function returns. This
+ * should be done AFTER the PAIN.002 data corresponding to a payment witnesses it.
*/
post("/ebics/admin/execute-payments") {
- transaction {
- Pain001Entity.find {
+ val (painDoc, debtorAccount) = transaction {
+ val entity = Pain001Entity.find {
Pain001Table.submitted eq false
- }.forEach {
- // FIXME TODO
- }
+ }.firstOrNull() ?: throw Exception("No ready payments found")
+ kotlin.Pair(createPain001document(entity), entity.debtorAccount)
}
-
+ logger.info("Processing payment for bank account: ${debtorAccount}")
+ val subscriberDetails = getSubscriberDetailsFromBankAccount(debtorAccount)
+ val response = doEbicsUploadTransaction(
+ client,
+ subscriberDetails,
+ "CCC",
+ painDoc.toByteArray(Charsets.UTF_8),
+ EbicsStandardOrderParams()
+ )
+ call.respondText(
+ response.toString(),
+ ContentType.Text.Plain,
+ HttpStatusCode.OK
+ )
+ return@post
}
post("/ebics/subscribers/{id}/fetch-payment-status") {
diff --git a/sandbox/src/main/python/libeufin-cli b/sandbox/src/main/python/libeufin-cli
@@ -570,6 +570,22 @@ def prepare(ctx, account_id, nexus_base_url):
ctx.invoke(hia, account_id=account_id, nexus_base_url=nexus_base_url)
ctx.invoke(sync, account_id=account_id, nexus_base_url=nexus_base_url)
+
+@ebics.command(help="Picks the first unsubmitted payment and send it to the bank")
+@click.pass_context
+@click.argument(
+ "nexus-base-url"
+)
+def execute_payments(ctx, nexus_base_url):
+ try:
+ url = urljoin(nexus_base_url, "/ebics/admin/execute-payments")
+ resp = post(url)
+ except Exception as e:
+ print("Could not reach the Nexus", e)
+ return
+
+ print(resp.content.decode("utf-8"))
+
@ebics.command(help="Show status of payments")
@click.pass_context
@click.option(