public bool GeneratePayOrder(PayOrder payOrder) { var sqlParamsList = new List <SqlParameter>(); var properties = payOrder.GetType().GetProperties(); foreach (var pro in properties) { sqlParamsList.Add(new SqlParameter() { ParameterName = string.Format("@{0}", pro.Name), Value = pro.GetValue(payOrder, null) }); } using (System.Data.Common.DbCommand cmd = Context.Database.Connection.CreateCommand()) { try { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "P_PAY_NewPayOrder"; cmd.Parameters.AddRange(sqlParamsList.ToArray()); if (cmd.Connection.State != ConnectionState.Open) { cmd.Connection.Open(); } cmd.ExecuteNonQuery(); return(true); } catch (Exception e) { LogHelper.Logger.Error(e.Message); return(false); } } }
public string Post(PayOrder payOrder, Guid orderId) { string[] hashVarsSeq; string hash_string = string.Empty; Random rnd = new Random(); string strHash = Generatehash512(rnd.ToString() + DateTime.Now); txnid1 = strHash.ToString().Substring(0, 20); hashVarsSeq = ConfigurationManager.AppSettings["hashSequence"].Split('|'); // spliting hash sequence from config hash_string = ""; var propArray = payOrder.GetType().GetProperties(); foreach (string hash_var in hashVarsSeq) { if (hash_var == "key") { hash_string = hash_string + ConfigurationManager.AppSettings["MERCHANT_KEY"]; hash_string = hash_string + '|'; } else if (hash_var == "txnid") { hash_string = hash_string + txnid1; hash_string = hash_string + '|'; } else if (hash_var == "amount") { hash_string = hash_string + Convert.ToDecimal(payOrder.amount).ToString("g29"); hash_string = hash_string + '|'; } else { string val = null; var prop = propArray.Where(p => p.Name == hash_var).FirstOrDefault(); if (prop != null) { val = prop.GetValue(payOrder).ToString(); } hash_string = hash_string + (val != null ? val : "");// isset if else hash_string = hash_string + '|'; } } hash_string += ConfigurationManager.AppSettings["SALT"]; // appending SALT hash1 = Generatehash512(hash_string).ToLower(); //generating hash action1 = ConfigurationManager.AppSettings["PAYU_BASE_URL"] + "/_payment"; // setting URL if (!string.IsNullOrEmpty(hash1)) { System.Collections.Hashtable data = new System.Collections.Hashtable(); // adding values in gash table for data post data.Add("hash", hash1); data.Add("txnid", txnid1); data.Add("key", ConfigurationManager.AppSettings["MERCHANT_KEY"]); string amount = Convert.ToDecimal(payOrder.amount).ToString("g29");// eliminating trailing zeros data.Add("amount", amount); data.Add("firstname", payOrder.firstname); data.Add("email", payOrder.email); data.Add("phone", payOrder.phone); data.Add("productinfo", payOrder.productinfo); data.Add("surl", payOrder.surl); data.Add("furl", ""); data.Add("lastname", ""); data.Add("curl", ""); data.Add("address1", ""); data.Add("address2", ""); data.Add("city", ""); data.Add("state", ""); data.Add("country", ""); data.Add("zipcode", ""); data.Add("udf1", ""); data.Add("udf2", ""); data.Add("udf3", ""); data.Add("udf4", ""); data.Add("udf5", ""); data.Add("pg", ""); data.Add("service_provider", payOrder.service_provider); string strForm = PreparePOSTForm(action1, data); Payment payment = new Payment(); payment.Amount = decimal.Parse(amount); OrderProvider.SavePayment(payment, orderId); return(strForm); } else { //no hash } return(string.Empty); }