Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC implementation done #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 70 additions & 9 deletions CyberSource/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ def __init__(self, host=None, header_name=None, header_value=None, cookie=None):
"""
self.rest_client = RESTClientObject()
self.default_headers = {}
self.request_headers={}
#self.request_body={}

if header_name is not None:
self.default_headers[header_name] = header_value
if host is None:


if host is None:
self.host = Configuration().host
else:
self.host = host
Expand All @@ -94,8 +98,12 @@ def user_agent(self, value):
"""
self.default_headers['User-Agent'] = value




def set_default_header(self, header_name, header_value):
self.default_headers[header_name] = header_value


# replace the underscore
def replace_underscore(self, d):
Expand Down Expand Up @@ -141,8 +149,8 @@ def call_authentication_header(self,method, header_params, body):
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT or method.upper() == GlobalLabelParameters.PATCH:
mconfig.request_json_path_data = body

logger = mconfig.log

logger = MyLogger.__call__(mconfig).get_logger()
Configuration().merchantconfig=mconfig
auth = Authorization()
token = auth.get_token(mconfig, mconfig.get_time(), logger)
if mconfig.authentication_type.upper() == GlobalLabelParameters.HTTP.upper():
Expand All @@ -152,7 +160,7 @@ def call_authentication_header(self,method, header_params, body):
header_params["Host"] = mconfig.request_host
header_params["User-Agent"] = GlobalLabelParameters.USER_AGENT_VALUE
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT or method.upper() == GlobalLabelParameters.PATCH:
'''print((ast.literal_eval(json.dumps(self.del_none(json.loads(body))))))'''

digest_header = self.set_digest((body))

