@@ -60,6 +60,7 @@ def _pycurl_post(self,
6060 data = None ,
6161 username = "" ,
6262 password = "" ,
63+ xapikey = "" ,
6364 headers = {},
6465 timeout = 30 ):
6566 """This function will POST to the url endpoint using pycurl. returning
@@ -77,6 +78,8 @@ def _pycurl_post(self,
7778 as part of password.
7879 password (str, optional): Password for basic auth. Must be included
7980 as part of username.
81+ xapikey (str, optional): Adyen API key. Will be used for auth
82+ if username and password are absent.
8083 headers (dict, optional): Key/Value pairs of headers to include
8184 timeout (int, optional): Default 30. Timeout for the request.
8285
@@ -102,6 +105,11 @@ def _pycurl_post(self,
102105 # request can be identified as coming from the Adyen Python library.
103106 headers ['User-Agent' ] = self .user_agent
104107
108+ if username and password :
109+ curl .setopt (curl .USERPWD , '%s:%s' % (username , password ))
110+ elif xapikey :
111+ headers ["X-API-KEY" ] = xapikey
112+
105113 # Convert the header dict to formatted array as pycurl needs.
106114 if sys .version_info [0 ] >= 3 :
107115 header_list = ["%s:%s" % (k , v ) for k , v in headers .items ()]
@@ -120,9 +128,6 @@ def _pycurl_post(self,
120128 raw_request = json_lib .dumps (json ) if json else urlencode (data )
121129 curl .setopt (curl .POSTFIELDS , raw_request )
122130
123- if username and password :
124- curl .setopt (curl .USERPWD , '%s:%s' % (username , password ))
125-
126131 curl .setopt (curl .TIMEOUT , timeout )
127132 curl .perform ()
128133
@@ -143,7 +148,7 @@ def _requests_post(self, url,
143148 username = "" ,
144149 password = "" ,
145150 xapikey = "" ,
146- headers = None ,
151+ headers = {} ,
147152 timeout = 30 ):
148153 """This function will POST to the url endpoint using requests.
149154 Returning an AdyenResult object on 200 HTTP response.
@@ -160,6 +165,8 @@ def _requests_post(self, url,
160165 as part of password.
161166 password (str, optional): Password for basic auth. Must be included
162167 as part of username.
168+ xapikey (str, optional): Adyen API key. Will be used for auth
169+ if username and password are absent.
163170 headers (dict, optional): Key/Value pairs of headers to include
164171 timeout (int, optional): Default 30. Timeout for the request.
165172
@@ -169,8 +176,6 @@ def _requests_post(self, url,
169176 int: HTTP status code, eg 200,404,401
170177 dict: Key/Value pairs of the headers received.
171178 """
172- if headers is None :
173- headers = {}
174179
175180 # Adding basic auth if username and password provided.
176181 auth = None
@@ -194,11 +199,12 @@ def _requests_post(self, url,
194199 return request .text , message , request .status_code , request .headers
195200
196201 def _urllib_post (self , url ,
197- json = "" ,
198- data = "" ,
202+ json = None ,
203+ data = None ,
199204 username = "" ,
200205 password = "" ,
201- headers = None ,
206+ xapikey = "" ,
207+ headers = {},
202208 timeout = 30 ):
203209
204210 """This function will POST to the url endpoint using urllib2. returning
@@ -216,6 +222,8 @@ def _urllib_post(self, url,
216222 uncluded as part of password.
217223 password (str, optional): Password for basic auth. Must be
218224 included as part of username.
225+ xapikey (str, optional): Adyen API key. Will be used for auth
226+ if username and password are absent.
219227 headers (dict, optional): Key/Value pairs of headers to include
220228 timeout (int, optional): Default 30. Timeout for the request.
221229
@@ -225,8 +233,6 @@ def _urllib_post(self, url,
225233 int: HTTP status code, eg 200,404,401
226234 dict: Key/Value pairs of the headers received.
227235 """
228- if headers is None :
229- headers = {}
230236
231237 # Store regular dict to return later:
232238 raw_store = json
@@ -258,6 +264,8 @@ def _urllib_post(self, url,
258264 replace ('\n ' , '' )
259265 url_request .add_header ("Authorization" ,
260266 "Basic %s" % basic_authstring )
267+ elif xapikey :
268+ headers ["X-API-KEY" ] = xapikey
261269
262270 # Adding the headers to the request.
263271 for key , value in headers .items ():
@@ -302,6 +310,8 @@ def request(self, url,
302310 uncluded as part of password.
303311 password (str, optional): Password for basic auth. Must be
304312 included as part of username.
313+ xapikey (str, optional): Adyen API key. Will be used for auth
314+ if username and password are absent.
305315 headers (dict, optional): Key/Value pairs of headers to include
306316 Returns:
307317 str: Raw request placed
0 commit comments