commit dee6d7b62215972e958a8a5e03242d11e22117b9
parent 081f9a4f105c6f2855a382df09dab5eea4bf4fb9
Author: MS <ms@taler.net>
Date: Thu, 14 May 2020 20:57:45 +0200
Moving DB statements inside transaction block.
Diffstat:
2 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/integration-tests/test-ebics-new.py b/integration-tests/test-ebics-new.py
@@ -268,7 +268,7 @@ resp = assertResponse(
assert(len(resp.json().get("transactions")) == 0)
#5.a, prepare a payment
-assertResponse(
+resp = assertResponse(
post(
"http://localhost:5001/bank-accounts/{}/prepared-payments".format(BANK_ACCOUNT_LABEL),
json=dict(
@@ -281,16 +281,22 @@ assertResponse(
headers=dict(Authorization=USER_AUTHORIZATION_HEADER)
)
)
+PREPARED_PAYMENT_UUID=resp.json().get("uuid")
+assert(PREPARED_PAYMENT_UUID != None)
+
+#5.b, submit prepared statement
+assertResponse(
+ post(
+ "http://localhost:5001/bank-accounts/prepared-payments/submit",
+ json=dict(uuid=PREPARED_PAYMENT_UUID),
+ headers=dict(Authorization=USER_AUTHORIZATION_HEADER)
+ )
+)
nexus.terminate()
sandbox.terminate()
exit(44)
-#5.b
-assertResponse(
- post("http://localhost:5001/ebics/execute-payments")
-)
-
#6
assertResponse(
post(
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -280,19 +280,22 @@ fun main() {
/**
* Submit one particular payment at the bank.
*/
- post("/bank-accounts/{accountid}/prepared-payments/submit") {
+ post("/bank-accounts/prepared-payments/submit") {
val userId = authenticateRequest(call.request.headers["Authorization"])
val body = call.receive<SubmitPayment>()
val preparedPayment = getPreparedPayment(body.uuid)
- if (preparedPayment.nexusUser.id.value != userId) throw NexusError(
- HttpStatusCode.Forbidden,
- "No rights over such payment"
- )
- if (preparedPayment.submitted) {
- throw NexusError(
- HttpStatusCode.PreconditionFailed,
- "Payment ${body.uuid} was submitted already"
+ transaction {
+ if (preparedPayment.nexusUser.id.value != userId) throw NexusError(
+ HttpStatusCode.Forbidden,
+ "No rights over such payment"
)
+ if (preparedPayment.submitted) {
+ throw NexusError(
+ HttpStatusCode.PreconditionFailed,
+ "Payment ${body.uuid} was submitted already"
+ )
+ }
+
}
val pain001document = createPain001document(preparedPayment)
if (body.transport != null) {
@@ -314,7 +317,9 @@ fun main() {
client, userId, null, pain001document
)
}
- preparedPayment.submitted = true
+ transaction {
+ preparedPayment.submitted = true
+ }
call.respondText("Payment ${body.uuid} submitted")
return@post
}