66
77
88class Client :
9- def __init__ (self , api_key = None ):
10- self .api_url = 'https://testapi.multisafepay.com/v1/json'
9+ def __init__ (self , modus = None , api_key = None ):
10+ self .modus = modus
11+ self .api_url = None
1112 self .api_key = api_key
1213 self .order = Orders (self )
1314 self .paymentmethod = PaymentMethod
@@ -16,6 +17,15 @@ def __init__(self, api_key=None):
1617 def set_api_key (self , api_key ):
1718 self .api_key = self .validate_api_key (api_key )
1819
20+ def set_modus (self , modus ):
21+ self .modus = modus
22+ if self .modus is 'TEST' :
23+ self .api_url = 'https://testapi.multisafepay.com/v1/json'
24+ elif self .modus is 'LIVE' :
25+ self .api_url = 'https://api.multisafepay.com/v1/json'
26+ else :
27+ raise ValueError ('Invalid API mode, needs to be LIVE or TEST' )
28+
1929 @staticmethod
2030 def validate_api_key (api_key ):
2131 api_key = api_key .strip ()
@@ -24,10 +34,11 @@ def validate_api_key(api_key):
2434 "characters long" .format (api_key = api_key ))
2535 return api_key
2636
27- def execute_http_call (self , http_method , endpoint , data = None ,** kwargs ):
37+ def execute_http_call (self , http_method , endpoint , data = None , ** kwargs ):
38+ print (self .api_url )
2839 response = requests .request (http_method ,
2940 url = '{0}/{1}' .format (self .api_url , endpoint ),
3041 headers = {'api_key' :'{api_key}' .format (
31- api_key = self .api_key )}, json = data ,** kwargs )
42+ api_key = self .api_key )}, json = data , ** kwargs )
3243 json_data = json .loads (response .text )
3344 return json_data
0 commit comments