Example #1
0
        public static void Run()
        {
            try
            {
                var requestData = new RequestData();

                // Setting up Merchant Config
                var merchantConfig = new MerchantConfig
                {
                    RequestTarget   = RequestTarget,
                    RequestType     = Enumerations.RequestType.POST.ToString(),
                    RequestJsonData = requestData.JsonFileData(RequestJsonFilePath)
                };

                // Call to the Controller of API_SDK
                var apiController = new APIController(merchantConfig);
                var response      = apiController.PostPayment();

                // printing the response details
                if (response != null)
                {
                    Console.WriteLine("\n v-c-correlation-id:{0}", response.GetResponseHeaderValue(response.Headers, "v-c-correlation-id"));
                    Console.WriteLine("\n Response Code:{0}", response.StatusCode);
                    Console.WriteLine("\n Response Message:{0}", response.Data);
                }
            }
            catch (Exception e)
            {
                ExceptionUtility.Exception(e.Message, e.StackTrace);
            }
        }
        /**
         * @return a JwtToken object (JWT Bearer Token),
         * based on the Merchant Configuration passed to the Constructor of Authorize Class
         */
        public JwtToken GetToken()
        {
            try
            {
                if (_merchantConfig != null)
                {
                    LogMerchantDetails();

                    Enumerations.ValidateRequestType(_merchantConfig.RequestType);

                    var tokenObj = (JwtToken) new JwtTokenGenerator(_merchantConfig).GetToken();

                    if (_merchantConfig.IsGetRequest || _merchantConfig.IsDeleteRequest)
                    {
                        _logger.Trace("{0} {1}", "Content-Type:", "application/json");
                    }
                    else if (_merchantConfig.IsPostRequest || _merchantConfig.IsPutRequest || _merchantConfig.IsPatchRequest)
                    {
                        _logger.Trace("{0} {1}", "Content-Type:", "application/hal+json");
                    }

                    _logger.Trace("{0} {1}", "Authorization:", tokenObj.BearerToken);

                    return(tokenObj);
                }

                return(null);
            }
            catch (Exception e)
            {
                ExceptionUtility.Exception(e.Message, e.StackTrace);
                return(null);
            }
        }
Example #3
0
        public static void Run()
        {
            try
            {
                // Creating a dictionary object which contains the merchant configuration
                var config = new Configuration();

                // Passing the dictionary object to the Merchant Config Constructor to bypass the config set up via App.Config File
                var merchantConfig = new MerchantConfig(config.GetConfiguration())
                {
                    RequestTarget = RequestTarget,
                    RequestType   = Enumerations.RequestType.GET.ToString()
                };

                // Call to the Controller of API_SDK
                var apiController = new APIController(merchantConfig);
                var response      = apiController.GetPayment();

                // printing the response details
                if (response != null)
                {
                    Console.WriteLine("\n v-c-correlation-id:{0}", response.GetResponseHeaderValue(response.Headers, "v-c-correlation-id"));
                    Console.WriteLine("\n Response Code:{0}", response.StatusCode);
                    Console.WriteLine("\n Response Message:{0}", response.Data);
                }
            }
            catch (Exception e)
            {
                ExceptionUtility.Exception(e.Message, e.StackTrace);
            }
        }
Example #4
0
        /**
         * @return a Response object (HTTP Response) for the HTTP DELETE Request
         * based on the Merchant Configuration passed to the Constructor of ApiController Class
         */
        public Response DeletePayment()
        {
            try
            {
                // Call the Service to Get the Response Object
                var response = _paymentRequestService.DeleteResponse();
                LogResponseDetails(response);

                return(response);
            }
            catch (Exception e)
            {
                ExceptionUtility.Exception(e.Message, e.StackTrace);
                return(null);
            }
        }
