Added example to show the options of getAccountData()
This commit is contained in:
parent
345f84c0b2
commit
b35f1146a5
22
README.md
22
README.md
|
@ -32,11 +32,13 @@ dependencies {
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
For the full example source code see [ShowUsage](SampleApp/src/main/kotlin/net/codinux/banking/client/fints4k/example/ShowUsage.kt).
|
||||||
|
|
||||||
### Get AccountData
|
### Get AccountData
|
||||||
|
|
||||||
Retrieves data like accounts, balance and booked transactions (Konten, Saldo und Kontoumsätze).
|
Retrieves data like accounts, balance and booked transactions (Konten, Saldo und Kontoumsätze).
|
||||||
|
|
||||||
Basically:
|
Simple example:
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
class ShowUsage {
|
class ShowUsage {
|
||||||
|
@ -53,6 +55,11 @@ class ShowUsage {
|
||||||
|
|
||||||
val response = client.getAccountData()
|
val response = client.getAccountData()
|
||||||
|
|
||||||
|
printReceivedData(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun printReceivedData(response: Response<GetAccountDataResponse>) {
|
||||||
response.data?.let { data ->
|
response.data?.let { data ->
|
||||||
val customer = data.customer
|
val customer = data.customer
|
||||||
println("Kunde: ${customer.customerName} ${customer.accounts.size} Konten @ ${customer.bic} ${customer.bankName}")
|
println("Kunde: ${customer.customerName} ${customer.accounts.size} Konten @ ${customer.bic} ${customer.bankName}")
|
||||||
|
@ -84,6 +91,19 @@ val client = FinTs4kBankingClientForCustomer(bankCode, loginName, password, Simp
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also specify options e.g. which transactions should be retrieved:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val options = GetAccountDataOptions(
|
||||||
|
retrieveBalance = true, // retrieve balance (Saldo / Kontostand) yes or no
|
||||||
|
retrieveTransactions = RetrieveTransactions.AccordingToRetrieveFromAndTo, // so that fromDate and toDate below determine of which time period transactions (Umsätze) should be retrieved; defaults to OfLast90Days which in most cases doesn't require a TAN
|
||||||
|
retrieveTransactionsFrom = LocalDate(2023, 1, 1),
|
||||||
|
retrieveTransactionsTo = LocalDate(2023, 12, 31),
|
||||||
|
abortIfTanIsRequired = false // e.g. for command line application when entering TAN is either not possible or a TAN procedure is used that cannot be handled via a break point (e.g. showing a TAN image or flicker code)
|
||||||
|
)
|
||||||
|
val response = client.getAccountData(options)
|
||||||
|
```
|
||||||
|
|
||||||
Add some error handling by checking `response.error`:
|
Add some error handling by checking `response.error`:
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
|
|
|
@ -1,12 +1,20 @@
|
||||||
package net.codinux.banking.client.fints4k.example
|
package net.codinux.banking.client.fints4k.example
|
||||||
|
|
||||||
|
import kotlinx.datetime.LocalDate
|
||||||
import net.codinux.banking.client.SimpleBankingClientCallback
|
import net.codinux.banking.client.SimpleBankingClientCallback
|
||||||
import net.codinux.banking.client.fints4k.FinTs4kBankingClientForCustomer
|
import net.codinux.banking.client.fints4k.FinTs4kBankingClientForCustomer
|
||||||
import net.codinux.banking.client.getAccountData
|
import net.codinux.banking.client.getAccountData
|
||||||
|
import net.codinux.banking.client.model.options.GetAccountDataOptions
|
||||||
|
import net.codinux.banking.client.model.options.RetrieveTransactions
|
||||||
|
import net.codinux.banking.client.model.response.GetAccountDataResponse
|
||||||
|
import net.codinux.banking.client.model.response.Response
|
||||||
import net.codinux.banking.client.model.tan.EnterTanResult
|
import net.codinux.banking.client.model.tan.EnterTanResult
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
ShowUsage().getAccountData()
|
val showUsage = ShowUsage()
|
||||||
|
|
||||||
|
showUsage.getAccountDataSimpleExample()
|
||||||
|
// showUsage.getAccountDataFullExample()
|
||||||
}
|
}
|
||||||
|
|
||||||
class ShowUsage {
|
class ShowUsage {
|
||||||
|
@ -18,18 +26,38 @@ class ShowUsage {
|
||||||
private val password = "" // Online-Banking Password mit dem du dich beim Online-Banking deiner Bank anmeldest
|
private val password = "" // Online-Banking Password mit dem du dich beim Online-Banking deiner Bank anmeldest
|
||||||
|
|
||||||
|
|
||||||
fun getAccountData() {
|
fun getAccountDataSimpleExample() {
|
||||||
|
val client = FinTs4kBankingClientForCustomer(bankCode, loginName, password, SimpleBankingClientCallback())
|
||||||
|
|
||||||
|
val response = client.getAccountData()
|
||||||
|
|
||||||
|
printReceivedData(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAccountDataFullExample() {
|
||||||
val client = FinTs4kBankingClientForCustomer(bankCode, loginName, password, SimpleBankingClientCallback { tanChallenge, callback ->
|
val client = FinTs4kBankingClientForCustomer(bankCode, loginName, password, SimpleBankingClientCallback { tanChallenge, callback ->
|
||||||
val tan: String? = null // if a TAN is required, add a UI or ...
|
val tan: String? = null // if a TAN is required, add a UI or ...
|
||||||
callback.invoke(EnterTanResult(tan)) // ... set a break point here, get TAN e.g. from your TAN app, set tan variable in debugger view and resume debugger
|
callback.invoke(EnterTanResult(tan)) // ... set a break point here, get TAN e.g. from your TAN app, set tan variable in debugger view and resume debugger
|
||||||
})
|
})
|
||||||
|
|
||||||
val response = client.getAccountData()
|
val options = GetAccountDataOptions(
|
||||||
|
retrieveBalance = true, // retrieve balance (Saldo / Kontostand) yes or no
|
||||||
|
retrieveTransactions = RetrieveTransactions.AccordingToRetrieveFromAndTo, // so that fromDate and toDate below determine of which time period transactions (Umsätze) should be retrieved; defaults to OfLast90Days which in most cases doesn't require a TAN
|
||||||
|
retrieveTransactionsFrom = LocalDate(2023, 1, 1),
|
||||||
|
retrieveTransactionsTo = LocalDate(2023, 12, 31),
|
||||||
|
abortIfTanIsRequired = false // e.g. for command line application when entering TAN is either not possible or a TAN procedure is used that cannot be handled via a break point (e.g. showing a TAN image or flicker code)
|
||||||
|
)
|
||||||
|
val response = client.getAccountData(options)
|
||||||
|
|
||||||
response.error?.let{ error ->
|
response.error?.let{ error ->
|
||||||
println("Could not fetch account data: ${error.internalError ?: error.errorMessagesFromBank.joinToString()}")
|
println("Could not fetch account data: ${error.internalError ?: error.errorMessagesFromBank.joinToString()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printReceivedData(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun printReceivedData(response: Response<GetAccountDataResponse>) {
|
||||||
response.data?.let { data ->
|
response.data?.let { data ->
|
||||||
val customer = data.customer
|
val customer = data.customer
|
||||||
println("Kunde: ${customer.customerName} ${customer.accounts.size} Konten @ ${customer.bic} ${customer.bankName}")
|
println("Kunde: ${customer.customerName} ${customer.accounts.size} Konten @ ${customer.bic} ${customer.bankName}")
|
||||||
|
|
Loading…
Reference in New Issue