summaryrefslogtreecommitdiff
path: root/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
diff options
context:
space:
mode:
Diffstat (limited to 'nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt')
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt61
1 files changed, 38 insertions, 23 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
index 96710648..f1e85513 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
@@ -95,7 +95,10 @@ suspend fun ingestOutgoingPayment(
db: Database,
payment: OutgoingPayment
) {
- val result = db.payment.registerOutgoing(payment)
+ val metadata: Pair<ShortHashCode, ExchangeUrl>? = payment.wireTransferSubject?.let {
+ runCatching { parseOutgoingTxMetadata(it) }.getOrNull()
+ }
+ val result = db.payment.registerOutgoing(payment, metadata?.first, metadata?.second)
if (result.new) {
if (result.initiated)
logger.info("$payment")
@@ -106,8 +109,6 @@ suspend fun ingestOutgoingPayment(
}
}
-private val PATTERN = Regex("[a-z0-9A-Z]{52}")
-
/**
* Ingests an incoming payment. Stores the payment into valid talerable ones
* or bounces it, according to the subject.
@@ -117,18 +118,31 @@ private val PATTERN = Regex("[a-z0-9A-Z]{52}")
*/
suspend fun ingestIncomingPayment(
db: Database,
- payment: IncomingPayment
+ payment: IncomingPayment,
+ accountType: AccountType
) {
suspend fun bounce(msg: String) {
- val result = db.payment.registerMalformedIncoming(
- payment,
- payment.amount,
- Instant.now()
- )
- if (result.new) {
- logger.info("$payment bounced in '${result.bounceId}': $msg")
- } else {
- logger.debug("$payment already seen and bounced in '${result.bounceId}': $msg")
+ when (accountType) {
+ AccountType.exchange -> {
+ val result = db.payment.registerMalformedIncoming(
+ payment,
+ payment.amount,
+ Instant.now()
+ )
+ if (result.new) {
+ logger.info("$payment bounced in '${result.bounceId}': $msg")
+ } else {
+ logger.debug("$payment already seen and bounced in '${result.bounceId}': $msg")
+ }
+ }
+ AccountType.normal -> {
+ val res = db.payment.registerIncoming(payment)
+ if (res.new) {
+ logger.info("$payment")
+ } else {
+ logger.debug("$payment already seen")
+ }
+ }
}
}
runCatching { parseIncomingTxMetadata(payment.wireTransferSubject) }.fold(
@@ -156,14 +170,14 @@ private suspend fun ingestDocument(
whichDocument: SupportedDocument
) {
when (whichDocument) {
- SupportedDocument.CAMT_053, SupportedDocument.CAMT_054 -> {
+ SupportedDocument.CAMT_052, SupportedDocument.CAMT_053, SupportedDocument.CAMT_054 -> {
try {
parseTx(xml, cfg.currency, cfg.dialect).forEach {
if (cfg.fetch.ignoreBefore != null && it.executionTime < cfg.fetch.ignoreBefore) {
logger.debug("IGNORE $it")
} else {
when (it) {
- is IncomingPayment -> ingestIncomingPayment(db, it)
+ is IncomingPayment -> ingestIncomingPayment(db, it, cfg.accountType)
is OutgoingPayment -> ingestOutgoingPayment(db, it)
is TxNotification.Reversal -> {
logger.error("BOUNCE '${it.msgId}': ${it.reason}")
@@ -212,10 +226,6 @@ private suspend fun ingestDocument(
db.initiated.bankMessage(status.msgId, msg)
}
}
- SupportedDocument.CAMT_052 -> {
- // TODO parsing
- // TODO ingesting
- }
}
}
@@ -307,15 +317,18 @@ enum class EbicsDocument {
acknowledgement,
/// Payment status - CustomerPaymentStatusReport pain.002
status,
- /// Debit & credit notifications - BankToCustomerDebitCreditNotification camt.054
- notification,
+ /// Account intraday reports - BankToCustomerAccountReport camt.052
+ report,
/// Account statements - BankToCustomerStatement camt.053
statement,
+ /// Debit & credit notifications - BankToCustomerDebitCreditNotification camt.054
+ notification,
;
fun shortDescription(): String = when (this) {
acknowledgement -> "EBICS acknowledgement"
status -> "Payment status"
+ report -> "Account intraday reports"
statement -> "Account statements"
notification -> "Debit & credit notifications"
}
@@ -323,6 +336,7 @@ enum class EbicsDocument {
fun fullDescription(): String = when (this) {
acknowledgement -> "EBICS acknowledgement - CustomerAcknowledgement HAC pain.002"
status -> "Payment status - CustomerPaymentStatusReport pain.002"
+ report -> "Account intraday reports - BankToCustomerAccountReport camt.052"
statement -> "Account statements - BankToCustomerStatement camt.053"
notification -> "Debit & credit notifications - BankToCustomerDebitCreditNotification camt.054"
}
@@ -330,6 +344,7 @@ enum class EbicsDocument {
fun doc(): SupportedDocument = when (this) {
acknowledgement -> SupportedDocument.PAIN_002_LOGS
status -> SupportedDocument.PAIN_002
+ report -> SupportedDocument.CAMT_052
statement -> SupportedDocument.CAMT_053
notification -> SupportedDocument.CAMT_054
}
@@ -363,10 +378,10 @@ class EbicsFetch: CliktCommand("Fetches EBICS files") {
* mode when no flags are passed to the invocation.
*/
override fun run() = cliCmd(logger, common.log) {
- val cfg = extractEbicsConfig(common.config)
+ val cfg = loadNexusConfig(common.config)
val dbCfg = cfg.config.dbConfig()
- Database(dbCfg).use { db ->
+ Database(dbCfg, cfg.currency).use { db ->
val (clientKeys, bankKeys) = expectFullKeys(cfg)
val ctx = FetchContext(
cfg,