summaryrefslogtreecommitdiff
path: root/sandbox/src/main/kotlin/tech/libeufin
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-08-03 18:22:48 +0200
committerMS <ms@taler.net>2023-08-03 18:40:58 +0200
commit550bb76748e4008bd57fb0e323a553f7f5f3fe49 (patch)
tree45008cd8b9201ceea8b4c39453c53818de3ab6dc /sandbox/src/main/kotlin/tech/libeufin
parent7440a4b8ef2f24a95f0280e5b27bd88d93349365 (diff)
downloadlibeufin-550bb76748e4008bd57fb0e323a553f7f5f3fe49.tar.gz
libeufin-550bb76748e4008bd57fb0e323a553f7f5f3fe49.tar.bz2
libeufin-550bb76748e4008bd57fb0e323a553f7f5f3fe49.zip
Using the wireTransfer() method for EBICS.
Also: avoiding to use the "fetch all" specification for downloading EBICS reports in tests, because they easily miss the very latest transactions from the same day. Instead, use large enough time frames when all the transactions have to be returned.
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin')
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt5
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt53
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt12
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt10
4 files changed, 24 insertions, 56 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
index ebd72d3c..4d8d36d9 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/CircuitApi.kt
@@ -13,7 +13,6 @@ import tech.libeufin.util.*
import java.io.File
import java.io.InputStreamReader
import java.math.BigDecimal
-import java.math.RoundingMode
import java.util.concurrent.TimeUnit
import kotlin.text.toByteArray
@@ -322,7 +321,7 @@ fun circuitApi(circuitRoute: Route) {
amount = op.amountDebit
)
op.status = CashoutOperationStatus.CONFIRMED
- op.confirmationTime = getUTCnow().toInstant().toEpochMilli()
+ op.confirmationTime = getSystemTimeNow().toInstant().toEpochMilli()
// TODO(signal this payment over LIBEUFIN_REGIO_INCOMING)
}
call.respond(HttpStatusCode.NoContent)
@@ -538,7 +537,7 @@ fun circuitApi(circuitRoute: Route) {
this.sellAtRatio = ratiosAndFees.sell_at_ratio.toString()
this.sellOutFee = ratiosAndFees.sell_out_fee.toString()
this.subject = cashoutSubject
- this.creationTime = getUTCnow().toInstant().toEpochMilli()
+ this.creationTime = getSystemTimeNow().toInstant().toEpochMilli()
this.tanChannel = SupportedTanChannels.valueOf(tanChannel)
this.account = user
this.tan = getRandomString(5)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index 48f5d8a4..1bd6aa5e 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -30,7 +30,6 @@ import io.ktor.util.AttributeKey
import io.ktor.util.date.*
import org.apache.xml.security.binding.xmldsig.RSAKeyValueType
import org.jetbrains.exposed.sql.*
-import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.statements.api.ExposedBlob
import org.jetbrains.exposed.sql.transactions.transaction
import org.w3c.dom.Document
@@ -297,7 +296,7 @@ fun buildCamtString(
* - Proprietary code of the bank transaction
* - Id of the servicer (Issuer and Code)
*/
- val camtCreationTime = getUTCnow() // FIXME: should this be the payment time?
+ val camtCreationTime = getSystemTimeNow() // FIXME: should this be the payment time?
val dashedDate = camtCreationTime.toDashedDate()
val zonedDateTime = camtCreationTime.toZonedString()
val creationTimeMillis = camtCreationTime.toInstant().toEpochMilli()
@@ -703,46 +702,15 @@ private fun handleCct(
}
if (maybeDebit(bankAccount.label, maybeAmount, bankAccount.demoBank.name))
throw EbicsAmountCheckError("The requested amount (${parseResult.amount}) would exceed the debit threshold")
-
- // Get the two parties.
- BankAccountTransactionEntity.new {
- account = bankAccount
- demobank = bankAccount.demoBank
- creditorIban = parseResult.creditorIban
- creditorName = parseResult.creditorName
- creditorBic = parseResult.creditorBic
- debtorIban = parseResult.debtorIban
- debtorName = parseResult.debtorName
- debtorBic = parseResult.debtorBic
- subject = parseResult.subject
- amount = parseResult.amount
- currency = parseResult.currency
- date = getUTCnow().toInstant().toEpochMilli()
- pmtInfId = parseResult.pmtInfId
+ logger.debug("Wire-transfer'ing endToEndId: ${parseResult.endToEndId}")
+ wireTransfer(
+ bankAccount.label,
+ getBankAccountFromIban(parseResult.creditorIban).label,
+ bankAccount.demoBank.name,
+ parseResult.subject,
+ "${parseResult.currency}:${parseResult.amount}",
endToEndId = parseResult.endToEndId
- accountServicerReference = "sandboxref-${getRandomString(16)}"
- direction = "DBIT"
- }
- val maybeLocalCreditor = BankAccountEntity.find(BankAccountsTable.iban eq parseResult.creditorIban).firstOrNull()
- if (maybeLocalCreditor != null) {
- BankAccountTransactionEntity.new {
- account = maybeLocalCreditor
- demobank = maybeLocalCreditor.demoBank
- creditorIban = parseResult.creditorIban
- creditorName = parseResult.creditorName
- creditorBic = parseResult.creditorBic
- debtorIban = parseResult.debtorIban
- debtorName = parseResult.debtorName
- debtorBic = parseResult.debtorBic
- subject = parseResult.subject
- amount = parseResult.amount
- currency = parseResult.currency
- date = getUTCnow().toInstant().toEpochMilli()
- pmtInfId = parseResult.pmtInfId
- accountServicerReference = "sandboxref-${getRandomString(16)}"
- direction = "CRDT"
- }
- }
+ )
}
}
@@ -755,8 +723,9 @@ private fun handleEbicsC52(requestContext: RequestContext): ByteArray {
val dateRange: Pair<Long, Long>? = if (maybeDateRange is EbicsRequest.StandardOrderParams) {
val start: Long? = maybeDateRange.dateRange?.start?.toGregorianCalendar()?.timeInMillis
val end: Long? = maybeDateRange.dateRange?.end?.toGregorianCalendar()?.timeInMillis
- Pair(start ?: 0L, end ?: getTimeMillis())
+ Pair(start ?: 0L, end ?: Long.MAX_VALUE)
} else null
+ logger.debug("Date range: $dateRange")
val report = constructCamtResponse(
52,
requestContext.subscriber,
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
index cd886e55..bcd11a49 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -272,7 +272,7 @@ class Camt053Tick : CliktCommand(
)
BankAccountStatementEntity.new {
statementId = camtData.messageId
- creationTime = getUTCnow().toInstant().epochSecond
+ creationTime = getSystemTimeNow().toInstant().epochSecond
xmlMessage = camtData.camtMessage
bankAccount = accountIter
}
@@ -843,7 +843,7 @@ val sandboxApp: Application.() -> Unit = {
debtorName = body.debtorName
subject = body.subject
this.amount = amount.amount
- date = getUTCnow().toInstant().toEpochMilli()
+ date = getSystemTimeNow().toInstant().toEpochMilli()
accountServicerReference = "sandbox-$randId"
this.account = account
direction = "CRDT"
@@ -966,7 +966,7 @@ val sandboxApp: Application.() -> Unit = {
debtorName = "Max Mustermann"
subject = "sample transaction $transactionReferenceCrdt"
this.amount = amount.toString()
- date = getUTCnow().toInstant().toEpochMilli()
+ date = getSystemTimeNow().toInstant().toEpochMilli()
accountServicerReference = transactionReferenceCrdt
this.account = account
direction = "CRDT"
@@ -987,7 +987,7 @@ val sandboxApp: Application.() -> Unit = {
creditorName = "Max Mustermann"
subject = "sample transaction $transactionReferenceDbit"
this.amount = amount.toString()
- date = getUTCnow().toInstant().toEpochMilli()
+ date = getSystemTimeNow().toInstant().toEpochMilli()
accountServicerReference = transactionReferenceDbit
this.account = account
direction = "DBIT"
@@ -1530,9 +1530,9 @@ val sandboxApp: Application.() -> Unit = {
val size: Int = expectInt(call.request.queryParameters["size"] ?: "5")
if (size < 1) throw badRequest("'size' param is less than 1")
// Time range filter values
- val fromMs = expectLong(call.request.queryParameters["from_ms"] ?: "0")
+ val fromMs: Long = expectLong(call.request.queryParameters["from_ms"] ?: "0")
if (fromMs < 0) throw badRequest("'from_ms' param is less than 0")
- val untilMs = expectLong(call.request.queryParameters["until_ms"] ?: Long.MAX_VALUE.toString())
+ val untilMs: Long = expectLong(call.request.queryParameters["until_ms"] ?: Long.MAX_VALUE.toString())
if (untilMs < 0) throw badRequest("'until_ms' param is less than 0")
val longPollMs: Long? = call.maybeLong("long_poll_ms")
// LISTEN, if Postgres.
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
index 5adb1af0..d82a0eb4 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -1,8 +1,6 @@
package tech.libeufin.sandbox
import io.ktor.http.*
-import org.jetbrains.exposed.sql.StdOutSqlLogger
-import org.jetbrains.exposed.sql.addLogger
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.transactions.transaction
import tech.libeufin.util.*
@@ -140,9 +138,10 @@ fun wireTransfer(
demobank: String = "default",
subject: String,
amount: String, // $currency:x.y
- pmtInfId: String? = null
+ pmtInfId: String? = null,
+ endToEndId: String? = null
): String {
- logger.debug("Maybe wire transfer: $debitAccount -> $creditAccount, $subject, $amount")
+ logger.debug("Maybe wire transfer (endToEndId: $endToEndId): $debitAccount -> $creditAccount, $subject, $amount")
return transaction {
val demobankDb = ensureDemobank(demobank)
val debitAccountDb = getBankAccountFromLabel(debitAccount, demobankDb)
@@ -167,7 +166,7 @@ fun wireTransfer(
logger.error("Account ${debitAccountDb.label} would surpass debit threshold. Rollback wire transfer")
throw SandboxError(HttpStatusCode.Conflict, "Insufficient funds")
}
- val timeStamp = getUTCnow().toInstant().toEpochMilli()
+ val timeStamp = getNowMillis()
val transactionRef = getRandomString(8)
BankAccountTransactionEntity.new {
creditorIban = creditAccountDb.iban
@@ -202,6 +201,7 @@ fun wireTransfer(
direction = "DBIT"
this.demobank = demobankDb
this.pmtInfId = pmtInfId
+ this.endToEndId = endToEndId
}
// Adjusting the balances (acceptable debit conditions checked before).