commit 9ded2f3e02b3bd5a746fb56ae289705aa79efdfb
parent 9fe540fe8601e56dac3a7c9954f01a18e9432199
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Wed, 15 Apr 2020 16:38:09 +0200
/taler/transfer reads NEXUS_PRODUCTION env.
If NEXUS_PRODUCTION is defined, the requests to /taler/transfer
goes through the ordinary EBICS layer; in contrast, when such env
variable is not defined, then Nexus mocks all the requests as
successful payments in its local database. In this latter case,
no bank or sandbox are required for the nexus to participate in
tests.
Diffstat:
1 file changed, 17 insertions(+), 71 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/taler.kt
@@ -164,67 +164,12 @@ class Taler(app: Route) {
app.post("/taler/transfer") {
val exchangeId = authenticateRequest(call.request.headers["Authorization"])
val transferRequest = call.receive<TalerTransferRequest>()
- val opaque_row_id = transaction {
- val creditorData = parsePayto(transferRequest.credit_account)
- val exchangeBankAccount = getBankAccountsInfoFromId(exchangeId)
- val pain001 = createPain001entity(
- Pain001Data(
- creditorIban = creditorData.iban,
- creditorBic = creditorData.bic,
- creditorName = creditorData.name,
- subject = transferRequest.wtid,
- sum = parseAmount(transferRequest.amount).amount
- ),
- exchangeBankAccount.first().id.value
- )
- TalerRequestedPaymentEntity.find {
- TalerRequestedPayments.requestUId eq transferRequest.request_uid
- }.forEach {
- if (
- (it.amount != transferRequest.amount) or
- (it.creditAccount != transferRequest.exchange_base_url) or
- (it.wtid != transferRequest.wtid)
- ) {
- throw NexusError(
- HttpStatusCode.Conflict,
- "This uid (${transferRequest.request_uid}) belongs to a different payment already"
- )
- }
- }
- val row = TalerRequestedPaymentEntity.new {
- preparedPayment = pain001
- exchangeBaseUrl = transferRequest.exchange_base_url
- requestUId = transferRequest.request_uid
- amount = transferRequest.amount
- wtid = transferRequest.wtid
- creditAccount = transferRequest.credit_account
- }
- row.id.value
- }
- call.respond(
- HttpStatusCode.OK,
- TalerTransferResponse(
- /**
- * Normally should point to the next round where the background
- * routine will send new PAIN.001 data to the bank; work in progress..
- */
- timestamp = DateTime.now().millis / 1000,
- row_id = opaque_row_id
- )
- )
- return@post
- }
-
- app.post("/taler/test/transfer") {
- val exchangeId = authenticateRequest(call.request.headers["Authorization"])
- val transferRequest = call.receive<TalerTransferRequest>()
val amountObj = parseAmount(transferRequest.amount)
val creditorObj = parsePayto(transferRequest.credit_account)
val opaque_row_id = transaction {
val creditorData = parsePayto(transferRequest.credit_account)
val exchangeBankAccount = getBankAccountsInfoFromId(exchangeId).first()
-
/**
* Checking the UID has the desired characteristics.
*/
@@ -252,21 +197,23 @@ class Taler(app: Route) {
),
exchangeBankAccount.id.value
)
- val rawEbics = EbicsRawBankTransactionEntity.new {
- sourceFileName = "test"
- unstructuredRemittanceInformation = transferRequest.wtid
- transactionType = "DBIT"
- currency = amountObj.currency
- amount = amountObj.amount.toPlainString()
- debitorName = "Exchange Company"
- debitorIban = exchangeBankAccount.iban
- creditorName = creditorObj.name
- creditorIban = creditorObj.iban
- counterpartBic = creditorObj.bic
- bookingDate = DateTime.now().toString("Y-MM-dd")
- nexusSubscriber = exchangeBankAccount.subscriber
- status = "BOOK"
- }
+ val rawEbics = if (System.getenv("NEXUS_PRODUCTION") == null) {
+ EbicsRawBankTransactionEntity.new {
+ sourceFileName = "test"
+ unstructuredRemittanceInformation = transferRequest.wtid
+ transactionType = "DBIT"
+ currency = amountObj.currency
+ amount = amountObj.amount.toPlainString()
+ debitorName = "Exchange Company"
+ debitorIban = exchangeBankAccount.iban
+ creditorName = creditorObj.name
+ creditorIban = creditorObj.iban
+ counterpartBic = creditorObj.bic
+ bookingDate = DateTime.now().toString("Y-MM-dd")
+ nexusSubscriber = exchangeBankAccount.subscriber
+ status = "BOOK"
+ }
+ } else null
val row = TalerRequestedPaymentEntity.new {
preparedPayment = pain001 // not really used/needed, just here to silence warnings
@@ -397,7 +344,6 @@ class Taler(app: Route) {
}
}
}
-
/**
* Search for fresh OUTGOING transactions acknowledged by the bank. As well
* searching only for BOOKed transactions, even though status changes should