commit 8a74c8241cb89984e044b4d6136a4dc0763773f3
parent 88338078853317b1df1a0ac8cafd52c6266352a8
Author: MS <ms@taler.net>
Date: Wed, 15 Feb 2023 13:27:28 +0100
EBICS checks.
Moving the check for a transaction ID after having
checked that the EBICS technical return code is EBICS_OK.
Diffstat:
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsClient.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsClient.kt
@@ -105,12 +105,7 @@ suspend fun doEbicsDownloadTransaction(
val initResponseStr = client.postToBank(subscriberDetails.ebicsUrl, initDownloadRequestStr)
val initResponse = parseAndValidateEbicsResponse(subscriberDetails, initResponseStr)
- val transactionID =
- initResponse.transactionID ?: throw NexusError(
- HttpStatusCode.BadGateway,
- "Initial response must contain transaction ID, $orderType did not!"
- )
-
+ val transactionID: String? = initResponse.transactionID
// Checking for EBICS communication problems.
when (initResponse.technicalReturnCode) {
EbicsReturnCode.EBICS_OK -> {
@@ -125,13 +120,21 @@ suspend fun doEbicsDownloadTransaction(
throw EbicsProtocolError(
HttpStatusCode.UnprocessableEntity,
"Unexpected return code ${initResponse.technicalReturnCode}," +
- " for order type $orderType and transaction ID $transactionID," +
+ " for order type $orderType and transaction ID: $transactionID," +
" at init phase.",
initResponse.technicalReturnCode
)
}
}
-
+ /**
+ * At this point, the EBICS init phase went through,
+ * therefore the message should carry a transaction ID!
+ */
+ if (transactionID == null) throw NexusError(
+ HttpStatusCode.BadGateway,
+ "EBICS-correct init response should contain" +
+ " a transaction ID, $orderType did not!"
+ )
// Checking the 'bank technical' code.
when (initResponse.bankReturnCode) {
EbicsReturnCode.EBICS_OK -> {
@@ -145,7 +148,6 @@ suspend fun doEbicsDownloadTransaction(
return EbicsDownloadBankErrorResult(initResponse.bankReturnCode)
}
}
-
logger.debug("Bank acknowledges EBICS download initialization." +
" Transaction ID: $transactionID.")
val encryptionInfo = initResponse.dataEncryptionInfo
@@ -248,7 +250,9 @@ suspend fun doEbicsUploadTransaction(
orderParams: EbicsOrderParams
) {
if (subscriberDetails.bankEncPub == null) {
- throw NexusError(HttpStatusCode.BadRequest, "bank encryption key unknown, request HPB first")
+ throw NexusError(HttpStatusCode.BadRequest,
+ "bank encryption key unknown, request HPB first"
+ )
}
val preparedUploadData = prepareUploadPayload(subscriberDetails, payload)
val req = createEbicsRequestForUploadInitialization(subscriberDetails, orderType, orderParams, preparedUploadData)