diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index a51cf8fd..f0597ff7 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -124,6 +124,47 @@ open class FinTsClient @JvmOverloads constructor( } + 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, 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, bank, response) + + response.messageHeader?.let { header -> dialogData.dialogId = header.dialogId } + + closeDialog(bank, customer, dialogData) + } + + return FinTsClientResponse(response) + } + + open fun addAccountAsync(bank: BankData, customer: CustomerData, callback: (AddAccountResponse) -> Unit) { @@ -417,27 +458,6 @@ open class FinTsClient @JvmOverloads constructor( } - protected open fun resendMessageInNewDialog(message: MessageBuilderResult, bank: BankData, - customer: CustomerData): Response { - - val dialogData = DialogData() - - val initDialogResponse = initDialog(bank, customer, dialogData) - if (initDialogResponse.successful == false) { - return initDialogResponse - } - - - val newMessage = messageBuilder.rebuildMessage(message, bank, customer, dialogData) - - val response = getAndHandleResponseForMessageThatMayRequiresTan(newMessage, bank, customer, dialogData) - - closeDialog(bank, customer, dialogData) - - return response - } - - protected open fun initDialog(bank: BankData, customer: CustomerData, dialogData: DialogData): Response { // we first need to retrieve supported tan procedures and jobs before we can do anything @@ -482,47 +502,6 @@ open class FinTsClient @JvmOverloads constructor( } - 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, 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, bank, response) - - response.messageHeader?.let { header -> dialogData.dialogId = header.dialogId } - - closeDialog(bank, customer, dialogData) - } - - return FinTsClientResponse(response) - } - - protected open fun ensureBasicBankDataRetrieved(bank: BankData, customer: CustomerData): Response { if (bank.supportedTanProcedures.isEmpty() || bank.supportedJobs.isEmpty()) { val getBankInfoResponse = getBankAndCustomerInfoForNewUser(bank, customer) @@ -758,6 +737,27 @@ open class FinTsClient @JvmOverloads constructor( } + protected open fun resendMessageInNewDialog(message: MessageBuilderResult, bank: BankData, + customer: CustomerData): Response { + + val dialogData = DialogData() + + val initDialogResponse = initDialog(bank, customer, dialogData) + if (initDialogResponse.successful == false) { + return initDialogResponse + } + + + val newMessage = messageBuilder.rebuildMessage(message, bank, customer, dialogData) + + val response = getAndHandleResponseForMessageThatMayRequiresTan(newMessage, bank, customer, dialogData) + + closeDialog(bank, customer, dialogData) + + return response + } + + protected open fun updateBankData(bank: BankData, response: Response) { response.getFirstSegmentById(InstituteSegmentId.BankParameters)?.let { bankParameters -> bank.bpdVersion = bankParameters.bpdVersion