8
8
import string
9
9
10
10
import iyzipay
11
-
11
+ from iyzipay . iyzipay_response import IyzipayResponse
12
12
13
13
class IyzipayResource :
14
14
RANDOM_STRING_SIZE = 8
15
15
RE_SEARCH_V2 = r'/v2/'
16
16
header = {
17
- "Accept" : "application/json" ,
17
+ "Accept" : "application/json" ,
18
18
"Content-type" : "application/json" ,
19
19
'x-iyzi-client-version' : 'iyzipay-python-1.0.40'
20
20
}
@@ -27,7 +27,11 @@ def connect(self, method, url, options, request_body_dict=None, pki=None):
27
27
body_str = json .dumps (request_body_dict )
28
28
header = self .get_http_header (url , options , body_str , pki )
29
29
connection .request (method , url , body_str , header )
30
- return connection .getresponse ()
30
+ try :
31
+ body = json .loads (response .read ().decode ('utf-8' ))
32
+ except :
33
+ body = None
34
+ return IyzipayResponse (response .status , body )
31
35
32
36
def get_http_header (self , url , options = None , body_str = None , pki_string = None ):
33
37
random_str = self .generate_random_string (self .RANDOM_STRING_SIZE )
@@ -866,7 +870,7 @@ def encode(file_path):
866
870
class IyziLinkProduct (IyzipayResource ):
867
871
def create (self , request , options ):
868
872
return self .connect ('POST' , '/v2/iyzilink/products/' , options , request )
869
-
873
+
870
874
def retrieve (self , request , options ):
871
875
if request .get ('token' ) is None :
872
876
raise Exception ('token must be in request' )
@@ -883,7 +887,7 @@ def update(self, request, options):
883
887
raise Exception ('token must be in request' )
884
888
token = str (request .get ('token' ))
885
889
return self .connect ('PUT' , '/v2/iyzilink/products/' + token , options , request )
886
-
890
+
887
891
def delete (self , request , options ):
888
892
if request .get ('token' ) is None :
889
893
raise Exception ('token must be in request' )
0 commit comments