public ActionResult Index() { EndModel end = new EndModel(); try { //Request.Headers["referer"] perform referer check CCACrypto ccaCrypto = new CCACrypto(); string encResponse = ccaCrypto.Decrypt(Request.Form["encResp"], ConfigurationConstants.CCAVENUE_WORKING_KEY); NameValueCollection Params = new NameValueCollection(); string[] segments = encResponse.Split('&'); foreach (string seg in segments) { string[] parts = seg.Split('='); if (parts.Length > 0) { string Key = parts[0].Trim(); string Value = parts[1].Trim(); Params.Add(Key, Value); } } var entitiesInfo = new ThbLoginContextEntity(null).ThbEntities; string txnId = Params["merchant_param1"]; var record = entitiesInfo.PaymentInfoes.FirstOrDefault(cc => cc.TxnId.Equals(txnId) && cc.Status.Equals("Initiated")); if (record == null) { end.Result = "Invalid Transaction"; return(View(end)); } end.TransactionNumber = txnId; record.Response = "Decrypted Response " + encResponse + " " + Request.Form.ToString(); record.ResponseTime = DateTime.Now; if (Params["order_status"] == "Success") { { record.Status = "Success"; end.Result = "Successfully performed payment"; //Hash value did not matched } } else { record.Status = "Failure"; end.Result = "Bank Payment Failure"; // osc_redirect(osc_href_link(FILENAME_CHECKOUT, 'payment' , 'SSL', null, null,true)); } entitiesInfo.SaveChanges(); SendEmail(record, Params); } catch (Exception ex) { Response.Write("<span style='color:red'>" + ex.Message + "</span>"); } return(View(end)); }
public string GenerateUniqueId() { var entitiesInfo = new ThbLoginContextEntity(null).ThbEntities; Invoice invoice = new Invoice(); invoice.TimeStamp = DateTime.Now; invoice.Info = ""; invoice.SessionId = HttpContext.Session.SessionID; entitiesInfo.Invoices.Add(invoice); entitiesInfo.SaveChanges(); return(invoice.InvoiceNumber.ToString()); }
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); }