From f2e9c902f2a4f2d3aa2ac14ad7e48897ae540aab Mon Sep 17 00:00:00 2001 From: Jagaraganti Date: Tue, 19 Feb 2019 16:45:19 +0530 Subject: [PATCH] POC implemented code --- ...onfiguration.py => input_configuration.py} | 16 +++++++- samples/flex/coreservices/generate_key.py | 30 ++++++++++---- samples/flex/coreservices/tokenize_card.py | 32 +++++++++++---- samples/flex/flex_signature_verification.py | 4 +- samples/flex/keygeneration_noenc.py | 31 ++++++++++---- samples/flex/rsa_verify.py | 9 ++-- .../payments/coreservices/capture_payment.py | 31 ++++++++++---- .../process_authorization_reversal.py | 27 ++++++++---- .../payments/coreservices/process_credit.py | 28 +++++++++---- .../payments/coreservices/process_payment.py | 32 +++++++++++---- .../payments/coreservices/refund_capture.py | 27 ++++++++---- .../payments/coreservices/refund_payment.py | 29 +++++++++---- samples/payments/coreservices/void_capture.py | 27 ++++++++---- samples/payments/coreservices/void_credit.py | 27 ++++++++---- samples/payments/coreservices/void_payment.py | 27 ++++++++---- samples/payments/coreservices/void_refund.py | 27 ++++++++---- .../payouts/coreservices/process_payout.py | 25 ++++++++--- .../coreservices/create_adhoc_report.py | 27 ++++++++---- ...ription_for_report_name_by_organization.py | 39 ++++++++++++------ ...cription_of_report_name_by_organization.py | 24 +++++++---- .../reporting/coreservices/download_report.py | 27 ++++++++---- .../coreservices/get_all_subscriptions.py | 22 +++++++--- .../get_notification_of_changes.py | 26 ++++++++---- .../get_purchase_and_refund_details.py | 22 +++++++--- .../get_report_based_on_reportid.py | 22 +++++++--- .../coreservices/get_report_definition.py | 22 +++++++--- .../get_reporting_resource_information.py | 22 +++++++--- .../get_subscription_for_report_name.py | 22 +++++++--- .../retrieve_available_reports.py | 22 +++++++--- .../download_file_with_file_identifier.py | 25 +++++++---- .../coreservices/get_list_of_files.py | 24 ++++++++--- .../create_instrument_identifier.py | 41 +++++++++++-------- .../coreservices/create_payment_instrument.py | 39 ++++++++++-------- .../delete_instrument_identifier.py | 24 +++++++---- .../coreservices/delete_payment_instrument.py | 24 +++++++---- .../retrieve_all_payment_instruments.py | 25 +++++++---- .../retrieve_instrument_identifier.py | 27 ++++++++---- .../retrieve_payment_instrument.py | 27 ++++++++---- .../update_instrument_identifier.py | 41 +++++++++++-------- .../coreservices/update_payment_instrument.py | 40 ++++++++++-------- .../coreservices/get_individual_batch_file.py | 22 +++++++--- .../coreservices/get_list_of_batch_files.py | 22 +++++++--- .../coreservices/retrieve_transaction.py | 22 +++++++--- .../coreservices/create_search_request.py | 26 ++++++++---- .../coreservices/get_search_results.py | 24 +++++++---- .../coreservices/get_user_information.py | 22 +++++++--- 46 files changed, 840 insertions(+), 361 deletions(-) rename data/{Configuration.py => input_configuration.py} (80%) diff --git a/data/Configuration.py b/data/input_configuration.py similarity index 80% rename from data/Configuration.py rename to data/input_configuration.py index cd9eb5a..8e19dd2 100644 --- a/data/Configuration.py +++ b/data/input_configuration.py @@ -1,7 +1,7 @@ import os +from CyberSource.configuration import Configuration - -class Configuration: +class InputConfiguration: def __init__(self): self.authentication_type ="http_signature" self.merchantid = "testrest" @@ -46,4 +46,16 @@ def get_configuration(self): configuration_dictionary["log_directory"] = self.log_directory #configuration_dictionary["proxy_address"] = self.proxy_address #configuration_dictionary["proxy_port"] = self.proxy_port + #self.set_config() return configuration_dictionary + + '''def set_config(self): + #logger_file = self.log_directory + config = Configuration() + # config_logger.proxy = True + # http = urllib3.ProxyManager('https://userproxy.visa.com:443', maxsize=1) + # config.proxy = 'http://userproxy.visa.com:80' + config.debug = self.enable_log + #config.logger_file = logger_file + # config_logger.logger_file_handler = 'Logs' + # config_logger.logger_stream_handler = sys.stdout''' diff --git a/samples/flex/coreservices/generate_key.py b/samples/flex/coreservices/generate_key.py index fcce6eb..8bbfaea 100644 --- a/samples/flex/coreservices/generate_key.py +++ b/samples/flex/coreservices/generate_key.py @@ -1,27 +1,41 @@ from CyberSource import * import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def generate_key(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() key_generation_obj = KeyGenerationApi(details_dict1) # Setting the json message body - key_generation = GeneratePublicKeyRequest() - key_generation.encryption_type = "RsaOaep256" + key_generation = GeneratePublicKeyRequest(encryption_type="RsaOaep256") + #key_generation.encryption_type = "RsaOaep256" message_body = json.dumps(key_generation.__dict__) - return_data, status, body = key_generation_obj.generate_public_key(generate_public_key_request=message_body) - print("API RESPONSE CODE : ",status) - print("API RESPONSE BODY : ",body) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = key_generation_obj.generate_public_key(generate_public_key_request=message_body) + # Calling api_client variable in Configuration file to access the request_headers + request_headers = config.api_client.request_headers + + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling KeyGenerationApi->generate_public_key: %s\n" % e) + print("\nException when calling KeyGenerationApi->generate_public_key: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/flex/coreservices/tokenize_card.py b/samples/flex/coreservices/tokenize_card.py index 5c0de49..0f4af85 100644 --- a/samples/flex/coreservices/tokenize_card.py +++ b/samples/flex/coreservices/tokenize_card.py @@ -1,9 +1,10 @@ from CyberSource import * import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() # Following code is to handle the Sibling Package Import @@ -14,16 +15,18 @@ path.append(dir(path[0])) __package__ = "coreservices" import keygeneration_noenc +import flex_signature_verification def tokenize_card(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Setting the json message body tokenize_card = TokenizeRequest() card_info = Flexv1tokensCardInfo() # Getting the key_id dynamically api_response = keygeneration_noenc.keygeneration_noenc() - tokenize_card.key_id = api_response.key_id + tokenize_card.key_id = api_response['keyId'] card_info.card_expiration_year = "2031" card_info.card_number = "5555555555554444" @@ -32,15 +35,28 @@ def tokenize_card(): tokenize_card.card_info = card_info.__dict__ message_body = json.dumps(tokenize_card.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() tokenize_obj = FlexTokenApi(details_dict1) - return_data, status, body = tokenize_obj.tokenize(tokenize_request=message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = tokenize_obj.tokenize(tokenize_request=message_body) + # Calling api_client variable in Configuration file to access the request_headers + request_headers = config.api_client.request_headers + + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) + + flex_signature_verification.verify(api_response['der']['publicKey'],json.loads(response_data.data)) except Exception as e: - print("Exception when calling FlexTokenApi->tokenize: %s\n" % e) + print("\nException when calling FlexTokenApi->tokenize: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/flex/flex_signature_verification.py b/samples/flex/flex_signature_verification.py index 34da25a..adc5c0e 100644 --- a/samples/flex/flex_signature_verification.py +++ b/samples/flex/flex_signature_verification.py @@ -15,11 +15,13 @@ def verify(key, postparams): raise Flex_Security_Exception("Missing required field: signedFields") signed_field = (signed_fields.split(",")) - for i in signed_field: signed_list.append(",") signed_list.append(str(postparams.get("" + i))) + signed_string = "".join(signed_list) signed_string = signed_string[1:] + + print("Flex Signature Verification: ",rsa_verify.verify_sign(key, signature, signed_string)) diff --git a/samples/flex/keygeneration_noenc.py b/samples/flex/keygeneration_noenc.py index 7b30998..32853d1 100644 --- a/samples/flex/keygeneration_noenc.py +++ b/samples/flex/keygeneration_noenc.py @@ -1,30 +1,43 @@ from CyberSource import * import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def keygeneration_noenc(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() key_generation_obj = KeyGenerationApi(details_dict1) # Setting the json message body - key_generation = GeneratePublicKeyRequest() - key_generation.encryption_type = "None" + key_generation = GeneratePublicKeyRequest(encryption_type='None') + #key_generation.encryption_type = "None" message_body = json.dumps(key_generation.__dict__) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = key_generation_obj.generate_public_key(generate_public_key_request=message_body) + # Calling api_client variable in Configuration file to access the request_headers + request_headers = config.api_client.request_headers - return_data, status, body = key_generation_obj.generate_public_key(generate_public_key_request=message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - return return_data + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) + return json.loads(response_data.data) except Exception as e: - print("Exception when calling KeyGenerationApi->generate_public_key: %s\n" % e) + print("\nException when calling KeyGenerationApi->generate_public_key: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/flex/rsa_verify.py b/samples/flex/rsa_verify.py index 216b2da..8ac8e16 100644 --- a/samples/flex/rsa_verify.py +++ b/samples/flex/rsa_verify.py @@ -4,6 +4,7 @@ from base64 import b64decode + def verify_sign(public_key_loc, signature, data): """ Verifies with a public key from whom the data came that it was indeed @@ -12,15 +13,15 @@ def verify_sign(public_key_loc, signature, data): param: signature String signature to be verified return: Boolean. True if the signature is valid; False otherwise. """ - pub_key = "-----BEGIN PUBLIC KEY-----\n" + public_key_loc + "\n-----END PUBLIC KEY-----" + pub_key = b64decode(public_key_loc ) rsakey = RSA.importKey(pub_key) signer = PKCS1_v1_5.new(rsakey) digest = SHA512.new() - # Assumes the data is base64 encoded to begin with - digest.update(b64decode(data)) - + digest.update(data.encode('utf-8')) + if signer.verify(digest, b64decode(signature)): return True else: + return False diff --git a/samples/payments/coreservices/capture_payment.py b/samples/payments/coreservices/capture_payment.py index f30fb4e..2dd02e6 100644 --- a/samples/payments/coreservices/capture_payment.py +++ b/samples/payments/coreservices/capture_payment.py @@ -2,18 +2,21 @@ import process_payment import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def capture_a_payment(): + try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the payment_id dynamically using process_a_payment method api_payment_response = process_payment.process_a_payment( False) - payment_id = api_payment_response.id + payment_id = api_payment_response['id'] # Setting the json message body request = CapturePaymentRequest() client_reference = Ptsv2paymentsClientReferenceInformation() @@ -28,16 +31,28 @@ def capture_a_payment(): request.order_information = order_information.__dict__ message_body = (json.dumps(request.__dict__)) + # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() capture_obj = CaptureApi(details_dict1) - return_data, status, body = capture_obj.capture_payment(message_body, payment_id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - return return_data + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = capture_obj.capture_payment(message_body, payment_id) + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) + return json.loads(response_data.data) except Exception as e: - print("Exception when calling CaptureApi->capture_payment: %s\n" % e) + print("\nException when calling CaptureApi->capture_payment: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) + if __name__ == "__main__": diff --git a/samples/payments/coreservices/process_authorization_reversal.py b/samples/payments/coreservices/process_authorization_reversal.py index 92a1fcf..23f3d5f 100644 --- a/samples/payments/coreservices/process_authorization_reversal.py +++ b/samples/payments/coreservices/process_authorization_reversal.py @@ -2,17 +2,19 @@ import process_payment import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def process_an_authorization_reversal(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the payment_id dynamically using process_a_payment method api_payment_response = process_payment.process_a_payment(False) - payment_id = api_payment_response.id + payment_id = api_payment_response['id'] # Setting the json message body request = AuthReversalRequest() client_reference = Ptsv2paymentsClientReferenceInformation() @@ -27,14 +29,25 @@ def process_an_authorization_reversal(): request.reversal_information = reversal_information.__dict__ message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() reversal_obj = ReversalApi(details_dict1) - return_data, status, body = reversal_obj.auth_reversal(payment_id, message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data= reversal_obj.auth_reversal(payment_id, message_body) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling ReversalApi->auth_reversal: %s\n" % e) + print("\nException when calling ReversalApi->auth_reversal: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/payments/coreservices/process_credit.py b/samples/payments/coreservices/process_credit.py index bf46c92..8bcc7e2 100644 --- a/samples/payments/coreservices/process_credit.py +++ b/samples/payments/coreservices/process_credit.py @@ -1,14 +1,16 @@ from CyberSource import * import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def process_a_credit(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Setting the json message body request = CreateCreditRequest() client_reference = Ptsv2paymentsClientReferenceInformation() @@ -42,17 +44,29 @@ def process_a_credit(): request.order_information = order_information.__dict__ request.payment_information = payment_information.__dict__ message_body = json.dumps(request.__dict__) + # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() credit_obj = CreditApi(details_dict1) - return_data, status, body = credit_obj.create_credit(message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - return return_data + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = credit_obj.create_credit(message_body) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) + return json.loads(response_data.data) except Exception as e: - print("Exception when calling CreditApi->create_credit: %s\n" % e) + print("\nException when calling CreditApi->create_credit: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/payments/coreservices/process_payment.py b/samples/payments/coreservices/process_payment.py index d5d4ddf..601ef61 100644 --- a/samples/payments/coreservices/process_payment.py +++ b/samples/payments/coreservices/process_payment.py @@ -1,14 +1,18 @@ from CyberSource import * import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() + def process_a_payment(flag): + try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Setting the json message body request = CreatePaymentRequest() client_reference = Ptsv2paymentsClientReferenceInformation() @@ -16,7 +20,6 @@ def process_a_payment(flag): request.client_reference_information = client_reference.__dict__ processing_info = Ptsv2paymentsProcessingInformation() - if flag: processing_info.capture = "true" @@ -77,16 +80,27 @@ def process_a_payment(flag): message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() payment_obj = PaymentsApi(details_dict1) - return_data, status, body = payment_obj.create_payment(message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - - return return_data + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = payment_obj.create_payment(message_body) + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) + + return json.loads(response_data.data) except Exception as e: - print("Exception when calling PaymentsApi->create_payment: %s\n" % e) + print("\nException when calling PaymentsApi->create_payment: %s\n" % e) + finally: + + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/payments/coreservices/refund_capture.py b/samples/payments/coreservices/refund_capture.py index 277def9..1b40eb1 100644 --- a/samples/payments/coreservices/refund_capture.py +++ b/samples/payments/coreservices/refund_capture.py @@ -2,17 +2,19 @@ import capture_payment import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def refund_a_capture(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the capture_id dynamically using capture_a_payment method api_capture_response = capture_payment.capture_a_payment() - capture_id = api_capture_response.id + capture_id = api_capture_response['id'] # Setting the json message body request = RefundCaptureRequest() client_reference = Ptsv2paymentsClientReferenceInformation() @@ -27,14 +29,25 @@ def refund_a_capture(): request.order_information = order_information.__dict__ message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() refund_api = RefundApi(details_dict1) - return_data, status, body = refund_api.refund_capture(message_body, capture_id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = refund_api.refund_capture(message_body, capture_id) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling RefundApi->refund_capture: %s\n" % e) + print("\nException when calling RefundApi->refund_capture: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/payments/coreservices/refund_payment.py b/samples/payments/coreservices/refund_payment.py index 5c7ccb1..2e5fdbb 100644 --- a/samples/payments/coreservices/refund_payment.py +++ b/samples/payments/coreservices/refund_payment.py @@ -2,17 +2,19 @@ import process_payment import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def refund_a_payment(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the payment_id dynamically using process_a_payment method api_payment_response = process_payment.process_a_payment(True) - payment_id = api_payment_response.id + payment_id = api_payment_response['id'] # Setting the json message body request = RefundPaymentRequest() client_reference = Ptsv2paymentsClientReferenceInformation() @@ -27,16 +29,27 @@ def refund_a_payment(): request.order_information = order_information.__dict__ message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() refund_api = RefundApi(details_dict1) - return_data, status, body = refund_api.refund_payment(message_body, payment_id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - return return_data + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = refund_api.refund_payment(message_body, payment_id) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) + return json.loads(response_data.data) except Exception as e: - print("Exception when calling RefundApi->refund_payment: %s\n" % e) + print("\nException when calling RefundApi->refund_payment: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/payments/coreservices/void_capture.py b/samples/payments/coreservices/void_capture.py index d72b61d..be27d92 100644 --- a/samples/payments/coreservices/void_capture.py +++ b/samples/payments/coreservices/void_capture.py @@ -2,17 +2,19 @@ import capture_payment import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def void_a_capture(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the capture_id dynamically using capture_a_payment method api_capture_response = capture_payment.capture_a_payment() - capture_id = api_capture_response.id + capture_id = api_capture_response['id'] # Setting the json message body request = VoidCaptureRequest() client_reference = Ptsv2paymentsClientReferenceInformation() @@ -20,14 +22,25 @@ def void_a_capture(): request.client_reference_information = client_reference.__dict__ message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() void_obj = VoidApi(details_dict1) - return_data, status, body = void_obj.void_capture(message_body, capture_id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = void_obj.void_capture(message_body, capture_id) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling VoidApi->void_capture: %s\n" % e) + print("\nException when calling VoidApi->void_capture: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/payments/coreservices/void_credit.py b/samples/payments/coreservices/void_credit.py index a395e0d..6d19619 100644 --- a/samples/payments/coreservices/void_credit.py +++ b/samples/payments/coreservices/void_credit.py @@ -2,17 +2,19 @@ import process_credit import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def void_a_credit(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the credit_id dynamically using process_a_credit method api_credit_response = process_credit.process_a_credit() - credit_id = api_credit_response.id + credit_id = api_credit_response['id'] # Setting the json message body request = VoidCreditRequest() client_reference = Ptsv2paymentsClientReferenceInformation() @@ -20,14 +22,25 @@ def void_a_credit(): request.client_reference_information = client_reference.__dict__ message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() void_obj = VoidApi(details_dict1) - return_data, status, body = void_obj.void_credit(message_body, credit_id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data= void_obj.void_credit(message_body, credit_id) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling VoidApi->void_credit: %s\n" % e) + print("\nException when calling VoidApi->void_credit: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/payments/coreservices/void_payment.py b/samples/payments/coreservices/void_payment.py index 5b7eefe..0bfd9cd 100644 --- a/samples/payments/coreservices/void_payment.py +++ b/samples/payments/coreservices/void_payment.py @@ -2,17 +2,19 @@ import process_payment import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def void_a_payment(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the payment_id dynamically using process_a_payment method api_payment_response = process_payment.process_a_payment(True) - payment_id = api_payment_response.id + payment_id = api_payment_response['id'] # Setting the json message body request = VoidPaymentRequest() client_reference = Ptsv2paymentsClientReferenceInformation() @@ -20,14 +22,25 @@ def void_a_payment(): request.client_reference_information = client_reference.__dict__ message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() void_obj = VoidApi(details_dict1) - return_data, status, body = void_obj.void_payment(message_body, payment_id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data= void_obj.void_payment(message_body, payment_id) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling VoidApi->void_payment: %s\n" % e) + print("\nException when calling VoidApi->void_payment: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/payments/coreservices/void_refund.py b/samples/payments/coreservices/void_refund.py index bedcd7e..dd42b89 100644 --- a/samples/payments/coreservices/void_refund.py +++ b/samples/payments/coreservices/void_refund.py @@ -2,17 +2,19 @@ import refund_payment import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def void_a_refund(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the refund_id dynamically using refund_a_payment method api_refund_rsponse = refund_payment.refund_a_payment() - refund_id = api_refund_rsponse.id + refund_id = api_refund_rsponse['id'] # Setting the json message body request = VoidRefundRequest() client_reference = Ptsv2paymentsClientReferenceInformation() @@ -20,14 +22,25 @@ def void_a_refund(): request.client_reference_information = client_reference.__dict__ message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() void_obj = VoidApi(details_dict1) - return_data, status, body = void_obj.void_refund(message_body, refund_id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = void_obj.void_refund(message_body, refund_id) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling VoidApi->void_refund: %s\n" % e) + print("\nException when calling VoidApi->void_refund: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/payouts/coreservices/process_payout.py b/samples/payouts/coreservices/process_payout.py index 9571f81..96dbc30 100644 --- a/samples/payouts/coreservices/process_payout.py +++ b/samples/payouts/coreservices/process_payout.py @@ -1,14 +1,16 @@ from CyberSource import * import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def process_a_payout(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Setting the json message body request = PtsV2PayoutsPostResponse() client_reference = Ptsv2paymentsClientReferenceInformation() @@ -81,14 +83,25 @@ def process_a_payout(): request.recipient_information = recepient_info.__dict__ message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() process_payout_obj = ProcessAPayoutApi(details_dict1) - return_data, status, body = process_payout_obj.oct_create_payment(message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = process_payout_obj.oct_create_payment(message_body) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling ProcessAPayoutApi->oct_create_payment: %s\n" % e) + print("\nException when calling ProcessAPayoutApi->oct_create_payment: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/reporting/coreservices/create_adhoc_report.py b/samples/reporting/coreservices/create_adhoc_report.py index 37f023c..69a8c69 100644 --- a/samples/reporting/coreservices/create_adhoc_report.py +++ b/samples/reporting/coreservices/create_adhoc_report.py @@ -1,20 +1,22 @@ from CyberSource import * import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def create_adhoc_report(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Setting the json message body request = RequestBody1() request.report_definition_name = "TransactionRequestClass" request.timezone = "GMT" request.report_mime_type = "application/xml" - request.report_name = "cybersource-dec-17" + request.report_name = "Cybersource-rest-py098" request.report_start_time = "2018-09-01T12:00:00+05:00" request.report_end_time = "2018-09-02T12:00:00+05:00" request.report_filters = { @@ -24,14 +26,25 @@ def create_adhoc_report(): request.report_fields = ["Request.RequestID", "Request.TransactionDate", "Request.MerchantID"] message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() report_obj = ReportsApi(details_dict1) - return_data, status, body = report_obj.create_report(message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = report_obj.create_report(message_body) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling ReportsApi->create_report: %s\n" % e) + print("\nException when calling ReportsApi->create_report: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/reporting/coreservices/create_report_subscription_for_report_name_by_organization.py b/samples/reporting/coreservices/create_report_subscription_for_report_name_by_organization.py index 68c99e9..3d21aa2 100644 --- a/samples/reporting/coreservices/create_report_subscription_for_report_name_by_organization.py +++ b/samples/reporting/coreservices/create_report_subscription_for_report_name_by_organization.py @@ -1,41 +1,54 @@ from CyberSource import * import json import os +import inspect import delete_subscription_of_report_name_by_organization from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def create_report_subscription(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Setting the json message body - request = RequestBody() - request.report_definition_name = "TransactionRequestClass" - request.report_fields = ["Request.RequestID", "Request.TransactionDate", "Request.MerchantID"] + request = RequestBody(report_definition_name="TransactionRequestClass",report_fields=["Request.RequestID", "Request.TransactionDate", "Request.MerchantID"],report_name="Cybersource-rest-py") + #request.report_definition_name = "TransactionRequestClass" + #request.report_fields = ["Request.RequestID", "Request.TransactionDate", "Request.MerchantID"] request.report_mime_type = "application/xml" request.report_frequency = "WEEKLY" request.timezone = "GMT" - request.start_time = "0827" + request.start_time = "0825" request.start_day = 1 - request.report_name = "Cybersource-rest-py" + #request.report_name = "Cybersource-rest-py" message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() report_subscription_obj = ReportSubscriptionsApi(details_dict1) - return_data, status, body = report_subscription_obj.create_subscription(message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = report_subscription_obj.create_subscription(message_body,report_name=request.report_name) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) # Deleting the Report created by create_subscription method - if status == 201: + if response_data.status == 201: delete_subscription_of_report_name_by_organization.delete_subscriptions_report(request.report_name) - return return_data + return json.loads(response_data.data) except Exception as e: - print("Exception when calling ReportSubscriptionsApi->create_subscription: %s\n" % e) + print("\nException when calling ReportSubscriptionsApi->create_subscription: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/reporting/coreservices/delete_subscription_of_report_name_by_organization.py b/samples/reporting/coreservices/delete_subscription_of_report_name_by_organization.py index 704dcf0..001cf50 100644 --- a/samples/reporting/coreservices/delete_subscription_of_report_name_by_organization.py +++ b/samples/reporting/coreservices/delete_subscription_of_report_name_by_organization.py @@ -1,25 +1,33 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def delete_subscriptions_report(reportname): try: - + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) report_name = reportname # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() report_subscription_obj = ReportSubscriptionsApi(details_dict1) - return_data, status, body = report_subscription_obj.delete_subscription(report_name) - - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = report_subscription_obj.delete_subscription(report_name) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling ReportSubscriptionsApi->delete_subscription: %s\n" % e) + print("\nException when calling ReportSubscriptionsApi->delete_subscription: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/reporting/coreservices/download_report.py b/samples/reporting/coreservices/download_report.py index 5a0e278..aff9d57 100644 --- a/samples/reporting/coreservices/download_report.py +++ b/samples/reporting/coreservices/download_report.py @@ -1,34 +1,43 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def download_reports(): try: - report_name = "testrest_v2" + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) + report_name = "Cybersource-rest-py60" report_date = "2018-09-02" # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() report_download_obj = ReportDownloadsApi(details_dict1) - return_data, status, body = report_download_obj.download_report(report_date, report_name,organization_id="testrest") - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - + response_data = report_download_obj.download_report(report_date, report_name,organization_id="testrest") + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) # The Report obtained is being stored in a CSV file f = open(os.path.join(os.getcwd(), "resources", "download_report.csv"), "a+") f.write("\n********************** Start Of Report***********************\n") - f.write(body) + f.write(response_data.data) f.write("\n********************** End Of Report*************************\n") f.close() print("File Downloaded at the Location : " + os.path.join(os.getcwd(), "resources", "download_report.csv")) except Exception as e: - print("Exception when calling ReportDownloadsApi->download_report: %s\n" % e) + print("\nException when calling ReportDownloadsApi->download_report: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/reporting/coreservices/get_all_subscriptions.py b/samples/reporting/coreservices/get_all_subscriptions.py index 9957805..0e893ff 100644 --- a/samples/reporting/coreservices/get_all_subscriptions.py +++ b/samples/reporting/coreservices/get_all_subscriptions.py @@ -1,22 +1,32 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def get_all_subscriptions(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() get_subscription_obj = ReportSubscriptionsApi(details_dict1) - return_data, status, body = get_subscription_obj.get_all_subscriptions() - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data= get_subscription_obj.get_all_subscriptions() + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling ReportSubscriptionsApi->get_all_subscriptions: %s\n" % e) + print("\nException when calling ReportSubscriptionsApi->get_all_subscriptions: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/reporting/coreservices/get_notification_of_changes.py b/samples/reporting/coreservices/get_notification_of_changes.py index a72e4c0..ce06496 100644 --- a/samples/reporting/coreservices/get_notification_of_changes.py +++ b/samples/reporting/coreservices/get_notification_of_changes.py @@ -1,24 +1,34 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def notification_of_change(): try: - start_time = "2018-09-01T12:00:00-05:00" - end_time = "2018-09-30T12:00:00-05:00" + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) + start_time = "2018-05-01T12:00:00-05:00" + end_time = "2018-05-30T12:00:00-05:00" # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() notification_obj = NotificationOfChangesApi(details_dict1) - return_data, status, body = notification_obj.get_notification_of_change_report(start_time, end_time) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = notification_obj.get_notification_of_change_report(start_time, end_time) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling NotificationOfChangesApi->get_notification_of_change_report: %s\n" % e) + print("\nException when calling NotificationOfChangesApi->get_notification_of_change_report: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/reporting/coreservices/get_purchase_and_refund_details.py b/samples/reporting/coreservices/get_purchase_and_refund_details.py index 6595923..ba22c66 100644 --- a/samples/reporting/coreservices/get_purchase_and_refund_details.py +++ b/samples/reporting/coreservices/get_purchase_and_refund_details.py @@ -1,25 +1,35 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def purchase_and_refund(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) start_time = "2018-05-01T12:00:00-05:00" end_time = "2018-05-30T12:00:00-05:00" # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() purchase_refund_obj = PurchaseAndRefundDetailsApi(details_dict1) - return_data, status, body = purchase_refund_obj.get_purchase_and_refund_details(start_time, end_time) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = purchase_refund_obj.get_purchase_and_refund_details(start_time, end_time) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling PurchaseAndRefundDetailsApi->get_purchase_and_refund_details: %s\n" % e) + print("\nException when calling PurchaseAndRefundDetailsApi->get_purchase_and_refund_details: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/reporting/coreservices/get_report_based_on_reportid.py b/samples/reporting/coreservices/get_report_based_on_reportid.py index 5c145f5..99bb71d 100644 --- a/samples/reporting/coreservices/get_report_based_on_reportid.py +++ b/samples/reporting/coreservices/get_report_based_on_reportid.py @@ -1,23 +1,33 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def get_report_by_reportid(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) report_id = "79642c43-2368-0cd5-e053-a2588e0a7b3c" # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() get_report_obj = ReportsApi(details_dict1) - return_data, status, body = get_report_obj.get_report_by_report_id(report_id, organization_id="testrest") - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = get_report_obj.get_report_by_report_id(report_id, organization_id="testrest") + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling ReportsApi->get_report_by_report_id: %s\n" % e) + print("\nException when calling ReportsApi->get_report_by_report_id: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/reporting/coreservices/get_report_definition.py b/samples/reporting/coreservices/get_report_definition.py index 1da056d..4d94f2f 100644 --- a/samples/reporting/coreservices/get_report_definition.py +++ b/samples/reporting/coreservices/get_report_definition.py @@ -1,23 +1,33 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def get_report_definitions(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) report_definition_name = "AcquirerExceptionDetailClass" # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() report_definition_obj = ReportDefinitionsApi(details_dict1) - return_data, status, body = report_definition_obj.get_resource_info_by_report_definition(report_definition_name) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = report_definition_obj.get_resource_info_by_report_definition(report_definition_name) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling ReportDefinitionsApi->get_resource_info_by_report_definition: %s\n" % e) + print("\nException when calling ReportDefinitionsApi->get_resource_info_by_report_definition: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/reporting/coreservices/get_reporting_resource_information.py b/samples/reporting/coreservices/get_reporting_resource_information.py index 3d8b828..5a353b2 100644 --- a/samples/reporting/coreservices/get_reporting_resource_information.py +++ b/samples/reporting/coreservices/get_reporting_resource_information.py @@ -1,22 +1,32 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def get_reporting_resource_information(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() report_definition_obj = ReportDefinitionsApi(details_dict1) - return_data, status, body = report_definition_obj.get_resource_v2_info(organization_id="testrest") - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = report_definition_obj.get_resource_v2_info(organization_id="testrest") + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling ReportDefinitionsApi->get_resource_v2_info: %s\n" % e) + print("\nException when calling ReportDefinitionsApi->get_resource_v2_info: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/reporting/coreservices/get_subscription_for_report_name.py b/samples/reporting/coreservices/get_subscription_for_report_name.py index 2578890..3b1e1e0 100644 --- a/samples/reporting/coreservices/get_subscription_for_report_name.py +++ b/samples/reporting/coreservices/get_subscription_for_report_name.py @@ -1,23 +1,33 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def get_subscriptions_by_name(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) report_name = "Cybersource-rest-py" # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() report_subscription_obj = ReportSubscriptionsApi(details_dict1) - return_data, status, body = report_subscription_obj.get_subscription(report_name) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = report_subscription_obj.get_subscription(report_name) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling ReportSubscriptionsApi->get_subscription: %s\n" % e) + print("\nException when calling ReportSubscriptionsApi->get_subscription: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/reporting/coreservices/retrieve_available_reports.py b/samples/reporting/coreservices/retrieve_available_reports.py index 6db2489..9f0144a 100644 --- a/samples/reporting/coreservices/retrieve_available_reports.py +++ b/samples/reporting/coreservices/retrieve_available_reports.py @@ -1,25 +1,35 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def available_reports(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) start_time = "2018-10-01T00:00:00.0Z" end_time = "2018-10-30T23:59:59.0Z" time_query_type = "executedTime" # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() report_obj = ReportsApi(details_dict1) - return_data, status, body = report_obj.search_reports(start_time, end_time, time_query_type) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = report_obj.search_reports(start_time, end_time, time_query_type) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling ReportsApi->search_reports: %s\n" % e) + print("\nException when calling ReportsApi->search_reports: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/secure_file_share/coreservices/download_file_with_file_identifier.py b/samples/secure_file_share/coreservices/download_file_with_file_identifier.py index 10568ec..1a3faa3 100644 --- a/samples/secure_file_share/coreservices/download_file_with_file_identifier.py +++ b/samples/secure_file_share/coreservices/download_file_with_file_identifier.py @@ -1,31 +1,40 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def download_file_with_file_identifier(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) field_id = "VFJSUmVwb3J0LTc4NTVkMTNmLTkzOTgtNTExMy1lMDUzLWEyNTg4ZTBhNzE5Mi5jc3YtMjAxOC0xMC0yMA==" # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() search_transaction_obj = SecureFileShareApi(details_dict1) - return_data, status, body = search_transaction_obj.get_file(field_id, organization_id="testrest") - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - + response_data = search_transaction_obj.get_file(field_id, organization_id="testrest") + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) # The Report obtained is being stored in a CSV file f = open(os.path.join(os.getcwd(), "resources", "fileshare_report.csv"), "a+") f.write("\n********************** Start Of Report***********************\n") - f.write(body) + f.write(response_data.data) f.write("\n********************** End Of Report*************************\n") f.close() print("File Downloaded at the Location : " + os.path.join(os.getcwd(), "resources", "fileshare_report.csv")) except Exception as e: - print("Exception when calling SecureFileShareApi->get_file: %s\n" % e) + print("\nException when calling SecureFileShareApi->get_file: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/secure_file_share/coreservices/get_list_of_files.py b/samples/secure_file_share/coreservices/get_list_of_files.py index 48dc219..7c22edb 100644 --- a/samples/secure_file_share/coreservices/get_list_of_files.py +++ b/samples/secure_file_share/coreservices/get_list_of_files.py @@ -1,25 +1,37 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def get_list_of_files(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) start_date = "2018-10-20" end_date = "2018-10-30" # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() search_transaction_obj = SecureFileShareApi(details_dict1) - return_data, status, body = search_transaction_obj.get_file_details(start_date, end_date, + response_data = search_transaction_obj.get_file_details(start_date, end_date, organization_id="testrest") - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + config = Configuration() + request_headers = config.api_client.request_headers + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling SecureFileShareApi->get_file_details: %s\n" % e) + print("\nException when calling SecureFileShareApi->get_file_details: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/tms/coreservices/create_instrument_identifier.py b/samples/tms/coreservices/create_instrument_identifier.py index f87efa5..b878524 100644 --- a/samples/tms/coreservices/create_instrument_identifier.py +++ b/samples/tms/coreservices/create_instrument_identifier.py @@ -1,14 +1,16 @@ from CyberSource import * import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def create_instrument_identifier(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Setting the json message body request = Body() card_info = Tmsv1instrumentidentifiersCard() @@ -24,28 +26,31 @@ def create_instrument_identifier(): authorize_options_info.initiator = initiator.__dict__ processing_info.authorization_options = authorize_options_info.__dict__ request.processing_information = processing_info.__dict__ - message_body = del_none(request.__dict__) - message_body = json.dumps(message_body) + + message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() instrument_identifier_obj = InstrumentIdentifiersApi(details_dict1) - return_data, status, body = instrument_identifier_obj.tms_v1_instrumentidentifiers_post( + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = instrument_identifier_obj.tms_v1_instrumentidentifiers_post( "93B32398-AD51-4CC2-A682-EA3E93614EB1", body=message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - return return_data + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) + return json.loads(response_data.data) except Exception as e: - print("Exception when calling InstrumentIdentifiersApi->tms_v1_instrumentidentifiers_post: %s\n" % e) - -# To delete None values in Input Request Json body -def del_none(d): - for key, value in list(d.items()): - if value is None: - del d[key] - elif isinstance(value, dict): - del_none(value) - return d + print("\nException when calling InstrumentIdentifiersApi->tms_v1_instrumentidentifiers_post: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) + if __name__ == "__main__": diff --git a/samples/tms/coreservices/create_payment_instrument.py b/samples/tms/coreservices/create_payment_instrument.py index e135756..0991610 100644 --- a/samples/tms/coreservices/create_payment_instrument.py +++ b/samples/tms/coreservices/create_payment_instrument.py @@ -1,14 +1,16 @@ from CyberSource import * import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def create_payment_instrument(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Setting the json message body request = Body2() card_info = Tmsv1paymentinstrumentsCard() @@ -36,31 +38,32 @@ def create_payment_instrument(): card_info.number = "4111111111111111" instument_identifier.card = card_info.__dict__ request.instrument_identifier = instument_identifier.__dict__ - message_body = del_none(request.__dict__) - message_body = json.dumps(message_body) + message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() payment_instrument_obj = PaymentInstrumentsApi(details_dict1) - return_data, status, body = payment_instrument_obj.tms_v1_paymentinstruments_post( + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = payment_instrument_obj.tms_v1_paymentinstruments_post( "93B32398-AD51-4CC2-A682-EA3E93614EB1", message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - return return_data + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) + return json.loads(response_data.data) except Exception as e: - print("Exception when calling PaymentInstrumentsApi->tms_v1_paymentinstruments_post: %s\n" % e) + print("\nException when calling PaymentInstrumentsApi->tms_v1_paymentinstruments_post: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) -# To delete None values in Input Request Json body -def del_none(d): - for key, value in list(d.items()): - if value is None: - del d[key] - elif isinstance(value, dict): - del_none(value) - return d - if __name__ == "__main__": create_payment_instrument() diff --git a/samples/tms/coreservices/delete_instrument_identifier.py b/samples/tms/coreservices/delete_instrument_identifier.py index 813d98d..4b67d77 100644 --- a/samples/tms/coreservices/delete_instrument_identifier.py +++ b/samples/tms/coreservices/delete_instrument_identifier.py @@ -1,27 +1,37 @@ from CyberSource import * import retrieve_instrument_identifier import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def remove_instrument_identifiers(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the api_instrument_response-id dynamically using retrieve_instrument_identifier method api_instrument_response = retrieve_instrument_identifier.retrieve_instrument_identifier() # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() instrument_identifier_obj = InstrumentIdentifierApi(details_dict1) - return_data, status, body = instrument_identifier_obj.tms_v1_instrumentidentifiers_token_id_delete( - "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_instrument_response.id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = instrument_identifier_obj.tms_v1_instrumentidentifiers_token_id_delete( + "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_instrument_response['id']) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling InstrumentIdentifierApi->tms_v1_instrumentidentifiers_token_id_delete: %s\n" % e) + print("\nException when calling InstrumentIdentifierApi->tms_v1_instrumentidentifiers_token_id_delete: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/tms/coreservices/delete_payment_instrument.py b/samples/tms/coreservices/delete_payment_instrument.py index 7a10dc8..49644a2 100644 --- a/samples/tms/coreservices/delete_payment_instrument.py +++ b/samples/tms/coreservices/delete_payment_instrument.py @@ -1,27 +1,37 @@ from CyberSource import * import retrieve_payment_instrument import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def remove_payment_instruments(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the api_payment_response-id dynamically using retrieve_payment_instrument method api_payment_response = retrieve_payment_instrument.retrieve_payment_instrument() # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() payment_instrument_obj = PaymentInstrumentsApi(details_dict1) - return_data, status, body = payment_instrument_obj.tms_v1_paymentinstruments_token_id_delete( - "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_payment_response.id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = payment_instrument_obj.tms_v1_paymentinstruments_token_id_delete( + "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_payment_response['id']) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling PaymentInstrumentsApi->tms_v1_paymentinstruments_token_id_delete: %s\n" % e) + print("\nException when calling PaymentInstrumentsApi->tms_v1_paymentinstruments_token_id_delete: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/tms/coreservices/retrieve_all_payment_instruments.py b/samples/tms/coreservices/retrieve_all_payment_instruments.py index d48b9fc..84075fd 100644 --- a/samples/tms/coreservices/retrieve_all_payment_instruments.py +++ b/samples/tms/coreservices/retrieve_all_payment_instruments.py @@ -1,29 +1,38 @@ from CyberSource import * import create_instrument_identifier import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def retrieve_all_payments(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the api_instrument_identifier_response-id dynamically using create_instrument_identifier method api_instrument_identifier_response = create_instrument_identifier.create_instrument_identifier() # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() instrument_identifier = PaymentInstrumentsApi(details_dict1) - return_data, status, body = instrument_identifier.tms_v1_instrumentidentifiers_token_id_paymentinstruments_get( - "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_instrument_identifier_response.id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - + response_data = instrument_identifier.tms_v1_instrumentidentifiers_token_id_paymentinstruments_get( + "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_instrument_identifier_response['id']) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: print( - "Exception when calling PaymentInstrumentsApi->tms_v1_instrumentidentifiers_token_id_paymentinstruments_get: %s\n" % e) + "\nException when calling PaymentInstrumentsApi->tms_v1_instrumentidentifiers_token_id_paymentinstruments_get: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/tms/coreservices/retrieve_instrument_identifier.py b/samples/tms/coreservices/retrieve_instrument_identifier.py index a552821..10f7dd1 100644 --- a/samples/tms/coreservices/retrieve_instrument_identifier.py +++ b/samples/tms/coreservices/retrieve_instrument_identifier.py @@ -1,27 +1,38 @@ from CyberSource import * import create_instrument_identifier import os +import json +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def retrieve_instrument_identifier(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the api_instrument_identifier_response-id dynamically using create_instrument_identifier method api_instrument_identifier_response = create_instrument_identifier.create_instrument_identifier() # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() instrument_identifier = InstrumentIdentifierApi(details_dict1) - return_data, status, body = instrument_identifier.tms_v1_instrumentidentifiers_token_id_get( - "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_instrument_identifier_response.id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - return return_data + response_data = instrument_identifier.tms_v1_instrumentidentifiers_token_id_get( + "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_instrument_identifier_response['id']) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) + return json.loads(response_data.data) except Exception as e: - print("Exception when calling InstrumentIdentifierApi->tms_v1_instrumentidentifiers_token_id_get: %s\n" % e) + print("\nException when calling InstrumentIdentifierApi->tms_v1_instrumentidentifiers_token_id_get: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/tms/coreservices/retrieve_payment_instrument.py b/samples/tms/coreservices/retrieve_payment_instrument.py index d0acc73..0c21628 100644 --- a/samples/tms/coreservices/retrieve_payment_instrument.py +++ b/samples/tms/coreservices/retrieve_payment_instrument.py @@ -1,27 +1,38 @@ from CyberSource import * import create_payment_instrument import os +import json +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def retrieve_payment_instrument(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the api_payment_response-id dynamically using create_payment_instrument method api_payment_response = create_payment_instrument.create_payment_instrument() # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() payment_instruments = PaymentInstrumentsApi(details_dict1) - return_data, status, body = payment_instruments.tms_v1_paymentinstruments_token_id_get( - "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_payment_response.id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - return return_data + response_data= payment_instruments.tms_v1_paymentinstruments_token_id_get( + "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_payment_response['id']) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) + return json.loads(response_data.data) except Exception as e: - print("Exception when calling PaymentInstrumentsApi->tms_v1_paymentinstruments_token_id_get: %s\n" % e) + print("\nException when calling PaymentInstrumentsApi->tms_v1_paymentinstruments_token_id_get: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/tms/coreservices/update_instrument_identifier.py b/samples/tms/coreservices/update_instrument_identifier.py index 998e506..b2b1f2d 100644 --- a/samples/tms/coreservices/update_instrument_identifier.py +++ b/samples/tms/coreservices/update_instrument_identifier.py @@ -2,14 +2,16 @@ import retrieve_instrument_identifier import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def update_instrument_identifier(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the api_instrument_identifier_response-id dynamically using retrieve_instrument_identifier method api_instrument_identifier_response = retrieve_instrument_identifier.retrieve_instrument_identifier() # Setting the json message body @@ -24,28 +26,31 @@ def update_instrument_identifier(): authorize_options_info.initiator = initiator.__dict__ processing_info.authorization_options = authorize_options_info.__dict__ request.processing_information = processing_info.__dict__ - message_body = del_none(request.__dict__) - message_body = json.dumps(message_body) + + message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() instrument_identifier_obj = InstrumentIdentifierApi(details_dict1) - return_data, status, body = instrument_identifier_obj.tms_v1_instrumentidentifiers_token_id_patch( - "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_instrument_identifier_response.id, body=message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = instrument_identifier_obj.tms_v1_instrumentidentifiers_token_id_patch( + "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_instrument_identifier_response['id'], body=message_body) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling InstrumentIdentifierApi->tms_v1_instrumentidentifiers_token_id_patch: %s\n" % e) - -# To delete None values in Input Request Json body -def del_none(d): - for key, value in list(d.items()): - if value is None: - del d[key] - elif isinstance(value, dict): - del_none(value) - return d + print("\nException when calling InstrumentIdentifierApi->tms_v1_instrumentidentifiers_token_id_patch: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) + if __name__ == "__main__": diff --git a/samples/tms/coreservices/update_payment_instrument.py b/samples/tms/coreservices/update_payment_instrument.py index 1d3a6e5..a992f1f 100644 --- a/samples/tms/coreservices/update_payment_instrument.py +++ b/samples/tms/coreservices/update_payment_instrument.py @@ -2,14 +2,16 @@ import retrieve_payment_instrument import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def update_payment_instrument(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Getting the api_payment_response-id dynamically using retrieve_payment_instrument method api_payment_response = retrieve_payment_instrument.retrieve_payment_instrument() # Setting the json message body @@ -40,28 +42,30 @@ def update_payment_instrument(): card_info.number = "4111111111111111" instument_identifier.card = card_info.__dict__ request.instrument_identifier = instument_identifier.__dict__ - message_body = del_none(request.__dict__) - message_body = json.dumps(message_body) + + message_body = json.dumps(request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() payment_instrument_obj = PaymentInstrumentsApi(details_dict1) - return_data, status, body = payment_instrument_obj.tms_v1_paymentinstruments_token_id_patch( - "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_payment_response.id, message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data= payment_instrument_obj.tms_v1_paymentinstruments_token_id_patch( + "93B32398-AD51-4CC2-A682-EA3E93614EB1", api_payment_response['id'], message_body) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling PaymentInstrumentsApi->tms_v1_paymentinstruments_token_id_patch: %s\n" % e) - -# To delete None values in Input Request Json body -def del_none(d): - for key, value in list(d.items()): - if value is None: - del d[key] - elif isinstance(value, dict): - del_none(value) - return d + print("\nException when calling PaymentInstrumentsApi->tms_v1_paymentinstruments_token_id_patch: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/transaction_batches/coreservices/get_individual_batch_file.py b/samples/transaction_batches/coreservices/get_individual_batch_file.py index ecc6937..4952c6a 100644 --- a/samples/transaction_batches/coreservices/get_individual_batch_file.py +++ b/samples/transaction_batches/coreservices/get_individual_batch_file.py @@ -1,23 +1,33 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def get_individual_batch_file(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() transction_api_obj = TransactionBatchApi(details_dict1) batch_file_id = "Owcyk6pl" - return_data, status, body = transction_api_obj.pts_v1_transaction_batches_id_get(batch_file_id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = transction_api_obj.pts_v1_transaction_batches_id_get(batch_file_id) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling TransactionBatchApi->pts_v1_transaction_batches_id_get: %s\n" % e) + print("\nException when calling TransactionBatchApi->pts_v1_transaction_batches_id_get: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/transaction_batches/coreservices/get_list_of_batch_files.py b/samples/transaction_batches/coreservices/get_list_of_batch_files.py index 5d411d6..e5390b5 100644 --- a/samples/transaction_batches/coreservices/get_list_of_batch_files.py +++ b/samples/transaction_batches/coreservices/get_list_of_batch_files.py @@ -1,24 +1,34 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def get_list_of_batch_files(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() start_time = "2018-10-01T20:34:24.000Z" end_time = "2018-10-29T23:27:25.000Z" transction_api_obj = TransactionBatchesApi(details_dict1) - return_data, status, body = transction_api_obj.pts_v1_transaction_batches_get(start_time, end_time) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = transction_api_obj.pts_v1_transaction_batches_get(start_time, end_time) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling TransactionBatchesApi->pts_v1_transaction_batches_get: %s\n" % e) + print("\nException when calling TransactionBatchesApi->pts_v1_transaction_batches_get: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/transaction_details/coreservices/retrieve_transaction.py b/samples/transaction_details/coreservices/retrieve_transaction.py index 25d2e92..096224e 100644 --- a/samples/transaction_details/coreservices/retrieve_transaction.py +++ b/samples/transaction_details/coreservices/retrieve_transaction.py @@ -1,23 +1,33 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def retrieve_transaction(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() transction_details_obj = TransactionDetailsApi(details_dict1) retrieve_transaction_id = "5408386919326811103004" - return_data, status, body = transction_details_obj.get_transaction(retrieve_transaction_id) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data= transction_details_obj.get_transaction(retrieve_transaction_id) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling TransactionDetailsApi->get_transaction: %s\n" % e) + print("\nException when calling TransactionDetailsApi->get_transaction: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/transaction_search/coreservices/create_search_request.py b/samples/transaction_search/coreservices/create_search_request.py index b7a109a..2ddbcd2 100644 --- a/samples/transaction_search/coreservices/create_search_request.py +++ b/samples/transaction_search/coreservices/create_search_request.py @@ -1,14 +1,16 @@ from CyberSource import * import json import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def create_search_request(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Setting the json message body create_search_request = TssV2TransactionsPostResponse() create_search_request.save = "false" @@ -20,16 +22,26 @@ def create_search_request(): create_search_request.sort = "id:asc, submitTimeUtc:asc" message_body = json.dumps(create_search_request.__dict__) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() search_transaction_obj = SearchTransactionsApi(details_dict1) - return_data, status, body = search_transaction_obj.create_search(message_body) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) - return return_data + # Calling api_client variable in Configuration file + config = Configuration() + print("\nAPI REQUEST BODY: ", + config.api_client.masking(json.dumps(config.api_client.replace_underscore(json.loads(message_body))))) + response_data = search_transaction_obj.create_search(message_body) + # Calling api_client variable in Configuration file + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling SearchTransactionsApi->create_search: %s\n" % e) + print("\nException when calling SearchTransactionsApi->create_search: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/transaction_search/coreservices/get_search_results.py b/samples/transaction_search/coreservices/get_search_results.py index 0cf3506..7f35c5e 100644 --- a/samples/transaction_search/coreservices/get_search_results.py +++ b/samples/transaction_search/coreservices/get_search_results.py @@ -1,23 +1,33 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def get_search_results(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() search_transaction_obj = SearchTransactionsApi(details_dict1) - id_input = "95f6ab1c-d64d-4fdb-949d-cf174405c21f" - return_data, status, body = search_transaction_obj.get_search(id_input) - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + id_input = "a3e82358-892b-467b-9c38-1049294e1d0b" + response_data = search_transaction_obj.get_search(id_input) + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling SearchTransactionsApi->get_search: %s\n" % e) + print("\nException when calling SearchTransactionsApi->get_search: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__": diff --git a/samples/user_management/coreservices/get_user_information.py b/samples/user_management/coreservices/get_user_information.py index 6e85aff..990c4c4 100644 --- a/samples/user_management/coreservices/get_user_information.py +++ b/samples/user_management/coreservices/get_user_information.py @@ -1,23 +1,33 @@ from CyberSource import * import os +import inspect from importlib.machinery import SourceFileLoader -config_file = os.path.join(os.getcwd(), "data", "Configuration.py") +config_file = os.path.join(os.getcwd(), "data", "input_configuration.py") configuration = SourceFileLoader("module.name", config_file).load_module() def get_user_information(): try: + print("\n[BEGIN] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) # Reading Merchant details from Configuration file - config_obj = configuration.Configuration() + config_obj = configuration.InputConfiguration() details_dict1 = config_obj.get_configuration() user_management_obj = UserManagementApi(details_dict1) - return_data, status, body = user_management_obj.get_users(organization_id="testrest") - print("API RESPONSE CODE : ", status) - print("API RESPONSE BODY : ", body) + response_data = user_management_obj.get_users(organization_id="testrest") + # Calling api_client variable in Configuration file to access the request_headers + config = Configuration() + request_headers = config.api_client.request_headers + # Statements to print on console + print("\nAPI REQUEST HEADERS: ", request_headers) + print("\nAPI RESPONSE CODE : ", response_data.status) + print("\nAPI RESPONSE BODY : ", response_data.data) + print("\nAPI RESPONSE HEADERS: ", response_data.getheaders()) except Exception as e: - print("Exception when calling UserManagementApi->get_users: %s\n" % e) + print("\nException when calling UserManagementApi->get_users: %s\n" % e) + finally: + print("\n[END] EXECUTION OF SAMPLE CODE:" + inspect.currentframe().f_code.co_name) if __name__ == "__main__":