Skip to content

Commit ac57fc7

Browse files
authoredNov 8, 2018
Merge pull request #8 from CyberSource/cybersource-python-development
Phase 2 apis integrated
2 parents 92d3d47 + 473c12c commit ac57fc7

File tree

1,542 files changed

+85714
-62908
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,542 files changed

+85714
-62908
lines changed
 

‎CyberSource/__init__.py

+287-204
Large diffs are not rendered by default.

‎CyberSource/api_client.py

+28-10
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,17 @@ def set_configaration(self,config):
131131
mconfig.validate_merchant_details(config, mconfig)
132132

133133
# Calling the authentication header
134-
def call_authentication_header(self, resource_path, method, header_params, body):
134+
def call_authentication_header(self,method, header_params, body):
135135

136136
# give the URL path to where the data needs to be authenticated
137137
url = GlobalLabelParameters.HTTP_URL_PREFIX
138-
139-
time = mconfig.get_time()
138+
139+
time = mconfig.get_time() # mconfig.get_time()
140140

141141
mconfig.request_type_method = method
142-
mconfig.request_target = resource_path
143142

144143
mconfig.url = url + mconfig.request_host + mconfig.request_target
145-
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT:
144+
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT or method.upper() == GlobalLabelParameters.PATCH:
146145
mconfig.request_json_path_data = body
147146

148147
logger = mconfig.log
@@ -155,7 +154,7 @@ def call_authentication_header(self, resource_path, method, header_params, body)
155154
header_params["Date"] = time
156155
header_params["Host"] = mconfig.request_host
157156
header_params["User-Agent"] = GlobalLabelParameters.USER_AGENT_VALUE
158-
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT:
157+
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT or method.upper() == GlobalLabelParameters.PATCH:
159158
'''print((ast.literal_eval(json.dumps(self.del_none(json.loads(body))))))'''
160159
digest_header = self.set_digest((body))
161160

@@ -168,7 +167,6 @@ def call_authentication_header(self, resource_path, method, header_params, body)
168167
token = "Bearer " + token.decode("utf-8")
169168
header_params['Authorization'] = str(token)
170169

171-
172170
# Set the digest
173171
def set_digest(self, body):
174172
digest_obj = DigestAndPayload()
@@ -178,6 +176,21 @@ def set_digest(self, body):
178176

179177
return encoded_digest
180178

179+
# Adds query param to URL
180+
def set_query_params(self, path, query_param):
181+
query_param = dict(query_param)
182+
if query_param:
183+
first_query_param = True
184+
for param in query_param:
185+
186+
if (not first_query_param):
187+
path = path + "&" + param + "=" + str(query_param[param])
188+
else:
189+
path = path + "?" + param + "=" + str(query_param[param])
190+
first_query_param = False
191+
192+
return path
193+
181194
def __call_api(self, resource_path, method,
182195
path_params=None, query_params=None, header_params=None,
183196
body=None, post_params=None, files=None,
@@ -254,7 +267,7 @@ def __call_api(self, resource_path, method,
254267
else:
255268
callback((return_data, response_data.status, response_data.getheaders()))
256269
elif _return_http_data_only:
257-
return (return_data,response_data.status, response_data.data)
270+
return (return_data, response_data.status, response_data.data)
258271
else:
259272
return (return_data, response_data.status, response_data.getheaders())
260273

@@ -370,10 +383,15 @@ def call_api(self, resource_path, method,
370383
response_type=None, auth_settings=None, callback=None,
371384
_return_http_data_only=None, collection_formats=None, _preload_content=True,
372385
_request_timeout=None):
373-
if method.upper() == GlobalLabelParameters.POST:
386+
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT or method.upper() == GlobalLabelParameters.PATCH:
374387
request_body = self.replace_underscore(json.loads(body))
375388
body = json.dumps(request_body)
376-
self.call_authentication_header(resource_path, method, header_params, body)
389+
query_param_path = self.set_query_params(resource_path, query_params)
390+
if query_param_path:
391+
mconfig.request_target = query_param_path
392+
else:
393+
mconfig.request_target = resource_path
394+
self.call_authentication_header(method, header_params, body)
377395
"""
378396
Makes the HTTP request (synchronous) and return the deserialized data.
379397
To make an async request, define a function for callback.

0 commit comments

Comments
 (0)
Please sign in to comment.