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.38'
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 )
@@ -856,7 +860,7 @@ def encode(file_path):
856
860
class IyziLinkProduct (IyzipayResource ):
857
861
def create (self , request , options ):
858
862
return self .connect ('POST' , '/v2/iyzilink/products/' , options , request )
859
-
863
+
860
864
def retrieve (self , request , options ):
861
865
if request .get ('token' ) is None :
862
866
raise Exception ('token must be in request' )
@@ -873,7 +877,7 @@ def update(self, request, options):
873
877
raise Exception ('token must be in request' )
874
878
token = str (request .get ('token' ))
875
879
return self .connect ('PUT' , '/v2/iyzilink/products/' + token , options , request )
876
-
880
+
877
881
def delete (self , request , options ):
878
882
if request .get ('token' ) is None :
879
883
raise Exception ('token must be in request' )
0 commit comments