Java SDK for bunq API
Hi developers!
Welcome to the bunq Java SDK! π¨βπ»
Weβre very happy to introduce yet another unique product: complete banking SDKs!
Now you can build even bigger and better apps and integrate them with your bank of the free! π
Before you dive into this brand new SDK, please consider:
Give us your feedback, create pull requests, build your very own bunq apps and most importantly:
have fun! πͺ
This SDK is in beta. We cannot guarantee constant availability or stability.
Thanks to your feedback we will make improvements on it.
To install the package, please follow the instructions corresponding to your build tool under βHow toβ on the package page on JitPack: https://jitpack.io/#bunq/sdk_java
In order to start making calls with the bunq API, you must first register your API key and device,
and create a session. In the SDKs, we group these actions and call it βcreating an API contextβ. The
context can be created by using the following code snippet:
ApiContext apiContext = ApiContext.create(ENVIRONMENT_TYPE, API_KEY,
DEVICE_DESCRIPTION);
apiContext.save(API_CONTEXT_FILE_PATH);
Please note: initialising your application is a heavy task and it is recommended to do it only once per device.
After saving the context, you can restore it at any time:
ApiContext apiContext = ApiContext.restore(API_CONTEXT_FILE_PATH);
BunqContext.loadApiContext(apiContext);
Tip: both saving and restoring the context can be done without any arguments. In this case the context will be saved to/restored from the bunq.conf
file in the same folder with your executable.
It is possible to create an ApiContext as PSD2 Service Provider. Although this might seem a complex task, we wrote some helper implementations to get you started.
You need to create a certificate and private key to get you started. Our sandbox environment currently accepts all certificates, if these criteria are met:
Make sure you have your unique eIDAS certificate number and certificates ready when you want to perform these tasks on our production environment.
Creating a PSD2 context is very easy:
ApiContext apiContext = ApiContext.createForPsd2(
ENVIRONMENT_TYPE,
SecurityUtils.getCertificateFromFile(PATH_TO_CERTIFICATE),
SecurityUtils.getPrivateKeyFromFile(PATH_TO_PRIVATE_KEY),
new Certificate[]{
SecurityUtils.getCertificateFromFile(PATH_TO_CERTIFICATE_CHAIN)
},
DESCRIPTION
)
This context can be saved the same way as a normal ApiContext. After creating this context, create an OAuth client to get your users to grant you access.
For a more detailed example, check the tinker_java repository.
The file storing the context details (i.e. bunq.conf
) is a key to your account. Anyone having
access to it is able to perform any Public API actions with your account. Therefore, we recommend
choosing a truly safe place to store it.
There is a class for each endpoint. Each class has functions for each supported action. These actions can be create
, get
, update
, delete
and list
.
When making calls, The userId
and monetaryAccountId
needed to make calls will be determined by the SDK it. When no monetaryAccountId
has been passed, the SDK will use the first active monetary account it can find. This is normally the monetary account used for billing.
Before you make a call, make sure that you have loaded ApiContext
in to the BunqContext
.
With the create
method you can create new models. This method normally returns the id
of the created model.
Payment.create(
new Amount(amount, CURRENCY_EURO),
new Pointer(POINTER_TYPE_EMAIL, recipient),
description
);
Note! Due to an in internal change in the way we handle NotificationFilters
(Callbacks), you should not use the default classes included in this SDK.
Please make sure you make use of the associated Internal
-classes. For example when you need NotificationFilterUrlUser
, make use of NotificationFilterUrlUserInternal
.
You can use every method of these classes, except for the create()
method. Always use createWithListResponse()
instead.
NotificationFilterPushUserInternal.createWithListResponse(...)
NotificationFilterUrlUserInternal.createWithListResponse(...)
NotificationFilterUrlMonetaryAccountInternal.createWithListResponse(...)
Reading objects can be done via the get
or list
method.
These type of calls always returns the model or binary data.
Payment.list(
monetaryAccountBank.getId(),
pagination.getUrlParamsCountOnly()
)
Updating objects through the API goes the same way as creating objects, except that also the object to update identifier (ID or UUID) is needed.
The update
method will also normally return the Id
of the updated model.
MonetaryAccountBank.update(Integer.parseInt(accountId), name);
See tinker/update_monetary_account
Deleting object can be done via the delete
method. This method also requires the object identifier which could be an Id
or uuid
.
This method normally returns an empty response.
CustomerStatementExport.delete(customerStatementId);
To have an idea on how the SDK works you can play around with the java tinker located at: https://github.com/bunq/tinker_java
Information regarding the test cases can be found in the README.md
located in test.
The SDK can throw multiple exceptions. For an overview of these exceptions please
take a look at EXCEPTIONS.md