Esempio n. 1
0
        public async Task<TransferResponseDetailsModel> VoucherTranfer()
        {
            try
            {
                WriteLog("VoucherTranfer", "VoucherTranfer");
                TransferResponseDetailsModel model = new TransferResponseDetailsModel();
                string apiUrl = string.Empty;
                if (ConfigurationManager.AppSettings.AllKeys.Contains("ApiUrl")) // Key exists
                {
                    apiUrl = ConfigurationManager.AppSettings["ApiUrl"].ToString();
                    WriteLog("VoucherTranfer apiUrl", apiUrl);
                }
                else//Error log
                {
                }
                string rechargeType = Request.Form["rechargeType"];
                string serviceType = Request.Form["serviceType"];
                string operatorName = Request.Form["operatorCode"];
                string mobileNumber = Request.Form["mobileNumber"];
                string amount = Request.Form["amount"];
                string paymentID = Request.Form["paymentID"];
                string status = Request.Form["result"];
                string trackID = Request.Form["trackID"];
                string tranID = Request.Form["tranID"];
                string reference = Request.Form["ref"];
                using (var client = new HttpClient())
                {
                    #region login and get token
                    var logindata = string.Format("grant_type=password&username={0}&password={1}", USERNAME, PASSWORD);//LOGIN DATA

                    var url = BASEADDRESS + "token";

                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);
                    request.Content = new StringContent(logindata, Encoding.UTF8, "application/x-www-form-urlencoded");

                    var resp = client.PostAsync(url, request.Content);
                    Token token = new Token();
                    if (resp.Result.IsSuccessStatusCode)
                    {
                        token = await resp.Result.Content.ReadAsAsync<Token>();
                    }
                    #endregion login and get token
                    using (var httpClient = new HttpClient())
                    {
                        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token.token_type, token.access_token);
                        httpClient.BaseAddress = new Uri(BASEADDRESS);

                        string data = string.Format("?OperatorName={0}&Denomination={1}&MobileNo={2}", operatorName, amount, mobileNumber);
                        HttpResponseMessage response = await httpClient.GetAsync("api/Services/VoucherTransfer" + data);
                        if (response.IsSuccessStatusCode)
                        {
                            var result = await response.Content.ReadAsAsync<VoucherTransfer>();
                            if (result.Response.ToUpper() == "S")
                            {
                                model.Amount = Convert.ToDecimal(amount);
                                if (operatorName == "EZ")
                                {
                                    model.ImageURL = "/Content/img/Operators/zain.png";
                                }
                                else if (operatorName == "VV")
                                {
                                    model.ImageURL = "/Content/img/Operators/viva.png";
                                }
                                else if (operatorName == "XP")
                                {
                                    model.ImageURL = "/Content/img/Operators/ooreedo.png";
                                }

                                model.OperatorName = GetOperatorNameByOperatorCode(operatorName);
                                model.Response = result.Response;
                                model.RechargeCode = result.RechargeCode;
                                model.Denomination = result.Denomination;
                                model.Password = result.Password;
                                model.SerialNo = result.SerialNo;
                                if (ServiceType.DataCards.ToString() == serviceType)
                                {
                                    int datacardresponse = UpdateDataCardRechargeDetailsToDB(mobileNumber, rechargeType, operatorName, paymentID, status, trackID, tranID, reference, model);
                                    if (ConfigurationManager.AppSettings.AllKeys.Contains("ApiUrl")) // Key exists
                                    {
                                        apiUrl += "api/MessageApi/DataCardsSendMessage?MobileNumber=" + mobileNumber + "&OperatorCode=" + operatorName + "&RechargeCode=" + result.RechargeCode + "&Amount=" + amount + "&TranID=" + tranID;
                                        WriteLog("DataCards apiUrl", apiUrl);
                                        using (var clients = new WebClient())
                                        {
                                            var resFrmApi = JsonConvert.DeserializeObject<string>(clients.DownloadString(apiUrl));
                                        }
                                    }
                                }
                                else if (ServiceType.ShoppingCards.ToString() == serviceType)
                                {
                                    model.OperatorName = GetShoppingCardsOperatorName(operatorName);
                                    int id = UpdateShoppingCardDetailsToDB(mobileNumber, rechargeType, operatorName, paymentID, status, trackID, tranID, reference, model);
                                    if (ConfigurationManager.AppSettings.AllKeys.Contains("ApiUrl")) // Key exists
                                    {
                                        apiUrl += "api/MessageApi/ShoppingCardsSendMessage?MobileNumber=" + mobileNumber + "&OperatorCode=" + operatorName + "&RechargeCode=" + result.RechargeCode + "&Amount=" + amount + "&TranID=" + tranID;
                                        WriteLog("DataCards apiUrl", apiUrl);
                                        using (var clients = new WebClient())
                                        {
                                            var resFrmApi = JsonConvert.DeserializeObject<string>(clients.DownloadString(apiUrl));
                                        }
                                    }
                                }
                                else
                                { int id = UpdateRechargeDetailsToDB(mobileNumber, rechargeType, operatorName, paymentID, status, trackID, tranID, reference, model); }
                                if (ConfigurationManager.AppSettings.AllKeys.Contains("ApiUrl")) // Key exists
                                {
                                    apiUrl += "api/MessageApi/SendMessage?MobileNumber=" + mobileNumber + "&OperatorCode=" + operatorName + "&RechargeCode=" + result.RechargeCode + "&Amount=" + amount + "&TranID=" + tranID;
                                    WriteLog("VoucherTranfer apiUrl", apiUrl);
                                    using (var clients = new WebClient())
                                    {
                                        var resFrmApi = JsonConvert.DeserializeObject<string>(clients.DownloadString(apiUrl));
                                    }
                                }
                            }
                            else//Failed
                            {
                                if (ServiceType.DataCards.ToString() == serviceType)
                                {
                                    apiUrl += "api/MessageApi/DataCardsFailedMessage?MobileNumber=" + mobileNumber + "&OperatorCode=" + operatorName + "&TrackID=" + trackID; ;
                                    WriteLog("DataCards apiUrl failed ", apiUrl);
                                    using (var clients = new WebClient())
                                    {
                                        var resFrmApi = JsonConvert.DeserializeObject<string>(clients.DownloadString(apiUrl));
                                    }
                                }
                                else if (ServiceType.ShoppingCards.ToString() == serviceType)
                                {
                                    apiUrl += "api/MessageApi/ShoppingCardsFailedMessage?MobileNumber=" + mobileNumber + "&OperatorCode=" + operatorName + "&TrackID=" + trackID; ;
                                    WriteLog("ShoppingCards apiUrl failed ", apiUrl);
                                    using (var clients = new WebClient())
                                    {
                                        var resFrmApi = JsonConvert.DeserializeObject<string>(clients.DownloadString(apiUrl));
                                    }
                                }
                                else//Mobile Vouchers
                                {
                                    apiUrl += "api/MessageApi/FailedMessage?MobileNumber=" + mobileNumber + "&OperatorCode=" + operatorName + "&TrackID=" + trackID; ;
                                    WriteLog("VoucherTranfer apiUrl failed ", apiUrl);
                                    using (var clients = new WebClient())
                                    {
                                        var resFrmApi = JsonConvert.DeserializeObject<string>(clients.DownloadString(apiUrl));
                                    }
                                }
                            }
                        }
                    }
                }
                return model;
            }
            catch (Exception ex)
            {
                WriteLog("VoucherTranfer Exception ", ex.Message);
                throw ex;
            }
        }
