commit b230122c9f62c889f297c58451c0fa1d2dad1ebc
parent 92829a9d53a2605882b2747ea217fd01e5030256
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Tue, 3 Mar 2020 19:05:39 +0100
Avoid autoIncrement().
Diffstat:
5 files changed, 44 insertions(+), 17 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -59,12 +59,12 @@ const val ID_MAX_LENGTH = 50
//}
object Pain001Table : IntIdTableWithAmount() {
- val msgId = integer("msgId").uniqueIndex().autoIncrement()
- val paymentId = integer("paymentId").uniqueIndex().autoIncrement() // id for this system
- val fileDate = long("fileDate").default(DateTime.now().millis)
+ val msgId = long("msgId").uniqueIndex().autoIncrement()
+ val paymentId = long("paymentId")
+ val fileDate = long("fileDate")
val sum = amount("sum")
val debtorAccount = text("debtorAccount")
- val endToEndId = integer("EndToEndId").uniqueIndex().autoIncrement() // id for this and the creditor system
+ val endToEndId = long("EndToEndId")
val subject = text("subject")
val creditorIban = text("creditorIban")
val creditorBic = text("creditorBic")
@@ -137,6 +137,7 @@ fun dbCreateTables() {
transaction {
addLogger(StdOutSqlLogger)
SchemaUtils.create(
+ Pain001Table,
EbicsSubscribersTable,
EbicsAccountsInfoTable
)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
@@ -85,6 +85,14 @@ data class EbicsSubscriberInfoResponseJson(
val systemID: String? = null
)
+data class Pain001Data(
+ val creditorIban: String,
+ val creditorBic: String,
+ val creditorName: String,
+ val sum: Amount,
+ val subject: String
+)
+
/**
* Admin call that tells all the subscribers managed by Nexus.
*/
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -159,14 +159,6 @@ fun getSubscriberDetailsFromId(id: String): EbicsClientSubscriberDetails {
}
}
-data class Pain001Data(
- val creditorIban: String,
- val creditorBic: String,
- val creditorName: String,
- val sum: Amount,
- val subject: String
-)
-
/**
* Create a PAIN.001 XML document according to the input data.
* Needs to be called within a transaction block.
@@ -291,6 +283,7 @@ fun createPain001document(pain001Entity: Pain001Entity): String {
* Insert one row in the database, and leaves it marked as non-submitted.
*/
fun createPain001entry(entry: Pain001Data, debtorAccountId: String) {
+ val randomId = Random().nextLong()
transaction {
Pain001Entity.new {
subject = entry.subject
@@ -299,6 +292,10 @@ fun createPain001entry(entry: Pain001Data, debtorAccountId: String) {
creditorName = entry.creditorName
creditorBic = entry.creditorBic
creditorIban = entry.creditorIban
+ date = DateTime.now().millis
+ paymentId = randomId
+ msgId = randomId
+ endToEndId = randomId
}
}
}
diff --git a/nexus/src/test/kotlin/PainGeneration.kt b/nexus/src/test/kotlin/PainGeneration.kt
@@ -43,6 +43,20 @@ class PainTest {
}
@Test
+ fun testPain001helper() {
+ val data = Pain001Data(
+ creditorIban = "xy",
+ creditorBic = "xy",
+ creditorName = "xy",
+ sum = Amount("1.01"),
+ subject = "xy"
+ )
+ transaction {
+ createPain001entry(data, "debtor-bankaccount-id")
+ }
+ }
+
+ @Test
fun testPain001document() {
transaction {
val pain001Entity = Pain001Entity.new {
@@ -52,6 +66,11 @@ class PainTest {
creditorIban = "CREDIT IBAN"
creditorBic = "CREDIT BIC"
creditorName = "CREDIT NAME"
+ paymentId = 1
+ msgId = 1
+ endToEndId = 1
+ date = 1
+
}
val s = createPain001document(pain001Entity)
println(s)
diff --git a/sandbox/src/main/python/libeufin-cli b/sandbox/src/main/python/libeufin-cli
@@ -613,15 +613,17 @@ def prepare(ctx, account_id, nexus_base_url):
)
def prepare_payment(
ctx, account_id, bank_account_id, creditor_iban,
- creditor_bic, creditor_name, subject, amount, nexus_base_url):
+ creditor_bic, creditor_name, subject, sum, nexus_base_url):
nexus_url = urljoin(
nexus_base_url, "/ebics/subscribers/{}/accounts/{}/prepare-payment".format(
account_id, bank_account_id))
body = dict(
- ebicsURL=ebics_url,
- userID=user_id,
- partnerID=partner_id,
- hostID=host_id
+ debtorAccount = bank_account_id,
+ creditorIban = creditor_iban,
+ creditorBic = creditor_bic,
+ creditorName = creditor_name,
+ subject = subject,
+ sum = sum
)
try:
resp = post(nexus_url, json=body)