header_params[
Expand All @@ -164,6 +172,7 @@ def call_authentication_header(self,method, header_params, body):
token = "Bearer " + token.decode("utf-8")
header_params['Authorization'] = str(token)


# Set the digest
def set_digest(self, body):
digest_obj = DigestAndPayload()
Expand All @@ -180,6 +189,36 @@ def set_query_params(self, path, query_param):

return path

# This method reads the items to be masked and accordingly masks the response from the server
def masking(self,unmasked_data):
try:
unmasked_data_dict = json.loads(unmasked_data)
maskdata = json.dumps(
self.remove_key(unmasked_data_dict, "expirationMonth", "expirationYear", "email", "firstName", "lastName", "phoneNumber",
"number", "securityCode", "type"))


return maskdata
except Exception :
return unmasked_data


# This function replaces the value of the items to be masked to "XXXXX"
def remove_key(self,obj, *keys):
if type(obj) is dict:
for key, value in list(obj.items()):
if key not in keys:
obj[key] = self.remove_key(value, *keys)
obj[key] = value
else:
obj[key] = GlobalLabelParameters.MASKING_VALUE
elif type(obj) is list:
for i in range(len(obj)):
obj[i] = self.remove_key(obj[i],*keys)


return obj

def __call_api(self, resource_path, method,
path_params=None, query_params=None, header_params=None,
body=None, post_params=None, files=None,
Expand All @@ -191,7 +230,10 @@ def __call_api(self, resource_path, method,

# header parameters
header_params = header_params or {}
header_params.update(self.default_headers)
#header_params.update(self.default_headers)
# sankalp
self.request_headers.update(header_params)
#self.request_body.update(body)
if self.cookie:
header_params['Cookie'] = self.cookie
if header_params:
Expand Down Expand Up @@ -231,8 +273,6 @@ def __call_api(self, resource_path, method,

# request url
url = GlobalLabelParameters.HTTP_URL_PREFIX+self.host + resource_path


# perform request and return response
response_data = self.request(method, url,
query_params=query_params,
Expand All @@ -242,22 +282,39 @@ def __call_api(self, resource_path, method,
_request_timeout=_request_timeout)

self.last_response = response_data

return_data = response_data


if _preload_content:
# deserialize response data
if response_type:
return_data = self.deserialize(response_data, response_type)

else:
return_data = None
# Calling the masking logic
if response_data.data:
mask_values = self.masking(response_data.data)
response_data.data = mask_values
# Logging the details
'''if mconfig.enable_log is True:
self.logger.info("User Agent : "+(self.request_headers["User-Agent"]))
if body:
self.logger.info("Request Body : "+body)
self.logger.info("Request Headers : " + str(self.request_headers))
self.logger.info("Response Code : " + str(response_data.status))
self.logger.info("Response Message : "+response_data.data)
self.logger.info("Response Headers : "+str(response_data.getheaders()))
self.logger.info("END> =======================================")'''


if callback:
if _return_http_data_only:
callback(return_data)
else:
callback((return_data, response_data.status, response_data.getheaders()))
elif _return_http_data_only:
return (return_data, response_data.status, response_data.data)
return (response_data)
else:
return (return_data, response_data.status, response_data.getheaders())

Expand Down Expand Up @@ -367,6 +424,7 @@ def __deserialize(self, data, klass):
else:
return self.__deserialize_model(data, klass)


def call_api(self, resource_path, method,
path_params=None, query_params=None, header_params=None,
body=None, post_params=None, files=None,
Expand All @@ -377,6 +435,7 @@ def call_api(self, resource_path, method,
request_body = self.replace_underscore(json.loads(body))
body = json.dumps(request_body)
query_param_path = self.set_query_params(resource_path, query_params)

if query_param_path:
mconfig.request_target = query_param_path
else:
Expand Down Expand Up @@ -416,6 +475,7 @@ def call_api(self, resource_path, method,
If parameter callback is None,
then the method will return the response directly.
"""

if callback is None:
return self.__call_api(resource_path, method,
path_params, query_params, header_params,
Expand All @@ -431,6 +491,7 @@ def call_api(self, resource_path, method,
response_type, auth_settings,
callback, _return_http_data_only,
collection_formats, _preload_content, _request_timeout))

thread.start()
return thread

Expand Down
14 changes: 13 additions & 1 deletion CyberSource/apis/instrument_identifier_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from ..configuration import Configuration
from ..api_client import ApiClient

import json

class InstrumentIdentifierApi(object):
"""
Expand Down Expand Up @@ -391,6 +391,9 @@ def tms_v1_instrumentidentifiers_token_id_patch_with_http_info(self, profile_id,
# Authentication setting
auth_settings = []

# Check to delete null values in Input request json
body_params= json.dumps(self.del_none(json.loads(body_params)))

return self.api_client.call_api('/tms/v1/instrumentidentifiers/'+token_id, 'PATCH',
path_params,
query_params,
Expand All @@ -405,3 +408,12 @@ def tms_v1_instrumentidentifiers_token_id_patch_with_http_info(self, profile_id,
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)

# To delete None values in Input Request Json body(This code needs to be added through mustache changes)
def del_none(self,body):
for key, value in list(body.items()):
if value is None:
del body[key]
elif isinstance(value, dict):
self.del_none(value)
return body
13 changes: 12 additions & 1 deletion CyberSource/apis/instrument_identifiers_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from ..configuration import Configuration
from ..api_client import ApiClient

import json

class InstrumentIdentifiersApi(object):
"""
Expand Down Expand Up @@ -141,6 +141,8 @@ def tms_v1_instrumentidentifiers_post_with_http_info(self, profile_id, body, **k

# Authentication setting
auth_settings = []
# Check to delete null values in Input request json
body_params = json.dumps(self.del_none(json.loads(body_params)))

return self.api_client.call_api('/tms/v1/instrumentidentifiers', 'POST',
path_params,
Expand All @@ -156,3 +158,12 @@ def tms_v1_instrumentidentifiers_post_with_http_info(self, profile_id, body, **k
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)

# To delete None values in Input Request Json body(This code needs to be added through mustache changes)
def del_none(self, body):
for key, value in list(body.items()):
if value is None:
del body[key]
elif isinstance(value, dict):
self.del_none(value)
return body
6 changes: 3 additions & 3 deletions CyberSource/apis/notification_of_changes_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ def get_notification_of_change_report_with_http_info(self, start_time, end_time,
path_params = {}

query_params = []
'''if 'start_time' in params:
if 'start_time' in params:
query_params.append(('startTime', params['start_time']))
if 'end_time' in params:
query_params.append(('endTime', params['end_time']))'''
query_params.append(('endTime', params['end_time']))

header_params = {}

Expand All @@ -140,7 +140,7 @@ def get_notification_of_change_report_with_http_info(self, start_time, end_time,
# Authentication setting
auth_settings = []

return self.api_client.call_api('/reporting/v3/notification-of-changes?startTime='+start_time+'&endTime='+end_time, 'GET',
return self.api_client.call_api('/reporting/v3/notification-of-changes', 'GET',
path_params,
query_params,
header_params,
Expand Down
13 changes: 13 additions & 0 deletions CyberSource/apis/payment_instruments_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from ..configuration import Configuration
from ..api_client import ApiClient
import json


class PaymentInstrumentsApi(object):
Expand Down Expand Up @@ -274,6 +275,8 @@ def tms_v1_paymentinstruments_post_with_http_info(self, profile_id, body, **kwar

# Authentication setting
auth_settings = []
# Check to delete null values in Input request json
body_params = json.dumps(self.del_none(json.loads(body_params)))

return self.api_client.call_api('/tms/v1/paymentinstruments', 'POST',
path_params,
Expand Down Expand Up @@ -638,6 +641,8 @@ def tms_v1_paymentinstruments_token_id_patch_with_http_info(self, profile_id, to

# Authentication setting
auth_settings = []
# Check to delete null values in Input request json
body_params = json.dumps(self.del_none(json.loads(body_params)))

return self.api_client.call_api('/tms/v1/paymentinstruments/'+token_id, 'PATCH',
path_params,
Expand All @@ -653,3 +658,11 @@ def tms_v1_paymentinstruments_token_id_patch_with_http_info(self, profile_id, to
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)
# To delete None values in Input Request Json body(This code needs to be added through mustache changes)
def del_none(self,body):
for key, value in list(body.items()):
if value is None:
del body[key]
elif isinstance(value, dict):
self.del_none(value)
return body
2 changes: 2 additions & 0 deletions CyberSource/apis/payments_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, merchant_config, api_client=None):
if api_client:
self.api_client = api_client
else:

if not config.api_client:
config.api_client = ApiClient()
self.api_client = config.api_client
Expand Down Expand Up @@ -66,6 +67,7 @@ def create_payment(self, create_payment_request, **kwargs):
return self.create_payment_with_http_info(create_payment_request, **kwargs)
else:
(data) = self.create_payment_with_http_info(create_payment_request, **kwargs)

return data

def create_payment_with_http_info(self, create_payment_request, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions CyberSource/apis/purchase_and_refund_details_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def get_purchase_and_refund_details_with_http_info(self, start_time, end_time, *
path_params = {}

query_params = []
'''if 'start_time' in params:
if 'start_time' in params:
query_params.append(('startTime', params['start_time']))
if 'end_time' in params:
query_params.append(('endTime', params['end_time']))'''
query_params.append(('endTime', params['end_time']))
if 'organization_id' in params:
query_params.append(('organizationId', params['organization_id']))
if 'payment_subtype' in params:
Expand Down Expand Up @@ -174,7 +174,7 @@ def get_purchase_and_refund_details_with_http_info(self, start_time, end_time, *
# Authentication setting
auth_settings = []

return self.api_client.call_api('/reporting/v3/purchase-refund-details?startTime='+start_time+'&endTime='+end_time, 'GET',
return self.api_client.call_api('/reporting/v3/purchase-refund-details', 'GET',
path_params,
query_params,
header_params,
Expand Down
4 changes: 2 additions & 2 deletions CyberSource/apis/report_subscriptions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def create_subscription_with_http_info(self,request_body, **kwargs):
params[key] = val
del params['kwargs']
# verify the required parameter 'report_name' is set
#if ('report_name' not in params) or (params['report_name'] is None):
#raise ValueError("Missing the required parameter `report_name` when calling `create_subscription`")
if ('report_name' not in params) or (params['report_name'] is None):
raise ValueError("Missing the required parameter `report_name` when calling `create_subscription`")
# verify the required parameter 'request_body' is set
if ('request_body' not in params) or (params['request_body'] is None):
raise ValueError("Missing the required parameter `request_body` when calling `create_subscription`")
Expand Down
6 changes: 3 additions & 3 deletions CyberSource/apis/reports_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,12 @@ def search_reports_with_http_info(self, start_time, end_time, time_query_type, *
query_params = []
if 'organization_id' in params:
query_params.append(('organizationId', params['organization_id']))
'''if 'start_time' in params:
if 'start_time' in params:
query_params.append(('startTime', params['start_time']))
if 'end_time' in params:
query_params.append(('endTime', params['end_time']))
if 'time_query_type' in params:
query_params.append(('timeQueryType', params['time_query_type']))'''
query_params.append(('timeQueryType', params['time_query_type']))
if 'report_mime_type' in params:
query_params.append(('reportMimeType', params['report_mime_type']))
if 'report_frequency' in params:
Expand Down Expand Up @@ -399,7 +399,7 @@ def search_reports_with_http_info(self, start_time, end_time, time_query_type, *
# Authentication setting
auth_settings = []

return self.api_client.call_api('/reporting/v3/reports?startTime='+start_time+'&endTime='+end_time+'&timeQueryType='+time_query_type, 'GET',
return self.api_client.call_api('/reporting/v3/reports', 'GET',
path_params,
query_params,
header_params,
Expand Down
Loading