Ejemplo n.º 1
0
        private static string postingsUrl = System.Configuration.ConfigurationManager.AppSettings["ISO8583APIUrl"];// "http://localhost:9050/api/Iso8583/";//config
        public static async Task <bool> ProcessReversal(string institutionCode, string originalDataElements)
        {
            try
            {
                string              uniqueIdentifier   = Guid.NewGuid().ToString();
                string              publishInfoMessage = null;
                PublisherAPI        redisAPI           = new PublisherAPI(ConfigurationManager.AppSettings["ISOChannelName"]);
                TempClassForPublish publishInfo        = null;
                publishInfo = new TempClassForPublish
                {
                    Institution     = institutionCode,
                    UniqueId        = uniqueIdentifier,
                    IsResponse      = "false",
                    PostingResponse = "About to Post",
                    PostingType     = "6"
                };
                publishInfoMessage = TempClassForPublish.ConvertToCommaSeparated(publishInfo, "1", "");
                redisAPI.APIMethod(PublisherAPI.ConvertObjectToString(publishInfoMessage));
                string postingsMiddlewareUrl = PostingsMiddleware.GetPostingsURL(institutionCode);
                if (!string.IsNullOrEmpty(postingsMiddlewareUrl))
                {
                    System.Diagnostics.Trace.TraceInformation($"Redirect URI - {postingsMiddlewareUrl}");
                    try
                    {
                        postingsUrl = $"{postingsMiddlewareUrl.Split(new string[] { "api" }, StringSplitOptions.RemoveEmptyEntries)[0]}api/Iso8583/";
                        System.Diagnostics.Trace.TraceInformation($"Redirect URI - {postingsUrl}");
                    }
                    catch
                    {
                    }
                }
                else
                {
                    System.Diagnostics.Trace.TraceInformation($"Default URI - {postingsUrl}");
                }
                string uri = $"{postingsUrl}DoTransactionReversalByUniqueIdentifier?mfbCode={institutionCode}&uniqueIdentifier={originalDataElements}";
                System.Diagnostics.Trace.TraceError($"URI is {uri}");
                using (var request = new WebClient())
                {
                    request.Headers[HttpRequestHeader.Accept]      = "application/json";
                    request.Headers[HttpRequestHeader.ContentType] = "application/json";
                    //request.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);
                    string response = await request.UploadStringTaskAsync(new Uri(uri), "POST", "");

                    System.Diagnostics.Trace.TraceError($"response is {response}");
                    var reversalSuccess = JsonConvert.DeserializeObject <bool>(response);
                    publishInfo = new TempClassForPublish
                    {
                        Institution     = institutionCode,
                        UniqueId        = uniqueIdentifier,
                        IsResponse      = "true",
                        PostingResponse = reversalSuccess ? "Successfull" : "Failed",
                        PostingType     = "6"
                    };
                    publishInfoMessage = TempClassForPublish.ConvertToCommaSeparated(publishInfo, "2", reversalSuccess ? "00" : "06");
                    redisAPI.APIMethod(PublisherAPI.ConvertObjectToString(publishInfoMessage));

                    publishInfoMessage = TempClassForPublish.ConvertToCommaSeparated(publishInfo, "3", reversalSuccess ? "00" : "06");
                    redisAPI.APIMethod(PublisherAPI.ConvertObjectToString(publishInfoMessage));
                    if (reversalSuccess)
                    {
                        return(reversalSuccess);
                    }
                    throw new Exception("Reversal was dishonoured");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError(String.Format("{0} : {1}", ex.Message, ex.StackTrace));
                throw ex;
                //return false;
            }
        }
Ejemplo n.º 2
0
 public static string ConvertToCommaSeparated(TempClassForPublish publishInfo, string stage, string errorCode)
 {
     return(string.Join(",", new string[] { publishInfo.Institution, publishInfo.UniqueId, DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss:fffffff tt"),
                                            publishInfo.IsResponse, publishInfo.PostingResponse, publishInfo.PostingType, stage, errorCode }));
 }