summaryrefslogtreecommitdiff
path: root/sandbox/src/main/kotlin/tech/libeufin
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-08-02 12:13:09 +0200
committerMS <ms@taler.net>2023-08-02 12:13:09 +0200
commit219bc3cc2dae211b18b9d6de7953e69b34fbae9e (patch)
treed378f03352cefa1ad08d312fc76fe964f744d9a4 /sandbox/src/main/kotlin/tech/libeufin
parent8ed318feb46099f3531bfef02b2dcf13de557b6f (diff)
downloadlibeufin-219bc3cc2dae211b18b9d6de7953e69b34fbae9e.tar.gz
libeufin-219bc3cc2dae211b18b9d6de7953e69b34fbae9e.tar.bz2
libeufin-219bc3cc2dae211b18b9d6de7953e69b34fbae9e.zip
Server side EBICS date range.
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin')
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt37
-rw-r--r--sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt2
2 files changed, 29 insertions, 10 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
index 658d6373..48f5d8a4 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -27,6 +27,7 @@ import io.ktor.server.request.*
import io.ktor.server.response.respond
import io.ktor.server.response.respondText
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
@@ -476,20 +477,27 @@ private fun constructCamtResponse(
subscriber: EbicsSubscriberEntity,
dateRange: Pair<Long, Long>?
): List<String> {
-
if (type != 53 && type != 52) throw EbicsUnsupportedOrderType()
val bankAccount = getBankAccountFromSubscriber(subscriber)
+ val history = mutableListOf<XLibeufinBankTransaction>()
if (type == 52) {
- if (dateRange != null)
- throw EbicsOrderParamsIgnored("C52 does not support date ranges.")
- val history = mutableListOf<XLibeufinBankTransaction>()
- transaction {
- BankAccountFreshTransactionEntity.all().forEach {
- if (it.transactionRef.account.label == bankAccount.label) {
- history.add(getHistoryElementFromTransactionRow(it))
+ if (dateRange != null) {
+ transaction {
+ BankAccountTransactionEntity.find {
+ BankAccountTransactionsTable.account eq bankAccount.id and
+ BankAccountTransactionsTable.date.between(
+ dateRange.first, dateRange.second
+ )
+ }.forEach { history.add(getHistoryElementFromTransactionRow(it)) }
+ }
+ } else
+ transaction {
+ BankAccountFreshTransactionEntity.all().forEach {
+ if (it.transactionRef.account.label == bankAccount.label) {
+ history.add(getHistoryElementFromTransactionRow(it))
+ }
}
}
- }
if (history.size == 0) throw EbicsNoDownloadDataAvailable()
val camtData = buildCamtString(
type,
@@ -678,6 +686,9 @@ private fun handleCct(
)
return@transaction
}
+ /**
+ * FIXME: here call wire_transfer(), because it'll set the balances too.
+ */
val bankAccount = getBankAccountFromIban(parseResult.debtorIban)
if (parseResult.currency != bankAccount.demoBank.config.currency) throw EbicsRequestError(
"[EBICS_PROCESSING_ERROR] Currency (${parseResult.currency}) not supported.",
@@ -740,10 +751,16 @@ private fun handleCct(
* to the querying subscriber.
*/
private fun handleEbicsC52(requestContext: RequestContext): ByteArray {
+ val maybeDateRange = requestContext.requestObject.header.static.orderDetails?.orderParams
+ 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())
+ } else null
val report = constructCamtResponse(
52,
requestContext.subscriber,
- dateRange = null
+ dateRange = dateRange
)
sandboxAssert(
report.size == 1,
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
index faedcdd9..5adb1af0 100644
--- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
+++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -241,8 +241,10 @@ data class HistoryParams(
val untilMs: Long,
val bankAccount: BankAccountEntity
)
+
fun extractTxHistory(params: HistoryParams): List<XLibeufinBankTransaction> {
val ret = mutableListOf<XLibeufinBankTransaction>()
+
/**
* Helper that gets transactions earlier than the 'firstElementId'
* transaction AND that match the URI parameters.