Esempio n. 2
0
        public async Task<TransferResponseDetailsModel> BillPayment()
        {
            try
            {
                TransferResponseDetailsModel model = new TransferResponseDetailsModel();
                string rechargeType = Request.Form["rechargeType"];
                string operatorName = Request.Form["operatorCode"];
                string mobileNumber = Request.Form["mobileNumber"];
                string amount = Request.Form["amount"];
                string paymentID = Request.Form["paymentID"];
                string status = Request.Form["result"];
                string trackID = Request.Form["trackID"];
                string tranID = Request.Form["tranID"];
                string reference = Request.Form["ref"];
                using (var client = new HttpClient())
                {
                    #region login and get token
                    var logindata = string.Format("grant_type=password&username={0}&password={1}", USERNAME, PASSWORD);//LOGIN DATA

                    var url = BASEADDRESS + "token";

                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);
                    request.Content = new StringContent(logindata, Encoding.UTF8, "application/x-www-form-urlencoded");

                    var resp = client.PostAsync(url, request.Content);
                    Token token = new Token();
                    if (resp.Result.IsSuccessStatusCode)
                    {
                        token = await resp.Result.Content.ReadAsAsync<Token>();
                    }
                    #endregion login and get token
                    using (var httpClient = new HttpClient())
                    {
                        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token.token_type, token.access_token);
                        httpClient.BaseAddress = new Uri(BASEADDRESS);
                        string data = string.Format("?OperatorName={0}&AmtSelected={1}&MobileNumber={2}&PaymentType={3}", operatorName, amount, mobileNumber, "CASH");
                        HttpResponseMessage response = await httpClient.GetAsync("api/Services/BillPaymentTransfer" + data);
                        if (response.IsSuccessStatusCode)
                        {
                            var result = await response.Content.ReadAsAsync<BillPaymentTransfer>();
                            model.Amount = Convert.ToDecimal(amount);
                            model.Date = result.Date;
                            if (operatorName == "EZ")
                            {
                                model.ImageURL = "/Content/img/Operators/zain.png";
                            }
                            else if (operatorName == "VV")
                            {
                                model.ImageURL = "/Content/img/Operators/viva.png";
                            }
                            else if (operatorName == "XP")
                            {
                                model.ImageURL = "/Content/img/Operators/ooreedo.png";
                            }

                            model.OperatorName = GetOperatorNameByOperatorCode(operatorName);
                            model.PaymentID = result.PaymentID;
                            model.PaymentRef = result.PaymentRef;
                            model.Response = result.Response;
                            model.ResponseDescription = result.ResponseDescription;
                            int id = UpdateRechargeDetailsToDB(mobileNumber, rechargeType, operatorName, paymentID, status, trackID, tranID, reference, model);
                        }
                    }
                }
                return model;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
