@@ -60,6 +60,7 @@ def _pycurl_post(self,
60
60
data = None ,
61
61
username = "" ,
62
62
password = "" ,
63
+ xapikey = "" ,
63
64
headers = {},
64
65
timeout = 30 ):
65
66
"""This function will POST to the url endpoint using pycurl. returning
@@ -77,6 +78,8 @@ def _pycurl_post(self,
77
78
as part of password.
78
79
password (str, optional): Password for basic auth. Must be included
79
80
as part of username.
81
+ xapikey (str, optional): Adyen API key. Will be used for auth
82
+ if username and password are absent.
80
83
headers (dict, optional): Key/Value pairs of headers to include
81
84
timeout (int, optional): Default 30. Timeout for the request.
82
85
@@ -102,6 +105,11 @@ def _pycurl_post(self,
102
105
# request can be identified as coming from the Adyen Python library.
103
106
headers ['User-Agent' ] = self .user_agent
104
107
108
+ if username and password :
109
+ curl .setopt (curl .USERPWD , '%s:%s' % (username , password ))
110
+ elif xapikey :
111
+ headers ["X-API-KEY" ] = xapikey
112
+
105
113
# Convert the header dict to formatted array as pycurl needs.
106
114
if sys .version_info [0 ] >= 3 :
107
115
header_list = ["%s:%s" % (k , v ) for k , v in headers .items ()]
@@ -120,9 +128,6 @@ def _pycurl_post(self,
120
128
raw_request = json_lib .dumps (json ) if json else urlencode (data )
121
129
curl .setopt (curl .POSTFIELDS , raw_request )
122
130
123
- if username and password :
124
- curl .setopt (curl .USERPWD , '%s:%s' % (username , password ))
125
-
126
131
curl .setopt (curl .TIMEOUT , timeout )
127
132
curl .perform ()
128
133
@@ -143,7 +148,7 @@ def _requests_post(self, url,
143
148
username = "" ,
144
149
password = "" ,
145
150
xapikey = "" ,
146
- headers = None ,
151
+ headers = {} ,
147
152
timeout = 30 ):
148
153
"""This function will POST to the url endpoint using requests.
149
154
Returning an AdyenResult object on 200 HTTP response.
@@ -160,6 +165,8 @@ def _requests_post(self, url,
160
165
as part of password.
161
166
password (str, optional): Password for basic auth. Must be included
162
167
as part of username.
168
+ xapikey (str, optional): Adyen API key. Will be used for auth
169
+ if username and password are absent.
163
170
headers (dict, optional): Key/Value pairs of headers to include
164
171
timeout (int, optional): Default 30. Timeout for the request.
165
172
@@ -169,8 +176,6 @@ def _requests_post(self, url,
169
176
int: HTTP status code, eg 200,404,401
170
177
dict: Key/Value pairs of the headers received.
171
178
"""
172
- if headers is None :
173
- headers = {}
174
179
175
180
# Adding basic auth if username and password provided.
176
181
auth = None
@@ -194,11 +199,12 @@ def _requests_post(self, url,
194
199
return request .text , message , request .status_code , request .headers
195
200
196
201
def _urllib_post (self , url ,
197
- json = "" ,
198
- data = "" ,
202
+ json = None ,
203
+ data = None ,
199
204
username = "" ,
200
205
password = "" ,
201
- headers = None ,
206
+ xapikey = "" ,
207
+ headers = {},
202
208
timeout = 30 ):
203
209
204
210
"""This function will POST to the url endpoint using urllib2. returning
@@ -216,6 +222,8 @@ def _urllib_post(self, url,
216
222
uncluded as part of password.
217
223
password (str, optional): Password for basic auth. Must be
218
224
included as part of username.
225
+ xapikey (str, optional): Adyen API key. Will be used for auth
226
+ if username and password are absent.
219
227
headers (dict, optional): Key/Value pairs of headers to include
220
228
timeout (int, optional): Default 30. Timeout for the request.
221
229
@@ -225,8 +233,6 @@ def _urllib_post(self, url,
225
233
int: HTTP status code, eg 200,404,401
226
234
dict: Key/Value pairs of the headers received.
227
235
"""
228
- if headers is None :
229
- headers = {}
230
236
231
237
# Store regular dict to return later:
232
238
raw_store = json
@@ -258,6 +264,8 @@ def _urllib_post(self, url,
258
264
replace ('\n ' , '' )
259
265
url_request .add_header ("Authorization" ,
260
266
"Basic %s" % basic_authstring )
267
+ elif xapikey :
268
+ headers ["X-API-KEY" ] = xapikey
261
269
262
270
# Adding the headers to the request.
263
271
for key , value in headers .items ():
@@ -302,6 +310,8 @@ def request(self, url,
302
310
uncluded as part of password.
303
311
password (str, optional): Password for basic auth. Must be
304
312
included as part of username.
313
+ xapikey (str, optional): Adyen API key. Will be used for auth
314
+ if username and password are absent.
305
315
headers (dict, optional): Key/Value pairs of headers to include
306
316
Returns:
307
317
str: Raw request placed
0 commit comments