Extracted sendMessageAndHandleResponse()

This commit is contained in:
dankito 2020-05-09 13:13:26 +02:00
parent 9215a6974f
commit 978b7507bb
1 changed files with 23 additions and 37 deletions

View File

@ -362,24 +362,12 @@ open class FinTsClient @JvmOverloads constructor(
open fun getTanMediaList(bank: BankData, customer: CustomerData, tanMediaKind: TanMedienArtVersion = TanMedienArtVersion.Alle, open fun getTanMediaList(bank: BankData, customer: CustomerData, tanMediaKind: TanMedienArtVersion = TanMedienArtVersion.Alle,
tanMediumClass: TanMediumKlasse = TanMediumKlasse.AlleMedien): GetTanMediaListResponse { tanMediumClass: TanMediumKlasse = TanMediumKlasse.AlleMedien): GetTanMediaListResponse {
val dialogData = DialogData() val response = sendMessageAndHandleResponse(bank, customer) { dialogData ->
messageBuilder.createGetTanMediaListMessage(bank, customer, dialogData, tanMediaKind, tanMediumClass)
val initDialogResponse = initDialog(bank, customer, dialogData)
if (initDialogResponse.successful == false) {
return GetTanMediaListResponse(initDialogResponse, null)
} }
val tanMediaList = if (response.successful == false ) null
dialogData.increaseMessageNumber() else response.getFirstSegmentById<TanMediaList>(InstituteSegmentId.TanMediaList)
val message = messageBuilder.createGetTanMediaListMessage(bank, customer, dialogData, tanMediaKind, tanMediumClass)
val response = getAndHandleResponseForMessageThatMayRequiresTan(message, bank, customer, dialogData)
closeDialog(bank, customer, dialogData)
val tanMediaList = response.getFirstSegmentById<TanMediaList>(InstituteSegmentId.TanMediaList)
tanMediaList?.let { tanMediaList?.let {
customer.tanMedia = it.tanMedia customer.tanMedia = it.tanMedia
@ -403,23 +391,10 @@ open class FinTsClient @JvmOverloads constructor(
} }
val dialogData = DialogData() val response = sendMessageAndHandleResponse(bank, customer, false) { dialogData ->
messageBuilder.createChangeTanMediumMessage(newActiveTanMedium, bank, customer, dialogData,
val initDialogResponse = initDialog(bank, customer, dialogData)
if (initDialogResponse.successful == false) {
return FinTsClientResponse(initDialogResponse)
}
dialogData.increaseMessageNumber()
val message = messageBuilder.createChangeTanMediumMessage(newActiveTanMedium, bank, customer, dialogData,
enteredAtc?.tan, enteredAtc?.atc) enteredAtc?.tan, enteredAtc?.atc)
}
val response = getAndHandleResponseForMessage(message, bank)
closeDialog(bank, customer, dialogData)
return FinTsClientResponse(response) return FinTsClientResponse(response)
@ -437,26 +412,37 @@ open class FinTsClient @JvmOverloads constructor(
open fun doBankTransfer(bankTransferData: BankTransferData, bank: BankData, open fun doBankTransfer(bankTransferData: BankTransferData, bank: BankData,
customer: CustomerData, account: AccountData): FinTsClientResponse { customer: CustomerData, account: AccountData): FinTsClientResponse {
val response = sendMessageAndHandleResponse(bank, customer) { dialogData ->
messageBuilder.createBankTransferMessage(bankTransferData, bank, customer, account, dialogData)
}
return FinTsClientResponse(response)
}
protected open fun sendMessageAndHandleResponse(bank: BankData, customer: CustomerData, messageMayRequiresTan: Boolean = true,
createMessage: (DialogData) -> MessageBuilderResult): Response {
val dialogData = DialogData() val dialogData = DialogData()
val initDialogResponse = initDialog(bank, customer, dialogData) val initDialogResponse = initDialog(bank, customer, dialogData)
if (initDialogResponse.successful == false) { if (initDialogResponse.successful == false) {
return FinTsClientResponse(initDialogResponse) return initDialogResponse
} }
dialogData.increaseMessageNumber() dialogData.increaseMessageNumber()
val message = messageBuilder.createBankTransferMessage(bankTransferData, bank, customer, account, dialogData) val message = createMessage(dialogData)
val response = getAndHandleResponseForMessageThatMayRequiresTan(message, bank, customer, dialogData) val response = if (messageMayRequiresTan) getAndHandleResponseForMessageThatMayRequiresTan(message, bank, customer, dialogData)
else getAndHandleResponseForMessage(message, bank)
closeDialog(bank, customer, dialogData) closeDialog(bank, customer, dialogData)
return FinTsClientResponse(response)
}
return response
}
protected open fun initDialog(bank: BankData, customer: CustomerData, dialogData: DialogData): Response { protected open fun initDialog(bank: BankData, customer: CustomerData, dialogData: DialogData): Response {