Esempio n. 3
0
        public int UpdateInternationalRechargeDetailsToDB(string mobileNumber, string rechargeType, string operatorCode, string paymentID, string status, string trackID, string tranID, string reference, TransferResponseDetailsModel result)
        {
            var model = context.InternationalRecharges.Create();
            try
            {

                model.MobileNumber = mobileNumber;
                model.amount = result.Amount;
                model.ServiceProvider = context.internationalServiceProviders.Where(x => x.Code == operatorCode).FirstOrDefault();
                //model.RechargeType = context.NationalRechargeTypes.Where(x => x.Name.Equals(rechargeType, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
                model.IsActive = true;
                model.IsDeleted = false;
                model.CreatedBy = 1;
                model.CreatedDate = DateTime.Now;
                model.CustomerID = 1;
                context.InternationalRecharges.Add(model);
                context.SaveChanges();

                var paymentDetail = context.InternationalRechargePaymentDetails.Create();
                paymentDetail.PaymentID = paymentID;
                paymentDetail.Result = status;
                paymentDetail.TrackID = trackID;
                paymentDetail.TransID = tranID;
                paymentDetail.Ref = reference;
                paymentDetail.InternationalRecharge = model;
                context.InternationalRechargePaymentDetails.Add(paymentDetail);

                var apiResponseDetail = context.InternationalRechargeAPIResponseDetails.Create();
                apiResponseDetail.InternationalRecharge = model;
                apiResponseDetail.PaymentID = result.PaymentID;
                apiResponseDetail.PaymentRef = result.PaymentRef;
                apiResponseDetail.Response = result.Response;
                apiResponseDetail.ResponseDescription = result.ResponseDescription;
                apiResponseDetail.Date = result.Date == DateTime.MinValue ? DateTime.Now : result.Date;
                context.InternationalRechargeAPIResponseDetails.Add(apiResponseDetail);
                context.SaveChanges();

            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            return model.ID;
        }
Esempio n. 4
0
        /// <summary>
        ///  Save recharge details to db.
        /// </summary>
        /// <param name="OperatorName"></param>
        /// <param name="CountryCode"></param>
        /// <param name="OperatorCode"></param>
        /// <param name="MobileNumber"></param>
        /// <param name="Amount"></param>
        /// <param name="PaymentType"></param>
        /// <returns></returns>
        public async Task<JsonResult> InternationalTopupTransfer()
        {
            TransferResponseDetailsModel model = new TransferResponseDetailsModel();
            try
            {

                using (var client = new HttpClient())
                {

                    string rechargeType = Request.Form["rechargeType"];
                    string operatorName = Request.Form["operatorCode"];
                    string mobileNumber = Request.Form["mobileNumber"];
                    string amount = Request.Form["amount"];
                    string paymentID = Request.Form["paymentID"];
                    string status = Request.Form["result"];
                    string trackID = Request.Form["trackID"];
                    string tranID = Request.Form["tranID"];
                    string reference = Request.Form["ref"];
                    string countryCode = Request.Form["countryCode"];
                    string operatorCode = Request.Form["operatorCode"];


                    #region login and get token

                    var logindata = string.Format("grant_type=password&username={0}&password={1}", USERNAME, PASSWORD);//LOGIN DATA

                    var url = BASEADDRESS + "token";

                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);
                    request.Content = new StringContent(logindata, Encoding.UTF8, "application/x-www-form-urlencoded");

                    var resp = await client.PostAsync(url, request.Content);
                    Token token = new Token();
                    if (resp.IsSuccessStatusCode)
                    {
                        token = await resp.Content.ReadAsAsync<Token>();
                    }
                    #endregion login and get token
                    #region call services test


                    using (var httpClient = new HttpClient())
                    {
                        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token.token_type, token.access_token);
                        httpClient.BaseAddress = new Uri(BASEADDRESS);


                        //TestWebServiceClient.ServiceReference2.InternationalTopupCheck obj1 = 
                        //(TestWebServiceClient.ServiceReference2.InternationalTopupCheck)WCTest.InternationalTopupCheck("IT/IN/VF/919645834359/2.000");
                        string data = string.Format("?OperatorName={0}&amount={1}&MobileNumber={2}&CountryCode={3}&OperatorCode={4}&PaymentType={5}",
                            "IT", amount, mobileNumber, countryCode, operatorCode, "CASH");
                        HttpResponseMessage response = await httpClient.GetAsync("api/Services/InternationalTopupTransfer" + data);

                        //first call InternationalTopupCheck
                        //Internation topup transfer


                        if (response.IsSuccessStatusCode)
                        {
                            var result = await response.Content.ReadAsAsync<TopupTransfer>();

                            model.PaymentID = result.PaymentID;
                            model.PaymentRef = result.PaymentRef;
                            model.Response = result.Response;
                            model.ResponseDescription = result.ResponseDescription;
                            model.Amount = Convert.ToDecimal(amount);
                            int id = UpdateInternationalRechargeDetailsToDB(mobileNumber, rechargeType, operatorName, paymentID, status, trackID, tranID, reference, model);

                        }
                        else
                        {
                            //MessageBox.Show(response.ReasonPhrase);
                        }

                    }


                    #endregion call services test

                }

            }
            catch (Exception ex)
            {

                throw;
            }
            return Json(model, JsonRequestBehavior.AllowGet);
        }
