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

Phase 2 apis integrated #8

Merged
merged 2 commits into from
Nov 8, 2018
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
491 changes: 287 additions & 204 deletions CyberSource/__init__.py

Large diffs are not rendered by default.

38 changes: 28 additions & 10 deletions CyberSource/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,17 @@ def set_configaration(self,config):
mconfig.validate_merchant_details(config, mconfig)

# Calling the authentication header
def call_authentication_header(self, resource_path, method, header_params, body):
def call_authentication_header(self,method, header_params, body):

# give the URL path to where the data needs to be authenticated
url = GlobalLabelParameters.HTTP_URL_PREFIX
time = mconfig.get_time()

time = mconfig.get_time() # mconfig.get_time()

mconfig.request_type_method = method
mconfig.request_target = resource_path

mconfig.url = url + mconfig.request_host + mconfig.request_target
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT:
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT or method.upper() == GlobalLabelParameters.PATCH:
mconfig.request_json_path_data = body

logger = mconfig.log
Expand All @@ -155,7 +154,7 @@ def call_authentication_header(self, resource_path, method, header_params, body)
header_params["Date"] = time
header_params["Host"] = mconfig.request_host
header_params["User-Agent"] = GlobalLabelParameters.USER_AGENT_VALUE
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT:
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))

Expand All @@ -168,7 +167,6 @@ def call_authentication_header(self, resource_path, 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 @@ -178,6 +176,21 @@ def set_digest(self, body):

return encoded_digest

# Adds query param to URL
def set_query_params(self, path, query_param):
query_param = dict(query_param)
if query_param:
first_query_param = True
for param in query_param:

if (not first_query_param):
path = path + "&" + param + "=" + str(query_param[param])
else:
path = path + "?" + param + "=" + str(query_param[param])
first_query_param = False

return path

def __call_api(self, resource_path, method,
path_params=None, query_params=None, header_params=None,
body=None, post_params=None, files=None,
Expand Down Expand Up @@ -254,7 +267,7 @@ def __call_api(self, resource_path, method,
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 (return_data, response_data.status, response_data.data)
else:
return (return_data, response_data.status, response_data.getheaders())

Expand Down Expand Up @@ -370,10 +383,15 @@ def call_api(self, resource_path, method,
response_type=None, auth_settings=None, callback=None,
_return_http_data_only=None, collection_formats=None, _preload_content=True,
_request_timeout=None):
if method.upper() == GlobalLabelParameters.POST:
if method.upper() == GlobalLabelParameters.POST or method.upper() == GlobalLabelParameters.PUT or method.upper() == GlobalLabelParameters.PATCH:
request_body = self.replace_underscore(json.loads(body))
body = json.dumps(request_body)
self.call_authentication_header(resource_path, method, header_params, body)
query_param_path = self.set_query_params(resource_path, query_params)
if query_param_path:
mconfig.request_target = query_param_path
else:
mconfig.request_target = resource_path
self.call_authentication_header(method, header_params, body)
"""
Makes the HTTP request (synchronous) and return the deserialized data.
To make an async request, define a function for callback.
Expand Down
21 changes: 17 additions & 4 deletions CyberSource/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@
# import apis into api package
from .capture_api import CaptureApi
from .credit_api import CreditApi
from .default_api import DefaultApi
from .flex_token_api import FlexTokenApi
from .instrument_identifier_api import InstrumentIdentifierApi
from .instrument_identifiers_api import InstrumentIdentifiersApi
from .key_generation_api import KeyGenerationApi
from .payment_api import PaymentApi
from .payment_instrument_api import PaymentInstrumentApi
from .notification_of_changes_api import NotificationOfChangesApi
from .payment_instruments_api import PaymentInstrumentsApi
from .payments_api import PaymentsApi
from .process_a_payout_api import ProcessAPayoutApi
from .purchase_and_refund_details_api import PurchaseAndRefundDetailsApi
from .refund_api import RefundApi
from .report_definitions_api import ReportDefinitionsApi
from .report_downloads_api import ReportDownloadsApi
from .report_subscriptions_api import ReportSubscriptionsApi
from .reports_api import ReportsApi
from .reversal_api import ReversalApi
from .tokenization_api import TokenizationApi
from .search_transactions_api import SearchTransactionsApi
from .secure_file_share_api import SecureFileShareApi
from .transaction_batch_api import TransactionBatchApi
from .transaction_batches_api import TransactionBatchesApi
from .transaction_details_api import TransactionDetailsApi
from .user_management_api import UserManagementApi
from .void_api import VoidApi
108 changes: 3 additions & 105 deletions CyberSource/apis/capture_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def capture_payment(self, capture_payment_request, id, **kwargs):
for asynchronous request. (optional)
:param CapturePaymentRequest capture_payment_request: (required)
:param str id: The payment ID returned from a previous payment request. This ID links the capture to the payment. (required)
:return: InlineResponse2012
:return: PtsV2PaymentsCapturesPost201Response
If the method is called asynchronously,
returns the request thread.
"""
Expand All @@ -85,7 +85,7 @@ def capture_payment_with_http_info(self, capture_payment_request, id, **kwargs):
for asynchronous request. (optional)
:param CapturePaymentRequest capture_payment_request: (required)
:param str id: The payment ID returned from a previous payment request. This ID links the capture to the payment. (required)
:return: InlineResponse2012
:return: PtsV2PaymentsCapturesPost201Response
If the method is called asynchronously,
returns the request thread.
"""
Expand Down Expand Up @@ -147,109 +147,7 @@ def capture_payment_with_http_info(self, capture_payment_request, id, **kwargs):
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='InlineResponse2012',
auth_settings=auth_settings,
callback=params.get('callback'),
_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)

def get_capture(self, id, **kwargs):
"""
Retrieve a Capture
Include the capture ID in the GET request to retrieve the capture details.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the response.
>>> def callback_function(response):
>>> pprint(response)
>>>
>>> thread = api.get_capture(id, callback=callback_function)

:param callback function: The callback function
for asynchronous request. (optional)
:param str id: The capture ID returned from a previous capture request. (required)
:return: InlineResponse2004
If the method is called asynchronously,
returns the request thread.
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('callback'):
return self.get_capture_with_http_info(id, **kwargs)
else:
(data) = self.get_capture_with_http_info(id, **kwargs)
return data

def get_capture_with_http_info(self, id, **kwargs):
"""
Retrieve a Capture
Include the capture ID in the GET request to retrieve the capture details.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the response.
>>> def callback_function(response):
>>> pprint(response)
>>>
>>> thread = api.get_capture_with_http_info(id, callback=callback_function)

:param callback function: The callback function
for asynchronous request. (optional)
:param str id: The capture ID returned from a previous capture request. (required)
:return: InlineResponse2004
If the method is called asynchronously,
returns the request thread.
"""

all_params = ['id']
all_params.append('callback')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')

params = locals()
for key, val in iteritems(params['kwargs']):
if key not in all_params:
raise TypeError(
"Got an unexpected keyword argument '%s'"
" to method get_capture" % key
)
params[key] = val
del params['kwargs']
# verify the required parameter 'id' is set
if ('id' not in params) or (params['id'] is None):
raise ValueError("Missing the required parameter `id` when calling `get_capture`")


collection_formats = {}

path_params = {}
if 'id' in params:
path_params['id'] = params['id']

query_params = []

header_params = {}

form_params = []
local_var_files = {}

body_params = None
# HTTP header `Accept`
header_params['Accept'] = self.api_client.\
select_header_accept(['application/json'])

# Authentication setting
auth_settings = []

return self.api_client.call_api('/v2/captures/{id}', 'GET',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='InlineResponse2004',
response_type='PtsV2PaymentsCapturesPost201Response',
auth_settings=auth_settings,
callback=params.get('callback'),
_return_http_data_only=params.get('_return_http_data_only'),
Expand Down
108 changes: 3 additions & 105 deletions CyberSource/apis/credit_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create_credit(self, create_credit_request, **kwargs):
:param callback function: The callback function
for asynchronous request. (optional)
:param CreateCreditRequest create_credit_request: (required)
:return: InlineResponse2014
:return: PtsV2CreditsPost201Response
If the method is called asynchronously,
returns the request thread.
"""
Expand All @@ -83,7 +83,7 @@ def create_credit_with_http_info(self, create_credit_request, **kwargs):
:param callback function: The callback function
for asynchronous request. (optional)
:param CreateCreditRequest create_credit_request: (required)
:return: InlineResponse2014
:return: PtsV2CreditsPost201Response
If the method is called asynchronously,
returns the request thread.
"""
Expand Down Expand Up @@ -140,109 +140,7 @@ def create_credit_with_http_info(self, create_credit_request, **kwargs):
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='InlineResponse2014',
auth_settings=auth_settings,
callback=params.get('callback'),
_return_http_data_only=params.get('_return_http_data_only'),
_preload_content=params.get('_preload_content', True),
_request_timeout=params.get('_request_timeout'),
collection_formats=collection_formats)

def get_credit(self, id, **kwargs):
"""
Retrieve a Credit
Include the credit ID in the GET request to return details of the credit.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the response.
>>> def callback_function(response):
>>> pprint(response)
>>>
>>> thread = api.get_credit(id, callback=callback_function)

:param callback function: The callback function
for asynchronous request. (optional)
:param str id: The credit ID returned from a previous stand-alone credit request. (required)
:return: InlineResponse2006
If the method is called asynchronously,
returns the request thread.
"""
kwargs['_return_http_data_only'] = True
if kwargs.get('callback'):
return self.get_credit_with_http_info(id, **kwargs)
else:
(data) = self.get_credit_with_http_info(id, **kwargs)
return data

def get_credit_with_http_info(self, id, **kwargs):
"""
Retrieve a Credit
Include the credit ID in the GET request to return details of the credit.
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please define a `callback` function
to be invoked when receiving the response.
>>> def callback_function(response):
>>> pprint(response)
>>>
>>> thread = api.get_credit_with_http_info(id, callback=callback_function)

:param callback function: The callback function
for asynchronous request. (optional)
:param str id: The credit ID returned from a previous stand-alone credit request. (required)
:return: InlineResponse2006
If the method is called asynchronously,
returns the request thread.
"""

all_params = ['id']
all_params.append('callback')
all_params.append('_return_http_data_only')
all_params.append('_preload_content')
all_params.append('_request_timeout')

params = locals()
for key, val in iteritems(params['kwargs']):
if key not in all_params:
raise TypeError(
"Got an unexpected keyword argument '%s'"
" to method get_credit" % key
)
params[key] = val
del params['kwargs']
# verify the required parameter 'id' is set
if ('id' not in params) or (params['id'] is None):
raise ValueError("Missing the required parameter `id` when calling `get_credit`")


collection_formats = {}

path_params = {}
if 'id' in params:
path_params['id'] = params['id']

query_params = []

header_params = {}

form_params = []
local_var_files = {}

body_params = None
# HTTP header `Accept`
header_params['Accept'] = self.api_client.\
select_header_accept(['application/json'])

# Authentication setting
auth_settings = []

return self.api_client.call_api('/v2/credits/{id}', 'GET',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='InlineResponse2006',
response_type='PtsV2CreditsPost201Response',
auth_settings=auth_settings,
callback=params.get('callback'),
_return_http_data_only=params.get('_return_http_data_only'),
Expand Down
Loading