From 46fef1695d145dc2cb5ae553cc380422974bf386 Mon Sep 17 00:00:00 2001 From: dankl Date: Sun, 13 Oct 2019 18:11:38 +0200 Subject: [PATCH] Extracted getBalanceAfterDialogInit(), moved initDialog() to closeDialog() --- .../kotlin/net/dankito/fints/FinTsClient.kt | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index ac043885..7945631a 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -53,22 +53,6 @@ open class FinTsClient( } - open fun initDialog(bank: BankData, customer: CustomerData, dialogData: DialogData): Response { - - val requestBody = messageBuilder.createInitDialogMessage(bank, customer, product, dialogData) - - val response = getAndHandleResponseForMessage(requestBody, bank) - - if (response.successful) { - updateBankData(bank, response) - updateCustomerData(customer, response) - - response.messageHeader?.let { header -> dialogData.dialogId = header.dialogId } - } - - return response - } - open fun synchronizeCustomerSystemId(bank: BankData, customer: CustomerData): Response { val dialogData = DialogData() @@ -104,11 +88,7 @@ open class FinTsClient( var balance: BigDecimal? = null if (parameter.alsoRetrieveBalance) { - dialogData.increaseMessageNumber() - - val balanceRequest = messageBuilder.createGetBalanceMessage(bank, customer, product, dialogData) - - val balanceResponse = getAndHandleResponseForMessage(balanceRequest, bank) + val balanceResponse = getBalanceAfterDialogInit(bank, customer, dialogData) if (balanceResponse.successful == false) { return GetTransactionsResponse(balanceResponse) @@ -136,6 +116,16 @@ open class FinTsClient( return GetTransactionsResponse(response) } + protected open fun getBalanceAfterDialogInit(bank: BankData, customer: CustomerData, + dialogData: DialogData): Response { + + dialogData.increaseMessageNumber() + + val balanceRequest = messageBuilder.createGetBalanceMessage(bank, customer, product, dialogData) + + return getAndHandleResponseForMessage(balanceRequest, bank) + } + open fun doBankTransfer(bankTransferData: BankTransferData, bank: BankData, customer: CustomerData): Response { @@ -161,6 +151,22 @@ open class FinTsClient( } + protected open fun initDialog(bank: BankData, customer: CustomerData, dialogData: DialogData): Response { + + val requestBody = messageBuilder.createInitDialogMessage(bank, customer, product, dialogData) + + val response = getAndHandleResponseForMessage(requestBody, bank) + + if (response.successful) { + updateBankData(bank, response) + updateCustomerData(customer, response) + + response.messageHeader?.let { header -> dialogData.dialogId = header.dialogId } + } + + return response + } + protected open fun closeDialog(bank: BankData, customer: CustomerData, dialogData: DialogData) { dialogData.increaseMessageNumber()