summaryrefslogtreecommitdiff
path: root/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2021-08-07 16:10:25 +0200
committerFlorian Dold <florian@dold.me>2021-08-07 16:10:35 +0200
commit05ddacd80641db9ebd00ba6bb20aa8200c8b76f8 (patch)
treef6830f6cb04ea55f127744ee29d2ef524216190d /nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
parent695c23c2b1a9ee05409fff3d74621393edce042b (diff)
downloadlibeufin-05ddacd80641db9ebd00ba6bb20aa8200c8b76f8.tar.gz
libeufin-05ddacd80641db9ebd00ba6bb20aa8200c8b76f8.tar.bz2
libeufin-05ddacd80641db9ebd00ba6bb20aa8200c8b76f8.zip
check amount, catch exceptions when refunding
Diffstat (limited to 'nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt')
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt25
1 files changed, 17 insertions, 8 deletions
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
index 33f09651..33403da2 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Taler.kt
@@ -43,7 +43,9 @@ import tech.libeufin.util.*
import kotlin.math.abs
import kotlin.math.min
-/** Payment initiating data structures: one endpoint "$BASE_URL/transfer". */
+/**
+ * Request body for "$TWG_BASE_URL/transfer".
+ */
data class TalerTransferRequest(
val request_uid: String,
val amount: String,
@@ -94,7 +96,9 @@ data class GnunetTimestamp(
val t_ms: Long
)
-/** Sort query results in descending order for negative deltas, and ascending otherwise. */
+/**
+ * Sort query results in descending order for negative deltas, and ascending otherwise.
+ */
fun <T : Entity<Long>> SizedIterable<T>.orderTaler(delta: Int): List<T> {
return if (delta < 0) {
this.sortedByDescending { it.id }
@@ -165,7 +169,7 @@ fun customConverter(body: Any): String {
fun extractReservePubFromSubject(rawSubject: String): String? {
val re = "\\b[a-z0-9A-Z]{52}\\b".toRegex()
val result = re.find(rawSubject.replace("[\n]+".toRegex(), "")) ?: return null
- return result.value.toUpperCase()
+ return result.value.uppercase()
}
private fun getTalerFacadeState(fcid: String): TalerFacadeStateEntity {
@@ -185,7 +189,7 @@ private fun getTalerFacadeBankAccount(fcid: String): NexusBankAccountEntity {
val facadeState = getTalerFacadeState(fcid)
return NexusBankAccountEntity.findByName(facadeState.bankAccount) ?: throw NexusError(
HttpStatusCode.NotFound,
- "The facade: ${fcid} doesn't manage bank account: ${facadeState.bankAccount}"
+ "The facade: $fcid doesn't manage bank account: ${facadeState.bankAccount}"
)
}
@@ -356,7 +360,7 @@ fun maybePrepareRefunds(bankAccount: NexusBankAccountEntity, lastSeenId: Long) {
throw NexusError(HttpStatusCode.InternalServerError, "Unexpected void payment, cannot refund")
}
val debtorAccount = paymentData.batches[0].batchTransactions[0].details.debtorAccount
- if (debtorAccount == null || debtorAccount.iban == null) {
+ if (debtorAccount?.iban == null) {
logger.error("Could not find a IBAN to refund in transaction (AcctSvcrRef): ${paymentData.accountServicerRef}, aborting refund")
throw NexusError(HttpStatusCode.InternalServerError, "IBAN to refund not found")
}
@@ -441,7 +445,12 @@ fun ingestTalerTransactions(bankAccountId: String) {
}
lastId = it.id.value
}
- maybePrepareRefunds(bankAccount, facadeState.highestSeenMessageSerialId)
+ try {
+ // FIXME: This currently does not do proper error handing.
+ maybePrepareRefunds(bankAccount, facadeState.highestSeenMessageSerialId)
+ } catch (e: Exception) {
+ logger.warn("sending refund payment failed", e);
+ }
facadeState.highestSeenMessageSerialId = lastId
}
@@ -561,8 +570,8 @@ fun talerFacadeRoutes(route: Route, httpClient: HttpClient) {
route.get("/config") {
val facadeId = ensureNonNull(call.parameters["fcid"])
call.request.requirePermission(
- PermissionQuery("facade", facadeId, "facade.talerWireGateway.transfer"),
- PermissionQuery("facade", facadeId, "facade.talerWireGateway.history")
+ PermissionQuery("facade", facadeId, "facade.talerwiregateway.transfer"),
+ PermissionQuery("facade", facadeId, "facade.talerwiregateway.history")
)
call.respond(object {
val version = "0.0.0"