Skip to content

Commit 7a2f3e2

Browse files
Merge pull request #128 from bunq/feature/dependency_upgrades
Feature/dependency upgrades
2 parents 927545f + a16efdf commit 7a2f3e2

File tree

6 files changed

+66
-52
lines changed

6 files changed

+66
-52
lines changed

README.md

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This SDK is in **beta**. We cannot guarantee constant availability or stability.
2121
Thanks to your feedback we will make improvements on it.
2222

2323
## Installation
24-
``pip install bunq_sdk --upgrade``
24+
pip install bunq_sdk --upgrade
2525

2626
## Usage
2727

@@ -30,19 +30,37 @@ In order to start making calls with the bunq API, you must first register your A
3030
and create a session. In the SDKs, we group these actions and call it "creating an API context". The
3131
context can be created by using the following code snippet:
3232

33-
```
34-
apiContext = context.ApiContext(ENVIRONMENT_TYPE, API_KEY,
35-
DEVICE_DESCRIPTION);
36-
apiContext.save(API_CONTEXT_FILE_PATH)
37-
context.BunqContext.loadApiContext(apiContext)
38-
```
3933

40-
This code snippet, except for `context.BunqContext.loadApiContext(apiContext)` should be called once per API key.
34+
apiContext = ApiContext.create(ENVIRONMENT_TYPE, API_KEY, DEVICE_DESCRIPTION)
35+
apiContext.save(API_CONTEXT_FILE_PATH)
36+
37+
38+
**Please note**: initialising your application is a heavy task and it is recommended to do it only once per device.
39+
40+
apiContext = ApiContext.restore(self.API_CONTEXT_FILE_PATH)
41+
BunqContext.loadApiContext(apiContext)
42+
43+
After saving the context, you can restore it at any time:
4144

4245
#### Example
4346

