commit c93c130bc393eec9eeae3178d5fe55bad4629414
parent 889a6cba8ce4119c454857fae49828329b7fad4b
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Wed, 22 Apr 2020 18:38:06 +0200
De- duplicator skeleton.
Diffstat:
3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="CompilerConfiguration">
+ <bytecodeTargetLevel target="11" />
+ </component>
+</project>
+\ No newline at end of file
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -80,9 +80,8 @@ class TalerIncomingPaymentEntity(id: EntityID<Long>) : LongEntity(id) {
}
/**
- * This table _assumes_ that all the entries have a BOOK status. The
- * current code however does only enforces this trusting the C53 response,
- * but never actually checking the appropriate "Sts" field.
+ * This table contains history "elements" as returned by the bank from a
+ * CAMT message. Therefore, any row could come from a C52/3/4 message response.
*/
object EbicsRawBankTransactionsTable : LongIdTable() {
val nexusSubscriber = reference("subscriber", EbicsSubscribersTable)
@@ -97,7 +96,7 @@ object EbicsRawBankTransactionsTable : LongIdTable() {
val debitorName = text("debitorName")
val counterpartBic = text("counterpartBic")
val bookingDate = long("bookingDate")
- val status = text("status") // BOOK, ..
+ val status = text("status") // BOOK or other.
}
class EbicsRawBankTransactionEntity(id: EntityID<Long>) : LongEntity(id) {
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
@@ -203,6 +203,11 @@ class Taler(app: Route) {
return Gson().toJson(body)
}
+ /** Work in progress */
+ private fun duplicatePayment(entry: EbicsRawBankTransactionEntity): Boolean {
+ return false
+ }
+
/** Attach Taler endpoints to the main Web server */
init {
@@ -385,16 +390,21 @@ class Taler(app: Route) {
transaction {
val subscriberAccount = getBankAccountsInfoFromId(id).first()
/**
- * Search for fresh INCOMING transactions having a BOOK status. Cancellations and
- * other status changes will (1) be _appended_ to the payment history, and (2) be
- * handled _independently_ by another dedicated routine.
+ * Search for fresh incoming payments in the raw table, and making pointers
+ * from the Taler incoming payments table to the found fresh payments.
*/
val latestIncomingPaymentId: Long = TalerIncomingPaymentEntity.getLast()
EbicsRawBankTransactionEntity.find {
+ /** select payments having the exchange as the credited party */
EbicsRawBankTransactionsTable.creditorIban eq subscriberAccount.iban and
(EbicsRawBankTransactionsTable.status eq "BOOK") and
+ /** avoid processing old payments from the raw table */
(EbicsRawBankTransactionsTable.id.greater(latestIncomingPaymentId))
}.forEach {
+ if (duplicatePayment(it)) {
+ logger.warn("A duplicate payment situation is happening")
+ throw NexusError(HttpStatusCode.InternalServerError, "Duplicate payment situation")
+ }
if (CryptoUtil.checkValidEddsaPublicKey(it.unstructuredRemittanceInformation)) {
TalerIncomingPaymentEntity.new {
payment = it