From 124b3ca9f633aa9adefa99ab6e564835bae19c4b Mon Sep 17 00:00:00 2001 From: dankito Date: Sat, 16 May 2020 19:14:36 +0200 Subject: [PATCH] Implemented if bank already closed dialog no close dialog message gets send anymore to bank --- fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt | 9 +++++++++ .../main/kotlin/net/dankito/fints/model/DialogContext.kt | 1 + .../main/kotlin/net/dankito/fints/response/Response.kt | 3 +++ 3 files changed, 13 insertions(+) diff --git a/fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt index c5674f88..b49b3335 100644 --- a/fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4k/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -99,6 +99,10 @@ open class FinTsClient @JvmOverloads constructor( protected open fun closeAnonymousDialog(dialogContext: DialogContext, response: Response) { + if (dialogContext.didBankCloseDialog) { // bank already closed dialog -> there's no need to send dialog end message + return + } + val dialogEndRequestBody = messageBuilder.createAnonymousDialogEndMessage(dialogContext) getAndHandleResponseForMessage(dialogEndRequestBody, dialogContext) // TODO: really handle close dialog response? @@ -482,6 +486,10 @@ open class FinTsClient @JvmOverloads constructor( protected open fun closeDialog(dialogContext: DialogContext) { + if (dialogContext.didBankCloseDialog) { // bank already closed dialog -> there's no need to send dialog end message + return + } + val dialogEndRequestBody = messageBuilder.createDialogEndMessage(dialogContext) getAndHandleResponseForMessage(dialogEndRequestBody, dialogContext) // TODO: really handle close dialog response? @@ -561,6 +569,7 @@ open class FinTsClient @JvmOverloads constructor( dialogContext.response = response response.messageHeader?.let { header -> dialogContext.dialogId = header.dialogId } + dialogContext.didBankCloseDialog = response.didBankCloseDialog return response } diff --git a/fints4k/src/main/kotlin/net/dankito/fints/model/DialogContext.kt b/fints4k/src/main/kotlin/net/dankito/fints/model/DialogContext.kt index 1c73989b..44977db7 100644 --- a/fints4k/src/main/kotlin/net/dankito/fints/model/DialogContext.kt +++ b/fints4k/src/main/kotlin/net/dankito/fints/model/DialogContext.kt @@ -11,6 +11,7 @@ open class DialogContext( var currentMessage: MessageBuilderResult? = null, var dialogId: String = InitialDialogId, var response: Response? = null, + var didBankCloseDialog: Boolean = false, var previousMessageInDialog: MessageBuilderResult? = null ) : MessageBaseData(bank, customer, product) { diff --git a/fints4k/src/main/kotlin/net/dankito/fints/response/Response.kt b/fints4k/src/main/kotlin/net/dankito/fints/response/Response.kt index b48c8211..1d317bf3 100644 --- a/fints4k/src/main/kotlin/net/dankito/fints/response/Response.kt +++ b/fints4k/src/main/kotlin/net/dankito/fints/response/Response.kt @@ -46,6 +46,9 @@ open class Response( open val messageFeedback: MessageFeedback? get() = getFirstSegmentById(InstituteSegmentId.MessageFeedback) + open val didBankCloseDialog: Boolean + get() = messageFeedback?.feedbacks?.firstOrNull { it.responseCode == 9800 } != null + open val segmentFeedbacks: List get() = getSegmentsById(InstituteSegmentId.SegmentFeedback)