public ActionResult ReceivePaymentNotification(string MerchantTxnId, string GatewayTxnId)
        {
            //check MerchantTxnId in our db first
            var dbRes = _iLoad.CheckTrnasactionExistence(MerchantTxnId, GatewayTxnId);

            if (dbRes.Code == ResponseCode.Success)
            {
                string apiusername  = ApplicationUtilities.GetAppConfigValue("apiusername");
                string apipasssword = ApplicationUtilities.GetAppConfigValue("apipasssword");
                string apisecretkey = ApplicationUtilities.GetAppConfigValue("apisecretkey");
                string merchantname = ApplicationUtilities.GetAppConfigValue("merchantname");
                string merchantid   = ApplicationUtilities.GetAppConfigValue("merchantid");
                try
                {
                    MiddleServiceRequest serviceCall = new MiddleServiceRequest("cgpay", apiusername, apipasssword, apisecretkey);
                    var resp = serviceCall.GetTransactionDetail(merchantid, merchantname, MerchantTxnId);

                    if (resp.code == "0")
                    {
                        var transactionModel       = ApplicationUtilities.MapObject <CheckTransactionResponse>(resp.data);
                        LoadBalanceCommon lBalance = new LoadBalanceCommon()
                        {
                            pmt_gateway_id     = "",
                            pmt_gateway_txn_id = GatewayTxnId,
                            gateway_status     = transactionModel.Status,
                            gateway_process_id = "",
                            action_user        = "******",
                            action_ip          = ApplicationUtilities.GetIP(),
                            bank_name          = transactionModel.Institution,
                            payment_mode       = transactionModel.Instrument,
                            pmt_txn_id         = MerchantTxnId,
                            amount             = transactionModel.Amount,
                            service_charge     = transactionModel.ServiceCharge
                        };
                        _iLoad.UpdateTransaction(lBalance);
                    }
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                    throw;
                }
            }
            Response.Write("Received");
            Response.End();
            return(View());



            // then check if transaction is already updated by merchanttxnid and gatewaytxnid



            //if transaction exists or already received or txn not found
            //return "Received";
            //
        }
        public ActionResult BankList()
        {
            string apiusername  = ApplicationUtilities.GetAppConfigValue("apiusername");
            string apipasssword = ApplicationUtilities.GetAppConfigValue("apipasssword");
            string apisecretkey = ApplicationUtilities.GetAppConfigValue("apisecretkey");
            string merchantname = ApplicationUtilities.GetAppConfigValue("merchantname");
            string merchantid   = ApplicationUtilities.GetAppConfigValue("merchantid");
            MiddleServiceRequest middlewareCall = new MiddleServiceRequest("cgpay", apiusername, apipasssword, apisecretkey, Session["UserName"].ToString());
            var response = middlewareCall.GetPaymentInstrumentDetail(merchantid, merchantname);
            var bankList = ApplicationUtilities.MapObjects <BankList>(response.data);

            return(View(bankList));
        }
        public ActionResult BulkUpload(HttpPostedFileBase bulk_upload)
        {
            string AgentId    = Session["AgentId"].ToString(),
                   ActionUser = Session["UserName"].ToString();
            //ApplicationUtilities.GetIP();
            var UploadFilePath = "";

            if (bulk_upload != null)
            {
                var    allowedExtensions = new[] { ".csv" };
                var    fileName          = Path.GetFileName(bulk_upload.FileName);
                String timeStamp         = DateTime.Now.ToString();
                var    ext = Path.GetExtension(bulk_upload.FileName);
                if (bulk_upload.ContentLength > 5 * 1024 * 1024)//1 MB
                {
                    TempData["msg"] = "file must be less than 5MB";
                    return(RedirectToAction("Index"));
                }
                if (allowedExtensions.Contains(ext.ToLower()))
                {
                    string ftpusername        = ApplicationUtilities.GetAppConfigValue("ftpusername");
                    string ftppassword        = ApplicationUtilities.GetAppConfigValue("ftppassword");
                    string ftpurl             = ApplicationUtilities.GetAppConfigValue("ftpurl");
                    string uploadfilelocation = ApplicationUtilities.GetAppConfigValue("uploadfilelocation");

                    string datet        = DateTime.Now.ToString().Replace('/', '_').Replace(':', '_').Replace(' ', '_');
                    string myfilename   = "bulkupload_" + datet + ext;
                    string FileLocation = uploadfilelocation + myfilename;//webconfig file location for db
                    UploadFilePath = Path.Combine(Server.MapPath("~/Content/userupload/bulkupload"), myfilename);
                    //UploadFilePath = Path.Combine(Server.MapPath(FileLocation), myfilename);
                    bulk_upload.SaveAs(UploadFilePath);

                    var client = new WebClient();
                    client.Credentials = new NetworkCredential(ftpusername, ftppassword);                     //web config username and password ftp
                    client.UploadFile(ftpurl + myfilename, WebRequestMethods.Ftp.UploadFile, UploadFilePath); //web config ftp url

                    var log  = _upload.LogFile(myfilename, FileLocation, ActionUser);
                    var resp = _upload.BulkUpload(myfilename, FileLocation, ActionUser, AgentId);
                    //shared.Models.ResponseCode.Success
                    if (resp.Code == 0)
                    {
                        string ProcessId = resp.Extra1;
                        string FileName  = resp.Extra2;

                        return(RedirectToAction("GetErrorDataList", new { ProcessId = ProcessId, FileName = FileName }));
                    }
                    else
                    {
                        TempData["msg"] = resp.Message;
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    TempData["msg"] = "File Must be .csv";
                    return(RedirectToAction("Index"));
                }
            }

            TempData["msg"] = "File is required";


            //ViewBag.data = ErrorList;
            //TempData["msg"] = "successfully uploaded";
            return(RedirectToAction("Index"));
        }
        public ActionResult ReceivePaymentResponse(string MerchantTxnId, string GatewayTxnId)
        {
            if (string.IsNullOrEmpty(MerchantTxnId) && string.IsNullOrEmpty(GatewayTxnId))
            {
                CommonDbResponse            dbRes     = new CommonDbResponse();
                ViewTransactionReponseModel viewModel = new ViewTransactionReponseModel();


                viewModel.code           = 1;
                viewModel.Message        = "Tranasaction Failed";
                viewModel.gateway_status = "Failed";
                //dbRes.SetMessageInTempData(this);
                return(View(viewModel));
            }
            string                      apiusername  = ApplicationUtilities.GetAppConfigValue("apiusername");
            string                      apipasssword = ApplicationUtilities.GetAppConfigValue("apipasssword");
            string                      apisecretkey = ApplicationUtilities.GetAppConfigValue("apisecretkey");
            string                      merchantname = ApplicationUtilities.GetAppConfigValue("merchantname");
            string                      merchantid   = ApplicationUtilities.GetAppConfigValue("merchantid");
            CommonDbResponse            dbResponse   = new CommonDbResponse();
            ViewTransactionReponseModel model        = new ViewTransactionReponseModel();

            try
            {
                MiddleServiceRequest serviceCall = new MiddleServiceRequest("cgpay", apiusername, apipasssword, apisecretkey, Session["UserName"].ToString());
                var resp = serviceCall.GetTransactionDetail(merchantid, merchantname, MerchantTxnId);

                //if (resp != null && resp.code == "0" && resp.data.Status.ToLower() == "success" )
                //{
                //    dbResponse = _iLoad.GetTransactionReposne(MerchantTxnId, GatewayTxnId);
                //    if (dbResponse.Code == ResponseCode.Success)
                //    {
                //        model = ApplicationUtilities.MapObject<ViewTransactionReponseModel>(dbResponse.Data);
                //        model.code = int.Parse(resp.code);
                //        return View(model);
                //    }
                //    else
                //    {
                //        //dbResponse.SetMessageInTempData(this);
                //        model.code = 1;
                //        return View(model);
                //    }
                //}
                //else if (resp != null && resp.code == "0" && resp.data.Status.ToLower() == "fail")
                //{

                //    model.code = 1;
                //    model.Message = "Tranasaction Failed";
                //    //dbResponse.SetMessageInTempData(this);
                //    return View(model);
                //}
                //else if (resp != null && resp.code == "1")
                //{
                //    dbResponse.Code = ResponseCode.Failed;
                //    dbResponse.Message = resp.message;
                //    dbResponse.SetMessageInTempData(this);
                //    model.code = int.Parse(resp.code);
                //    return View(model);
                //}
                //else
                //{
                //    dbResponse.Code = ResponseCode.Failed;
                //    dbResponse.Message = "Service Call Failed";
                //    dbResponse.SetMessageInTempData(this);
                //    model.code = 1;
                //    return View(model);
                //}
                if (resp != null && resp.code == "0")
                {
                    dbResponse = _iLoad.GetTransactionReposne(MerchantTxnId, GatewayTxnId);
                    if (dbResponse.Code == ResponseCode.Success)
                    {
                        model      = ApplicationUtilities.MapObject <ViewTransactionReponseModel>(dbResponse.Data);
                        model.code = int.Parse(resp.code);
                        return(View(model));
                    }
                    else
                    {
                        model.code           = 1;
                        model.Message        = "Transaction status failed.";
                        model.gateway_status = "Failed";
                        return(View(model));
                    }
                }
                else if (resp != null && resp.code == "1")
                {
                    //dbResponse.Code = ResponseCode.Failed;
                    model.Message        = "Transaction status failed.";
                    model.gateway_status = "Failed";
                    model.code           = 1;
                    return(View(model));
                }
                else
                {
                    //dbResponse.Code = ResponseCode.Failed;
                    model.Message        = "Transaction status failed.";
                    model.gateway_status = "Failed";
                    model.code           = 1;
                    return(View(model));
                }
            }
            catch (Exception)
            {
                //dbResponse.Code = ResponseCode.Failed;
                model.Message        = "Transaction status failed.";
                model.gateway_status = "Failed";
                //dbResponse.SetMessageInTempData(this);
                model.code = 1;
                return(View(model));
            }
        }
        public ActionResult LoadBalanceIndex(LoadBalanceModel balance)
        {
            CommonDbResponse dbResponse = new CommonDbResponse();
            var dbLimits = _iLoad.GetTransactionLimit(Session["AgentId"].ToString());
            var limits   = dbLimits.Data.MapObject <LoadBalanceModel>();

            if (Convert.ToInt32(balance.amount) < 10 || Convert.ToInt32(balance.amount) > 100000)
            {
                return(View(limits));
            }

            //if (
            //    int.Parse(balance.amount) > limits.transactiondailylimitmax
            //    || int.Parse(balance.amount) > limits.transactionmonthlylimitmax
            //    )
            //{
            //    dbResponse.Code = ResponseCode.Failed;
            //    dbResponse.Message = "Amount Exceeded Transaction Limit";
            //    dbResponse.SetMessageInTempData(this);
            //    return View(limits);
            //}
            if (int.Parse(balance.amount) > limits.transactiondailylimitmax && int.Parse(balance.amount) <= limits.transactionmonthlylimitmax)
            {
                dbResponse.Code    = ResponseCode.Failed;
                dbResponse.Message = "Amount Exceeded Daily Transaction Limit";
                dbResponse.SetMessageInTempData(this);
                return(View(limits));
            }
            if (int.Parse(balance.amount) > limits.transactionmonthlylimitmax)
            {
                dbResponse.Code    = ResponseCode.Failed;
                dbResponse.Message = "Amount Exceeded Monthly Transaction Limit";
                dbResponse.SetMessageInTempData(this);
                return(View(limits));
            }


            LoadBalanceCommon ld = new LoadBalanceCommon();

            if (ModelState.IsValid)
            {
                balance.action_user    = Session["UserName"].ToString();
                balance.action_ip      = ApplicationUtilities.GetIP();
                balance.action_browser = HttpContext.Request.Browser.ToString();



                ld         = balance.MapObject <LoadBalanceCommon>();
                dbResponse = _iLoad.LoadBalance(ld);
                if (dbResponse.Code == ResponseCode.Success)
                {
                    string apiusername  = ApplicationUtilities.GetAppConfigValue("apiusername");
                    string apipasssword = ApplicationUtilities.GetAppConfigValue("apipasssword");
                    string apisecretkey = ApplicationUtilities.GetAppConfigValue("apisecretkey");
                    string merchantname = ApplicationUtilities.GetAppConfigValue("merchantname");
                    string merchantid   = ApplicationUtilities.GetAppConfigValue("merchantid");

                    try
                    {
                        MiddleServiceRequest middlewareCall = new MiddleServiceRequest("cgpay", apiusername, apipasssword, apisecretkey, Session["UserName"].ToString());
                        var response = middlewareCall.GetFormObject(merchantid, merchantname, dbResponse.Extra1, balance.amount, dbResponse.Extra2, balance.instrument_code);
                        if (response != null && response.code == "0")
                        {
                            var formString = ApplicationUtilities.MapObject <MiddlewareResponse.FormDataObject>(response.data);
                            Response.Write(formString.FormData);
                            Response.End();
                        }
                        else if (response != null && response.code == "1")
                        {
                            dbResponse.Code    = ResponseCode.Failed;
                            dbResponse.Message = response.message;
                            // dbResponse.SetMessageInTempData(this);
                            return(View(limits));
                        }
                        else
                        {
                            dbResponse.Code    = ResponseCode.Failed;
                            dbResponse.Message = "Service Call Failed";
                            //dbResponse.SetMessageInTempData(this);
                            return(View(limits));
                        }
                    }
                    catch (Exception)
                    {
                        dbResponse.Code    = ResponseCode.Failed;
                        dbResponse.Message = "Service Call Failed";
                        // dbResponse.SetMessageInTempData(this);
                        return(View(limits));
                    }
                }
                //dbResponse.SetMessageInTempData(this);
                return(View(limits));
            }

            return(View(limits));
        }