Esempio n. 5
0
        public int UpdateShoppingCardDetailsToDB(string mobileNumber, string rechargeType, string operatorCode, string paymentID, string status, string trackID, string tranID, string reference, TransferResponseDetailsModel result)
        {
            var model = context.ShoppingCards.Create();
            try
            {


                model.amount = result.Amount;
                model.ServiceProvider = context.ShoppingCardTypes.Where(x => x.Code == operatorCode).FirstOrDefault();
                //Set shopping Type card Id.
                model.ShoppingCardTypesID = model.ServiceProvider.ID;
                model.IsActive = true;
                model.IsDeleted = false;
                model.CreatedBy = 1;
                model.CreatedDate = DateTime.Now;
                model.CustomerID = 1;
                context.ShoppingCards.Add(model);
                context.SaveChanges();

                var paymentDetail = context.ShoppingCardPaymentDetails.Create();
                paymentDetail.PaymentID = paymentID;
                paymentDetail.Result = status;
                paymentDetail.TrackID = trackID;
                paymentDetail.TransID = tranID;
                paymentDetail.Ref = reference;
                paymentDetail.ShoppingCards = model;
                context.ShoppingCardPaymentDetails.Add(paymentDetail);

                var apiResponseDetail = context.ShoppingCardAPIResponseDetails.Create();
                apiResponseDetail.NationalRecharge = model;
                apiResponseDetail.Response = result.Response;
                apiResponseDetail.Denomination = result.Denomination;
                apiResponseDetail.Password = result.Password;
                apiResponseDetail.RechargeCode = result.RechargeCode;
                apiResponseDetail.SerialNo = result.SerialNo;
                context.ShoppingCardAPIResponseDetails.Add(apiResponseDetail);
                context.SaveChanges();

            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                            ve.PropertyName, ve.ErrorMessage);
                    }
                }
            }
            return model.ID;
        }