From 362b09a24689b064e1ec034cfb076bf488a0fdcb Mon Sep 17 00:00:00 2001 From: dankl Date: Sun, 13 Oct 2019 17:36:26 +0200 Subject: [PATCH] Added parameter alsoRetrieveBalance --- .../kotlin/net/dankito/fints/FinTsClient.kt | 19 ++++++++++++++----- .../fints/model/GetTransactionsParameter.kt | 1 + .../net/dankito/fints/FinTsClientTest.kt | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt index 1fd82cbb..a2ce0868 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -14,6 +14,7 @@ import net.dankito.utils.web.client.OkHttpWebClient import net.dankito.utils.web.client.RequestParameters import net.dankito.utils.web.client.WebClientResponse import org.slf4j.LoggerFactory +import java.math.BigDecimal open class FinTsClient( @@ -99,14 +100,22 @@ open class FinTsClient( } - dialogData.increaseMessageNumber() + var balance: BigDecimal? = null - val balanceRequest = messageBuilder.createGetBalanceMessage(bank, customer, product, dialogData) + if (parameter.alsoRetrieveBalance) { + dialogData.increaseMessageNumber() - val balanceResponse = getAndHandleResponseForMessage(balanceRequest, bank) + val balanceRequest = messageBuilder.createGetBalanceMessage(bank, customer, product, dialogData) - if (balanceResponse.successful == false) { - return balanceResponse + val balanceResponse = getAndHandleResponseForMessage(balanceRequest, bank) + + if (balanceResponse.successful == false) { + return balanceResponse + } + + balanceResponse.getFirstSegmentById(InstituteSegmentId.Balance)?.let { + balance = it.balance + } } diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/GetTransactionsParameter.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/GetTransactionsParameter.kt index a9f369dc..d9e05d1d 100644 --- a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/GetTransactionsParameter.kt +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/GetTransactionsParameter.kt @@ -4,6 +4,7 @@ import java.util.* open class GetTransactionsParameter( + val alsoRetrieveBalance: Boolean = true, val fromDate: Date? = null, val toDate: Date? = null, val maxAmount: Int? = null, diff --git a/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt b/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt index e8382f35..ebc62718 100644 --- a/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt +++ b/fints4javaLib/src/test/kotlin/net/dankito/fints/FinTsClientTest.kt @@ -65,7 +65,7 @@ class FinTsClientTest { val ninetyDaysAgo = Date(Date().time - ninetyDaysAgoMilliseconds) // when - val result = underTest.getTransactions(GetTransactionsParameter(ninetyDaysAgo), Bank, Customer) + val result = underTest.getTransactions(GetTransactionsParameter(fromDate = ninetyDaysAgo), Bank, Customer) // then assertThat(result.successful).isTrue()