Added GetTransactionsResponse to have a specific and detailed response

This commit is contained in:
dankl 2019-10-13 18:08:42 +02:00 committed by dankito
parent b086956f95
commit 1daaeeb8d8
5 changed files with 54 additions and 10 deletions

View File

@ -7,6 +7,7 @@ import net.dankito.fints.model.*
import net.dankito.fints.response.InstituteSegmentId import net.dankito.fints.response.InstituteSegmentId
import net.dankito.fints.response.Response import net.dankito.fints.response.Response
import net.dankito.fints.response.ResponseParser import net.dankito.fints.response.ResponseParser
import net.dankito.fints.response.client.GetTransactionsResponse
import net.dankito.fints.response.segments.* import net.dankito.fints.response.segments.*
import net.dankito.fints.util.IBase64Service import net.dankito.fints.util.IBase64Service
import net.dankito.utils.web.client.IWebClient import net.dankito.utils.web.client.IWebClient
@ -89,14 +90,14 @@ open class FinTsClient(
open fun getTransactions(parameter: GetTransactionsParameter, bank: BankData, open fun getTransactions(parameter: GetTransactionsParameter, bank: BankData,
customer: CustomerData): Response { customer: CustomerData): GetTransactionsResponse {
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 initDialogResponse return GetTransactionsResponse(initDialogResponse)
} }
@ -110,7 +111,7 @@ open class FinTsClient(
val balanceResponse = getAndHandleResponseForMessage(balanceRequest, bank) val balanceResponse = getAndHandleResponseForMessage(balanceRequest, bank)
if (balanceResponse.successful == false) { if (balanceResponse.successful == false) {
return balanceResponse return GetTransactionsResponse(balanceResponse)
} }
balanceResponse.getFirstSegmentById<BalanceSegment>(InstituteSegmentId.Balance)?.let { balanceResponse.getFirstSegmentById<BalanceSegment>(InstituteSegmentId.Balance)?.let {
@ -127,7 +128,12 @@ open class FinTsClient(
closeDialog(bank, customer, dialogData) closeDialog(bank, customer, dialogData)
return response
response.getFirstSegmentById<ReceivedAccountTransactions>(InstituteSegmentId.AccountTransactionsMt940)?.let { transactions ->
return GetTransactionsResponse(response, transactions.bookedTransactions, transactions.unbookedTransactions, balance)
}
return GetTransactionsResponse(response)
} }

View File

@ -24,13 +24,10 @@ open class Response constructor(
get() = didReceiveResponse && responseContainsErrors == false get() = didReceiveResponse && responseContainsErrors == false
open val isStrongAuthenticationRequired: Boolean open val isStrongAuthenticationRequired: Boolean
get() { get() = tanResponse?.isStrongAuthenticationRequired == true
getFirstSegmentById<TanResponse>(InstituteSegmentId.Tan)?.let { tanResponse ->
return tanResponse.isStrongAuthenticationRequired
}
return false open val tanResponse: TanResponse?
} get() = getFirstSegmentById(InstituteSegmentId.Tan)
open val messageHeader: ReceivedMessageHeader? open val messageHeader: ReceivedMessageHeader?

View File

@ -0,0 +1,26 @@
package net.dankito.fints.response.client
import net.dankito.fints.response.Response
import net.dankito.fints.response.segments.TanResponse
open class ClientResponseBase(
val successful: Boolean,
val isStrongAuthenticationRequired: Boolean,
val tanRequired: TanResponse? = null,
val errorsToShowToUser: List<String> = listOf(),
/**
* When a serious error occurred during web request or response parsing.
*/
val exception: Exception? = null
) {
constructor(response: Response) : this(response.successful, response.isStrongAuthenticationRequired,
response.tanResponse, response.errorsToShowToUser, response.exception)
}

View File

@ -0,0 +1,14 @@
package net.dankito.fints.response.client
import net.dankito.fints.model.AccountTransaction
import net.dankito.fints.response.Response
import java.math.BigDecimal
open class GetTransactionsResponse(
response: Response,
val bookedTransactions: List<AccountTransaction> = listOf(),
val unbookedTransactions: List<Any> = listOf(),
val balance: BigDecimal? = null
)
: ClientResponseBase(response)

View File

@ -69,6 +69,7 @@ class FinTsClientTest {
// then // then
assertThat(result.successful).isTrue() assertThat(result.successful).isTrue()
assertThat(result.bookedTransactions).isNotEmpty()
} }