1
1
import json
2
2
from os .path import isfile
3
3
import socket
4
+ from time import sleep
4
5
5
6
import requests
6
7
from bunq .sdk .client import Pagination
@@ -35,6 +36,7 @@ class BunqLib(object):
35
36
_REQUEST_SPENDING_MONEY_AMOUNT = '500.0'
36
37
_REQUEST_SPENDING_MONEY_RECIPIENT = 'sugardaddy@bunq.com'
37
38
_REQUEST_SPENDING_MONEY_DESCRIPTION = 'Requesting some spending money.'
39
+ _REQUEST_SPENDING_MONEY_WAIT_TIME_SECONDS = 1
38
40
39
41
_ZERO_BALANCE = 0.0
40
42
@@ -47,7 +49,7 @@ def __init__(self, env):
47
49
self .env = env
48
50
self .setup_context ()
49
51
self .setup_current_user ()
50
- self .request_spending_money_if_needed ()
52
+ self .__request_spending_money_if_needed ()
51
53
52
54
def setup_context (self ):
53
55
if isfile (self .determine_bunq_conf_filename ()):
@@ -242,12 +244,17 @@ def generate_new_sandbox_user(self):
242
244
243
245
raise BunqException (self ._ERROR_COULD_NOT_CREATE_NEW_SANDBOX_USER )
244
246
245
- def request_spending_money_if_needed (self ):
246
- if self .env == ApiEnvironmentType .SANDBOX \
247
- and float (BunqContext .user_context ().primary_monetary_account .balance .value ) <= self ._ZERO_BALANCE :
247
+ def __request_spending_money_if_needed (self ):
248
+ if self .__should_request_spending_money ():
248
249
endpoint .RequestInquiry .create (
249
250
amount_inquired = Amount (self ._REQUEST_SPENDING_MONEY_AMOUNT , self ._CURRENCY_EUR ),
250
251
counterparty_alias = Pointer (self ._POINTER_TYPE_EMAIL , self ._REQUEST_SPENDING_MONEY_RECIPIENT ),
251
252
description = self ._REQUEST_SPENDING_MONEY_DESCRIPTION ,
252
253
allow_bunqme = False
253
254
)
255
+ sleep (self ._REQUEST_SPENDING_MONEY_WAIT_TIME_SECONDS )
256
+ BunqContext .user_context ().refresh_user_context ()
257
+
258
+ def __should_request_spending_money (self ):
259
+ return self .env == ApiEnvironmentType .SANDBOX \
260
+ and float (BunqContext .user_context ().primary_monetary_account .balance .value ) <= self ._ZERO_BALANCE
0 commit comments