4447
See [`tinker/setup_context`](https://github.com/bunq/tinker_python/blob/2182b8be276fda921657ad22cfe0b8b48a585ccf/tinker/libs/bunq_lib.py#L44-L59)
4548

49+
#### PSD2
50+
It is possible to create an ApiContext as PSD2 Service Provider. Although this might seem a complex task, we wrote some
51+
helper implementations to get you started. You need to create a certificate and private key to get you started.
52+
Our sandbox environment currently accepts all certificates, if these criteria are met:
53+
54+
- Up to 64 characters
55+
- PISP and/or AISP used in the end.
56+
57+
Make sure you have your unique eIDAS certificate number and certificates ready when you want to perform these tasks on
58+
our production environment.
59+
60+
Creating a PSD2 context is very easy:
61+
62+
apiContext = ApiContext.create_for_psd2(ENVIRONMENT_TYPE, CERTIFICATE, PRIVATE_KEY, CERTIFICATE_CHAIN, DEVICE_DESCRIPTION)
63+
4664
#### Safety considerations
4765
The file storing the context details (i.e. `bunq.conf`) is a key to your account. Anyone having
4866
access to it is able to perform any Public API actions with your account. Therefore, we recommend
@@ -62,14 +80,11 @@ Creating objects through the API requires an `ApiContext`, a `requestMap` and id
6280
dependencies (such as User ID required for accessing a Monetary Account). Optionally, custom headers
6381
can be passed to requests.
6482

65-
66-
```
67-
payment_id = endpoint.Payment.create(
68-
amount=Amount(amount_string, self._CURRENCY_EURL),
69-
counterparty_alias=Pointer(self._POINTER_TYPE_EMAIL, recipient),
70-
description=description
83+
payment_id = endpoint.Payment.create(
84+
amount=Amount(amount_string, self._CURRENCY_EURL),
85+
counterparty_alias=Pointer(self._POINTER_TYPE_EMAIL, recipient),
86+
description=description
7187
)
72-
```
7388

7489
##### Example
7590
See [`tinker/make_payment`](https://github.com/bunq/tinker_python/blob/2182b8be276fda921657ad22cfe0b8b48a585ccf/tinker/libs/bunq_lib.py#L140-L151)
@@ -81,11 +96,9 @@ UUID) Optionally, custom headers can be passed to requests.
8196

8297
This type of calls always returns a model.
8398

84-
```
85-
monetary_account = generated.MonetaryAccountBank.get(
86-
_MONETARY_ACCOUNT_ITEM_ID
87-
)
88-
```
99+
monetary_account = generated.MonetaryAccountBank.get(
100+
_MONETARY_ACCOUNT_ITEM_ID
101+
)
89102

90103
##### Example
91104
See [`tinker/list_all_payment`](https://github.com/bunq/tinker_python/blob/2182b8be276fda921657ad22cfe0b8b48a585ccf/tinker/libs/bunq_lib.py#L85-L103)
@@ -94,12 +107,10 @@ See [`tinker/list_all_payment`](https://github.com/bunq/tinker_python/blob/2182b
94107
Updating objects through the API goes the same way as creating objects, except that also the object to update identifier
95108
(ID or UUID) is needed.
96109

97-
```
98-
endpoint.Card.update(
99-
card_id=int(card_id),
100-
monetary_account_current_id=int(account_id)
101-
)
102-
```
110+
endpoint.Card.update(
111+
card_id=int(card_id),
112+
monetary_account_current_id=int(account_id)
113+
)
103114

104115
##### Example
105116
See [`tinker/update_card`](https://github.com/bunq/tinker_python/blob/2182b8be276fda921657ad22cfe0b8b48a585ccf/tinker/libs/bunq_lib.py#L167-L174)
@@ -109,20 +120,15 @@ Deleting objects through the API requires an `ApiContext`, identifiers of all de
109120
accessing a Monetary Account), and the identifier of the object to delete (ID or UUID) Optionally, custom headers can be
110121
passed to requests.
111122

112-
```
113-
Session.delete(self._SESSION_ID)
114-
```
123+
Session.delete(self._SESSION_ID)
115124

116125
##### Example
117126

118-
119127
#### Listing objects
120128
Listing objects through the API requires an `ApiContext` and identifiers of all dependencies (such as User ID required
121129
for accessing a Monetary Account). Optionally, custom headers can be passed to requests.
122130

123-
```
124-
users = generated.User.list(api_context)
125-
```
131+
users = endpoint.User.list(api_context)
126132

127133
##### Example
128134
See [`UserListExample.py`](./examples/user_list_example.py)
@@ -133,8 +139,8 @@ To get an indication on how the SDK works you can use the python tinker which is
133139
## Running Tests
134140

135141
Information regarding the test cases can be found in the [README.md](./tests/README.md)
136-
located in [test](/tests)
142+
located in [test](/tests).
137143

138144
## Exceptions
139145
The SDK can raise multiple exceptions. For an overview of these exceptions please
140-
take a look at [EXCEPTIONS.md](./bunq/sdk/exception/EXCEPTIONS.md)
146+
take a look at [EXCEPTIONS.md](./bunq/sdk/exception/EXCEPTIONS.md).

bunq/sdk/exception/EXCEPTIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ DESCRIPTION = "This wil raise a BadRequestException"
5454

5555
try:
5656
# Make a call that might raise an exception
57-
ApiContext(ApiEnvironmentType.SANDBOX, API_KEY, DESCRIPTION)
57+
ApiContext.create(ApiEnvironmentType.SANDBOX, API_KEY, DESCRIPTION)
5858
except BadRequestException as error:
5959
# Do something if exception is raised
6060
print(error.response_code)

requirements.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
aenum==2.0.8
1+
aenum==2.2.3
22
chardet==3.0.4
3-
pycryptodomex==3.4.6
4-
requests[socks]==2.18.1
5-
simplejson==3.11.1
6-
urllib3==1.21.1
3+
pycryptodomex==3.9.7
4+
requests[socks]==2.23.0
5+
simplejson==3.17.0
6+
urllib3==1.25.8

setup.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,19 @@
7070
keywords='open-banking sepa bunq finance api payment',
7171

7272
# Packages of the project. "find_packages()" lists all the project packages.
73-
packages=find_packages(exclude=['contrib', 'docs', 'tests', 'examples',
74-
'assets', '.idea', 'run.py']),
73+
packages=find_packages(exclude=['contrib',
74+
'docs',
75+
'tests',
76+
'examples',
77+
'assets',
78+
'.idea',
79+
'run.py']),
7580

7681
# Run-time dependencies of the project. These will be installed by pip.
77-
install_requires=['aenum==2.0.8', 'chardet==3.0.4', 'pycryptodomex==3.4.6',
78-
'requests==2.18.1', 'simplejson==3.11.1',
79-
'urllib3==1.21.1'],
82+
install_requires=['aenum==2.2.3',
83+
'chardet==3.0.4',
84+
'pycryptodomex==3.9.7',
85+
'requests==2.23.0',
86+
'simplejson==3.17.0',
87+
'urllib3==1.25.8'],
8088
)

tests/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ Note:
4848

4949
## Execution
5050

51-
You can run the tests via command line:
51+
You can run all the tests via command line:
5252

53-
```
54-
python -m unittest discover -s tests/model/generated
55-
```
53+
python -m unittest discover -s tests/context && \
54+
python -m unittest discover -s tests/http && \
55+
python -m unittest discover -s tests/model/generated
5656

5757
or via PyCharm, but first you must configure PyCharm by doing the following:
58-
* Got to preferences --> tools --> Python integrated tools and change default
58+
* Go to `Preferences` --> `Tools` --> `Python integrated tools` and change default
5959
test runner to `unittests`.
6060
* Configure your Python interpreter to an supported Python version. Python 3 is
6161
recommended.

tests/context/test_psd2_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TestPsd2Context(unittest.TestCase):
1616
"""
1717

1818
_FILE_TEST_CONFIGURATION = '/assets/bunq-psd2-test.conf'
19-
_FILE_TEST_OAUTH = '/assets/bunq-oauth-test.conf'
19+
_FILE_TEST_OAUTH = '/assets/bunq-oauth-psd2-test.conf'
2020

2121
_FILE_TEST_CERTIFICATE = '/assets/cert.pem'
2222
_FILE_TEST_CERTIFICATE_CHAIN = '/assets/cert.pem'

0 commit comments

Comments
 (0)