3
3
from os .path import isfile
4
4
from os import remove
5
5
import socket
6
+ from time import sleep
6
7
7
8
import requests
8
9
from bunq .sdk .client import Pagination
14
15
from bunq .sdk .model .generated import endpoint
15
16
from bunq .sdk .model .generated .object_ import Pointer , Amount , NotificationFilter
16
17
18
+
17
19
NOTIFICATION_DELIVERY_METHOD_URL = 'URL'
18
20
19
21
NOTIFICATION_CATEGORY_MUTATION = 'MUTATION'
@@ -31,9 +33,16 @@ class BunqLib(object):
31
33
32
34
_DEFAULT_COUNT = 10
33
35
_POINTER_TYPE_EMAIL = 'EMAIL'
34
- _CURRENCY_EURL = 'EUR'
36
+ _CURRENCY_EUR = 'EUR'
35
37
_DEVICE_DESCRIPTION = "python tinker"
36
38
39
+ _REQUEST_SPENDING_MONEY_AMOUNT = '500.0'
40
+ _REQUEST_SPENDING_MONEY_RECIPIENT = 'sugardaddy@bunq.com'
41
+ _REQUEST_SPENDING_MONEY_DESCRIPTION = 'Requesting some spending money.'
42
+ _REQUEST_SPENDING_MONEY_WAIT_TIME_SECONDS = 1
43
+
44
+ _ZERO_BALANCE = 0.0
45
+
37
46
def __init__ (self , env ):
38
47
"""
39
48
:type env: ApiEnvironmentType
@@ -43,6 +52,7 @@ def __init__(self, env):
43
52
self .env = env
44
53
self .setup_context ()
45
54
self .setup_current_user ()
55
+ self .__request_spending_money_if_needed ()
46
56
47
57
def setup_context (self , reset_config_if_needed = True ):
48
58
if isfile (self .determine_bunq_conf_filename ()):
@@ -161,7 +171,7 @@ def make_payment(self, amount_string, description, recipient):
161
171
"""
162
172
163
173
endpoint .Payment .create (
164
- amount = Amount (amount_string , self ._CURRENCY_EURL ),
174
+ amount = Amount (amount_string , self ._CURRENCY_EUR ),
165
175
counterparty_alias = Pointer (self ._POINTER_TYPE_EMAIL , recipient ),
166
176
description = description
167
177
)
@@ -174,7 +184,7 @@ def make_request(self, amount_string, description, recipient):
174
184
"""
175
185
176
186
endpoint .RequestInquiry .create (
177
- amount_inquired = Amount (amount_string , self ._CURRENCY_EURL ),
187
+ amount_inquired = Amount (amount_string , self ._CURRENCY_EUR ),
178
188
counterparty_alias = Pointer (self ._POINTER_TYPE_EMAIL , recipient ),
179
189
description = description ,
180
190
allow_bunqme = True
@@ -249,3 +259,17 @@ def generate_new_sandbox_user(self):
249
259
json .dumps (response_json ["Response" ][0 ]["ApiKey" ]))
250
260
251
261
raise BunqException (self ._ERROR_COULD_NOT_CREATE_NEW_SANDBOX_USER )
262
+
263
+ def __request_spending_money_if_needed (self ):
264
+ if self .__should_request_spending_money ():
265
+ endpoint .RequestInquiry .create (
266
+ amount_inquired = Amount (self ._REQUEST_SPENDING_MONEY_AMOUNT , self ._CURRENCY_EUR ),
267
+ counterparty_alias = Pointer (self ._POINTER_TYPE_EMAIL , self ._REQUEST_SPENDING_MONEY_RECIPIENT ),
268
+ description = self ._REQUEST_SPENDING_MONEY_DESCRIPTION ,
269
+ allow_bunqme = False
270
+ )
271
+ sleep (self ._REQUEST_SPENDING_MONEY_WAIT_TIME_SECONDS )
272
+
273
+ def __should_request_spending_money (self ):
274
+ return self .env == ApiEnvironmentType .SANDBOX \
275
+ and float (BunqContext .user_context ().primary_monetary_account .balance .value ) <= self ._ZERO_BALANCE
0 commit comments