From 5b5173132f2d717a1ac4b1b90a573648be1616ea Mon Sep 17 00:00:00 2001 From: dankl Date: Sun, 26 Jan 2020 12:17:04 +0100 Subject: [PATCH] Updated Java showcase code --- .../net/dankito/fints/java/JavaShowcase.java | 67 +++++++++++++------ 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java b/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java index fb6aaf72..3b91a1cb 100644 --- a/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java +++ b/fints4javaLib/src/test/java/net/dankito/fints/java/JavaShowcase.java @@ -3,17 +3,16 @@ package net.dankito.fints.java; import net.dankito.fints.FinTsClient; import net.dankito.fints.FinTsClientCallback; import net.dankito.fints.banks.BankFinder; -import net.dankito.fints.messages.datenelemente.implementierte.signatur.Sicherheitsfunktion; import net.dankito.fints.messages.datenelemente.implementierte.tan.TanGeneratorTanMedium; import net.dankito.fints.model.*; import net.dankito.fints.model.mapper.BankDataMapper; +import net.dankito.fints.response.client.AddAccountResponse; +import net.dankito.fints.response.client.FinTsClientResponse; import net.dankito.fints.response.client.GetTransactionsResponse; import net.dankito.fints.util.Java8Base64Service; - import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Date; import java.util.List; @@ -24,13 +23,12 @@ public class JavaShowcase { // set your bank code (Bankleitzahl) here. Or create BankData manually. Required fields are: // bankCode, bankCountryCode (Germany = 280), finTs3ServerAddress and for bank transfers bic - List foundBanks = bankFinder.findBankByBankCode("10070000"); + List foundBanks = bankFinder.findBankByBankCode(""); if (foundBanks.isEmpty() == false) { BankData bank = new BankDataMapper().mapFromBankInfo(foundBanks.get(0)); // set your customer data (customerId = Kontonummer in most cases, pin = online banking pin) CustomerData customer = new CustomerData("", ""); - customer.setSelectedTanProcedure(new TanProcedure("", Sicherheitsfunktion.PIN_TAN_911, TanProcedureType.ChipTanOptisch)); FinTsClientCallback callback = new FinTsClientCallback() { @@ -55,18 +53,43 @@ public class JavaShowcase { FinTsClient finTsClient = new FinTsClient(callback, new Java8Base64Service()); - // some banks support retrieving account transactions of last 90 days without TAN - long ninetyDaysAgoMilliseconds = 90 * 24 * 60 * 60 * 1000L; - Date ninetyDaysAgo = new Date(new Date().getTime() - ninetyDaysAgoMilliseconds); + AddAccountResponse addAccountResponse = finTsClient.addAccount(bank, customer); + if (addAccountResponse.isSuccessful()) { + System.out.println("Could not add account for " + bank.getBankCode() + " " + customer.getCustomerId() + ":"); + showResponseError(addAccountResponse); + return; + } - GetTransactionsResponse response = finTsClient.getTransactions( - new GetTransactionsParameter(true, ninetyDaysAgo), bank, customer); + System.out.println("Successfully added account for " + bank.getBankCode() + " " + customer.getCustomerId()); - showResponse(response); + /* Other stuff you can do with the lib */ + + for (AccountData account : customer.getAccounts()) { // accounts are now retrieved + if (account.getSupportsRetrievingAccountTransactions()) { + // retrieves all account transactions, but requires entering a TAN (FinTsClientCallback.enterTan() will be called) +// GetTransactionsResponse response = finTsClient.getTransactions( +// new GetTransactionsParameter(true), bank, customer, account); +// +// showGetTransactionsResponse(response); + } + + if (account.getSupportsTransferringMoney()) { + // transfer 0.01 € to yourself +// BankTransferData data = new BankTransferData(customer.getName(), account.getIban(), bank.getBic(), new BigDecimal("0.01"), "Hey I can transfer money to myself") +// FinTsClientResponse transferMoneyResponse = finTsClient.doBankTransfer(data, bank, customer, account); +// +// if (transferMoneyResponse.isSuccessful()) { +// System.out.println("Successfully transferred " + data.getAmount() + " to " + data.getCreditorIban()); +// } +// else { +// showResponseError(transferMoneyResponse); +// } + } + } } } - private static void showResponse(GetTransactionsResponse response) { + private static void showGetTransactionsResponse(GetTransactionsResponse response) { if (response.isSuccessful()) { System.out.println("Balance (Saldo) = " + response.getBalance()); @@ -82,16 +105,20 @@ public class JavaShowcase { } else { System.out.println("An error occurred:"); - if (response.getException() != null) { // something severe occurred - System.out.println(response.getException().getMessage()); - } - - // error messages retrieved from bank (e.g. PIN is wrong, message contains errors, ...) - for (String retrievedErrorMessage : response.getErrorsToShowToUser()) { - System.out.println(retrievedErrorMessage); - } + showResponseError(response); } } } + private static void showResponseError(FinTsClientResponse response) { + if (response.getException() != null) { // something severe occurred + System.out.println(response.getException().getMessage()); + } + + // error messages retrieved from bank (e.g. PIN is wrong, message contains errors, ...) + for (String retrievedErrorMessage : response.getErrorsToShowToUser()) { + System.out.println(retrievedErrorMessage); + } + } + }