Added GetTransactionsResponse to have a specific and detailed response
This commit is contained in:
parent
b086956f95
commit
1daaeeb8d8
|
@ -7,6 +7,7 @@ import net.dankito.fints.model.*
|
|||
import net.dankito.fints.response.InstituteSegmentId
|
||||
import net.dankito.fints.response.Response
|
||||
import net.dankito.fints.response.ResponseParser
|
||||
import net.dankito.fints.response.client.GetTransactionsResponse
|
||||
import net.dankito.fints.response.segments.*
|
||||
import net.dankito.fints.util.IBase64Service
|
||||
import net.dankito.utils.web.client.IWebClient
|
||||
|
@ -89,14 +90,14 @@ open class FinTsClient(
|
|||
|
||||
|
||||
open fun getTransactions(parameter: GetTransactionsParameter, bank: BankData,
|
||||
customer: CustomerData): Response {
|
||||
customer: CustomerData): GetTransactionsResponse {
|
||||
|
||||
val dialogData = DialogData()
|
||||
|
||||
val initDialogResponse = initDialog(bank, customer, dialogData)
|
||||
|
||||
if (initDialogResponse.successful == false) {
|
||||
return initDialogResponse
|
||||
return GetTransactionsResponse(initDialogResponse)
|
||||
}
|
||||
|
||||
|
||||
|
@ -110,7 +111,7 @@ open class FinTsClient(
|
|||
val balanceResponse = getAndHandleResponseForMessage(balanceRequest, bank)
|
||||
|
||||
if (balanceResponse.successful == false) {
|
||||
return balanceResponse
|
||||
return GetTransactionsResponse(balanceResponse)
|
||||
}
|
||||
|
||||
balanceResponse.getFirstSegmentById<BalanceSegment>(InstituteSegmentId.Balance)?.let {
|
||||
|
@ -127,7 +128,12 @@ open class FinTsClient(
|
|||
|
||||
closeDialog(bank, customer, dialogData)
|
||||
|
||||
return response
|
||||
|
||||
response.getFirstSegmentById<ReceivedAccountTransactions>(InstituteSegmentId.AccountTransactionsMt940)?.let { transactions ->
|
||||
return GetTransactionsResponse(response, transactions.bookedTransactions, transactions.unbookedTransactions, balance)
|
||||
}
|
||||
|
||||
return GetTransactionsResponse(response)
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,13 +24,10 @@ open class Response constructor(
|
|||
get() = didReceiveResponse && responseContainsErrors == false
|
||||
|
||||
open val isStrongAuthenticationRequired: Boolean
|
||||
get() {
|
||||
getFirstSegmentById<TanResponse>(InstituteSegmentId.Tan)?.let { tanResponse ->
|
||||
return tanResponse.isStrongAuthenticationRequired
|
||||
}
|
||||
get() = tanResponse?.isStrongAuthenticationRequired == true
|
||||
|
||||
return false
|
||||
}
|
||||
open val tanResponse: TanResponse?
|
||||
get() = getFirstSegmentById(InstituteSegmentId.Tan)
|
||||
|
||||
|
||||
open val messageHeader: ReceivedMessageHeader?
|
||||
|
|
|
@ -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)
|
||||
|
||||
}
|
|
@ -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)
|
|
@ -69,6 +69,7 @@ class FinTsClientTest {
|
|||
|
||||
// then
|
||||
assertThat(result.successful).isTrue()
|
||||
assertThat(result.bookedTransactions).isNotEmpty()
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue