diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index 8c9f4eac..8b7b664c 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -2,6 +2,7 @@ package net.dankito.fints import net.dankito.fints.messages.MessageBuilder import net.dankito.fints.messages.datenelemente.implementierte.Dialogsprache +import net.dankito.fints.messages.datenelemente.implementierte.KundensystemID import net.dankito.fints.messages.datenelemente.implementierte.KundensystemStatusWerte import net.dankito.fints.model.* import net.dankito.fints.response.InstituteSegmentId @@ -65,30 +66,12 @@ open class FinTsClient( } - // TODO: i don't think this method is publicly needed - open fun synchronizeCustomerSystemId(bank: BankData, customer: CustomerData): FinTsClientResponse { - - val dialogData = DialogData() - val requestBody = messageBuilder.createSynchronizeCustomerSystemIdMessage(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 } - - closeDialog(bank, customer, dialogData) - } - - return FinTsClientResponse(response) - } - - open fun getTransactions(parameter: GetTransactionsParameter, bank: BankData, customer: CustomerData): GetTransactionsResponse { +// synchronizeCustomerSystemIdIfNotDoneYet(bank, customer) // even though specification says this is required it can be omitted + + val dialogData = DialogData() val initDialogResponse = initDialog(bank, customer, dialogData) @@ -189,6 +172,47 @@ open class FinTsClient( } + protected open fun synchronizeCustomerSystemIdIfNotDoneYet(bank: BankData, + customer: CustomerData): FinTsClientResponse { + + if (customer.customerSystemId == KundensystemID.Anonymous) { // customer system id not synchronized yet + return synchronizeCustomerSystemId(bank, customer) + } + + return FinTsClientResponse(true, false) + } + + /** + * According to specification synchronizing customer system id is required: + * "Die Kundensystem-ID ist beim HBCI RAH- / RDH- sowie dem PIN/TAN-Verfahren erforderlich." + * + * But as tests show this can be omitted. + * + * But when you do it, this has to be done in an extra dialog as dialog has to be initialized + * with retrieved customer system id. + * + * If you change customer system id during a dialog your messages get rejected by bank institute. + */ + protected open fun synchronizeCustomerSystemId(bank: BankData, customer: CustomerData): FinTsClientResponse { + + val dialogData = DialogData() + val requestBody = messageBuilder.createSynchronizeCustomerSystemIdMessage(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 } + + closeDialog(bank, customer, dialogData) + } + + return FinTsClientResponse(response) + } + + protected open fun getAndHandleResponseForMessage(requestBody: String, bank: BankData): Response { val webResponse = getResponseForMessage(requestBody, bank) diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt index 8ad97a5c..b8bb90ea 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt @@ -6,6 +6,7 @@ import net.dankito.fints.messages.datenelemente.implementierte.KundensystemStatu import net.dankito.fints.messages.datenelemente.implementierte.KundensystemStatusWerte import net.dankito.fints.messages.datenelemente.implementierte.signatur.Sicherheitsfunktion import net.dankito.fints.model.* +import net.dankito.fints.response.client.FinTsClientResponse import net.dankito.fints.util.Java8Base64Service import org.assertj.core.api.Assertions.assertThat import org.junit.Ignore @@ -16,7 +17,13 @@ import java.util.* @Ignore // not an automatic test, supply your settings below class FinTsClientTest { - private val underTest = FinTsClient(Java8Base64Service()) + private val underTest = object : FinTsClient(Java8Base64Service()) { + + fun synchronizeCustomerSystemId(customer: CustomerData, bank: BankData): FinTsClientResponse { + return synchronizeCustomerSystemId(bank, customer) + } + + } private val BankDataAnonymous = BankData("10070000", Laenderkennzeichen.Germany, "https://fints.deutsche-bank.de/") @@ -46,7 +53,7 @@ class FinTsClientTest { fun synchronizeCustomerSystemId() { // when - val result = underTest.synchronizeCustomerSystemId(Bank, Customer) + val result = underTest.synchronizeCustomerSystemId(Customer, Bank) // then assertThat(result.successful).isTrue()