Example #5
0
        public MerchantConfig(IReadOnlyDictionary <string, string> merchantConfigDictionary = null)
        {
            Logger = LogManager.GetCurrentClassLogger();

            // MerchantConfig section inside App.Config File
            var merchantConfigSection = (NameValueCollection)ConfigurationManager.GetSection("MerchantConfig");

            /*Set the properties of Merchant Config
             * If a dictionary object has been passed use that object
             * If no dictionary object is passed, that means use app.config
             * Howevere if App.Config does not contain Merchan Config, throw an exception*/
            if (merchantConfigDictionary != null)
            {
                SetValuesUsingDictObj(merchantConfigDictionary);
            }
            else
            {
                if (merchantConfigSection != null)
                {
                    SetValuesFromAppConfig(merchantConfigSection);
                }
                else
                {
                    throw new Exception($"{Constants.ErrorPrefix} Merchant Config Missing in App.Config File!");
                }
            }

            LogUtility.InitLogConfig(EnableLog, LogDirectory, LogFileName, LogfileMaxSize);

            try
            {
                // Logger object is ready to Log
                Logger.Trace("\n");
                Logger.Trace("START> =======================================");

                // Logging the source of properties' values
                Logger.Trace("Reading Merchant Configuration from " + _propertiesSetUsing);
            }
            catch (Exception e)
            {
                ExceptionUtility.Exception(e.Message, e.StackTrace);
            }

            // Validations
            ValidateProperties();
        }
        /**
         * @return an HttpToken object (HTTP Signature Headers),
         * based on the Merchant Configuration passed to the Constructor of Authorize Class
         */
        public HttpToken GetSignature()
        {
            try
            {
                if (_merchantConfig != null)
                {
                    LogMerchantDetails();

                    Enumerations.ValidateRequestType(_merchantConfig.RequestType);

                    var signatureObj = (HttpToken) new HttpTokenGenerator(_merchantConfig).GetToken();

                    if (_merchantConfig.IsGetRequest || _merchantConfig.IsDeleteRequest)
                    {
                        _logger.Trace("{0} {1}", "Content-Type:", "application/json");
                    }

                    if (_merchantConfig.IsPostRequest || _merchantConfig.IsPutRequest || _merchantConfig.IsPatchRequest)
                    {
                        _logger.Trace("{0} {1}", "Content-Type:", "application/hal+json");
                    }

                    _logger.Trace("{0} {1}", "v-c-merchant-id:", signatureObj.MerchantId);
                    _logger.Trace("{0} {1}", "Date:", signatureObj.GmtDateTime);
                    _logger.Trace("{0} {1}", "Host:", signatureObj.HostName);

                    if (_merchantConfig.IsPostRequest || _merchantConfig.IsPutRequest || _merchantConfig.IsPatchRequest)
                    {
                        _logger.Trace("{0} {1}", "digest:", signatureObj.Digest);
                    }

                    _logger.Trace("{0} {1}", "signature:", signatureObj.SignatureParam);

                    return(signatureObj);
                }

                return(null);
            }
            catch (Exception e)
            {
                ExceptionUtility.Exception(e.Message, e.StackTrace);
                return(null);
            }
        }
        public static void Run()
        {
            try
            {
                // Setting up Merchant Config
                var requestData = new RequestData();

                var merchantConfig = new MerchantConfig
                {
                    RequestTarget   = RequestTarget,
                    RequestType     = Enumerations.RequestType.PUT.ToString(),
                    RequestJsonData = requestData.JsonFileData(RequestJsonFilePath)
                };

                // Call to the Authorize class of AuthSDK to get the signature and token objects
                var authorizeObj = new Authorize(merchantConfig);

                if (string.Equals(merchantConfig.AuthenticationType, Enumerations.AuthenticationType.HTTP_SIGNATURE.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    var requestHeaders = authorizeObj.GetSignature();

                    Console.WriteLine("{0} {1}", "Content-Type:", "application/json");
                    Console.WriteLine("{0} {1}", "v-c-merchant-id:", requestHeaders.MerchantId);
                    Console.WriteLine("{0} {1}", "Date:", requestHeaders.GmtDateTime);
                    Console.WriteLine("{0} {1}", "Host:", requestHeaders.HostName);
                    Console.WriteLine("{0} {1}", "digest:", requestHeaders.Digest);
                    Console.WriteLine("{0} {1}", "signature:", requestHeaders.SignatureParam);
                }
                else if (string.Equals(merchantConfig.AuthenticationType, Enumerations.AuthenticationType.JWT.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    var requestHeaders = authorizeObj.GetToken();

                    Console.WriteLine("{0} {1}", "Content-Type:", "application/json");
                    Console.WriteLine("{0} {1}", "Authorization:", requestHeaders.BearerToken);
                }
            }
            catch (Exception e)
            {
                ExceptionUtility.Exception(e.Message, e.StackTrace);
            }
        }
        private void LogMerchantDetails()
        {
            try
            {
                // Using Request Target provided in the sample code/merchantconfig
                _logger.Trace("Using Request Target:'{0}'", _merchantConfig.RequestTarget);

                // logging Authentication type
                _logger.Trace("Authentication Type -> {0}", _merchantConfig.AuthenticationType);

                // logging Request Type
                _logger.Trace("Request Type -> {0}", _merchantConfig.RequestType);

                // Logging all the Properties of MerchantConfig and their respective Values
                _logger.Trace("MERCHCFG > {0}", MerchantConfig.LogAllproperties(_merchantConfig));
            }
            catch (Exception e)
            {
                ExceptionUtility.Exception(e.Message, e.StackTrace);
            }
        }