Giter VIP home page Giter VIP logo

beeone-banking-client's Introduction

beeone-banking-client

API client for the BeeOne netbanking light API.

You should use this together with the REST api documentation for the netbanking API. I did not bother packaging this into a jar file, since you probably want tohave the option to look at or modify the code anyway.

There are no dependencies if you run this on Android. Just add the source code to your project and you should be fine. If you need to use the API in a JDK project, you also need to package the json parser in /lib with your project.

// create a new session for a user and login to the netbanking system
NetbankingSession session = new NetbankingSession.Builder()
        .endpoint(ENDPOINT).username(USERNAME).password(PASSWORD)
        .login();

// let's start with something simple:
assertTrue(session.ping());// the server is up and reachable

// a list of all accounts that the user owns.
List<Account> accounts = session.getAccounts();

// you can get a single account for a specific iban
String someIban = "AT032011156172743372";
Account account = session.getAccount(someIban);

// you can update an accounts settings, like giving it a new name:
account.getSettings().setName("my new account name");
session.updateAccountSettings(account);

Long amount = 133700L;

// lets create a new transaction. There are no mandatory fields on the
// transaction. Unless we finish it, it will be considered a just a
// draft.
Transaction newTransaction = session.newTransaction();
newTransaction.setAmount(amount);
newTransaction = session.addTransaction(account, newTransaction);
assertNotNull(newTransaction.getId());
assertEquals(someIban, newTransaction.getAccount().getIban());
// let's see if this worked. We try to get the new transaction from the
// server
Transaction ourTransaction = session.getTransaction(account,
        newTransaction.getId());

assertEquals(newTransaction.getId(), ourTransaction.getId());
assertEquals(amount, ourTransaction.getAmount());

// now we add some more data to the transaction and send the update to
// the server:
String purpose = "I won the hackathon!";
ourTransaction.setPurpose(purpose);

Calendar cal = java.util.Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.MONTH, 1); // I hate java.util.Calendar...
Date carryOutDate = cal.getTime();
ourTransaction.setCarryOutDate(carryOutDate);

session.updateTransaction(ourTransaction);

// to test this, we fetch the transaction once again from the server
ourTransaction = session
        .getTransaction(account, ourTransaction.getId());

assertEquals(purpose, ourTransaction.getPurpose());

// finally, we finish the transaction
ourTransaction.setFinished(true);
session.updateTransaction(ourTransaction);

// of course, we cannot update the transaction after we finished it:
try {
    ourTransaction.setAmount(1234500L);
    session.updateTransaction(ourTransaction);
    fail();
} catch (RuntimeException e) {
    assert (true);
}

// errors like these are expected and not really exceptional. So often
// we want to pass an ErrorHandler to handle these cases, instead of
// catching Exceptions:
ourTransaction.setAmount(1234500L);
final boolean[] errorHandlerExecuted = new boolean[] { false };
session.updateTransaction(ourTransaction, new ErrorHandler() {
    public void onError(HttpError status) {
        errorHandlerExecuted[0] = true;
        assertEquals(409, status.getStatusCode());
        assertEquals("Conflict", status.getStatusMessage());

        // we would like to have an Error
        assertEquals(null, status.getErrorMessage());
    }
});

if (!errorHandlerExecuted[0]) {
    fail();
}

// finally, we can delete the transaction
session.deleteTransaction(ourTransaction);

// let's get some transactions from the account
int pageSize = 16;
int page = 2;
List<Transaction> transactions = session.getTransactions(
        account.getIban(), pageSize, page);

// or we search for some transactions
pageSize = 5;
page = 0;
transactions = session.searchTransactions(">119.80", pageSize, page);
assertEquals(5, transactions.size());

beeone-banking-client's People

Contributors

bookwormat avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.