public ActionResult Index(FormCollection form) { StartModel obj = new StartModel() { SubmitButtonVisible = true }; if (ModelState.IsValid) { try { if (TryUpdateModel(obj)) { surl = Request.Url.Scheme + "://" + Request.Url.Authority + surl; curl = Request.Url.Scheme + "://" + Request.Url.Authority + curl; furl = Request.Url.Scheme + "://" + Request.Url.Authority + furl; PerformPostBack(obj); } } catch (OverflowException) { ModelState.AddModelError("Amount", "Please Enter Lower Amount Value"); } } return(View(obj)); }
private StartModel PerformPostBack(StartModel obj) { try { var entitiesInfo = new ThbLoginContextEntity(null).ThbEntities; var paymentInfo = new PaymentInfo(); if (string.IsNullOrEmpty(Request.Form["txnid"])) // generating txnid { Random rnd = new Random(); string strHash = Generatehash512(rnd.ToString() + DateTime.Now); txnid1 = strHash.ToString().Substring(0, 20); } else { txnid1 = Request.Form["txnid"]; } if ( string.IsNullOrEmpty(ConfigurationConstants.MERCHANT_ID) || string.IsNullOrEmpty(txnid1) || (obj.Amount <= 0) || string.IsNullOrEmpty(obj.Name) || string.IsNullOrEmpty(obj.Email) || string.IsNullOrEmpty(obj.Phone) || string.IsNullOrEmpty(obj.InvoiceNumber) || string.IsNullOrEmpty(obj.ProductInfo) ) { //error obj.ErrorMessage = true; return(obj); } else { obj.ErrorMessage = false; action1 = ConfigurationConstants.CCAVENUE_URL; } { txnid = txnid1; System.Collections.Hashtable data = new System.Collections.Hashtable(); // adding values in gash table for data post data.Add("merchant_param1", txnid); string AmountForm = Convert.ToDecimal(obj.Amount).ToString("g29"); // eliminating trailing zeros data.Add("order_id", obj.InvoiceNumber); data.Add("currency", obj.Currency); data.Add("amount", obj.Amount); data.Add("billing_name", obj.Name); data.Add("merchant_id", ConfigurationConstants.MERCHANT_ID); data.Add("billing_email", obj.Email); data.Add("billing_tel", obj.Phone); data.Add("redirect_url", surl.Trim()); data.Add("cancel_url", curl.Trim()); string inputRequest = ""; string strForm = PreparePOSTForm(action1, data, ref inputRequest); paymentInfo.TxnId = txnid; paymentInfo.Amount = Convert.ToDecimal(AmountForm); paymentInfo.Name = obj.Name.Trim(); paymentInfo.Email = obj.Email.Trim(); paymentInfo.ProductInfo = obj.ProductInfo.Trim(); paymentInfo.InvoiceNumber = obj.InvoiceNumber.Trim(); paymentInfo.Status = "Initiated"; paymentInfo.Phone = obj.Phone.Trim(); paymentInfo.Response = ""; paymentInfo.Request = inputRequest; paymentInfo.CreatedOn = DateTime.Now; paymentInfo.ModifiedOn = DateTime.Now; paymentInfo.Browser = Request.Browser == null ? "" : Request.Browser.Browser; paymentInfo.MachineIp = GetIPAddress(Request); paymentInfo.Currency = obj.Currency; entitiesInfo.PaymentInfoes.Add(paymentInfo); entitiesInfo.SaveChanges(); ViewData["InvoiceNumber"] = null; obj.Html = strForm; } } catch (Exception ex) { Response.Write("<span style='color:red'>" + ex.Message + "</span>"); } return(obj); }