protected void Page_Load(object sender, EventArgs e)
 {
     //EmailUtil.CreateSupportTicket("*****@*****.**", "Sample Test Ticket", "Yes this is working ...");
     //com.fokatdeals.recharge.CommonDAL dal = new com.fokatdeals.recharge.CommonDAL();
     //Response.Write(dal.HttpGet(com.fokatdeals.recharge.AppConstant.GET_BALANCE_API + "?uid=9407393303&pwd=demo@123"));
     //Response.Write(com.fokatdeals.recharge.AppConstant.GET_ALL_OPERATORS());
     //Response.Write(dal.HttpGet(com.fokatdeals.recharge.AppConstant.GET_OPERATOR_API("8269")));
     PayUMoneyHandler p = new PayUMoneyHandler("PO00019391", "100", "Mayank", "*****@*****.**", "2481355", "ProductInfo", "http://localhost:8080/paymentResponse.aspx", "http://localhost:8080/paymentResponseFail.aspx");
     Page.Controls.Add(new LiteralControl(PayUService.RequestToPayUMoney(p)));
 }
        public static String RequestPayUMoney(String mn, String op, String amt)
        {
            RechargeDAL dal = new RechargeDAL();
            try
            {
                String orderid = "REC-"+System.DateTime.Now.Ticks.ToString();
                String productInfo = amt + "/- recharge on " + mn + " mobile number for operator code "+op+" on " + System.DateTime.Now;
                String userid = HttpContext.Current.Session[AppConstants.SESSION_USER_ID].ToString();
                String username = HttpContext.Current.Session[AppConstants.SESSION_USERNAME].ToString();
                String email = HttpContext.Current.Session[AppConstants.SESSION_EMAIL_ID].ToString();
                int i = dal.InsertRecharge(orderid, userid, mn, amt, productInfo, op);
                if (i == 0 || i == -2)
                {
                    HttpContext.Current.Session[RechargeDAL.SESSION_REC_ORDER] = orderid;
                    PayUMoneyHandler p = new PayUMoneyHandler(orderid, amt, username, email, mn, productInfo, AppConstants.RECHARGE_SUCCESS_URL, AppConstants.RECHARGE_FAIL_URL);
                    return PayUService.RequestToPayUMoney(p);
                }
                else {
                    return null;
                }
            }
            catch
            {
                HttpContext.Current.Session[RechargeDAL.SESSION_AMT] = amt;
                HttpContext.Current.Session[RechargeDAL.SESSION_MN] = mn;
                HttpContext.Current.Session[RechargeDAL.SESSION_OPCODE] = op;
                return null;
            }

        }
        public static String RequestToPayUMoney(PayUMoneyHandler payU)
        {
            try
            {
                string[] hashVarsSeq;
                string hash_string = string.Empty;
                string action1 = string.Empty;
                string hash1 = string.Empty;

                hashVarsSeq = ConfigurationManager.AppSettings["hashSequence"].Split('|'); // spliting hash sequence from config
                hash_string = "";
                hash_string = hash_string + payU.MERCHANT_KEY + "|" + payU.ORDER_ID + "|" + payU.AMOUNT + "|" + payU.PRODUCT_INFO + "|" + payU.FIRSTNAME + "|" + payU.EMAIL + "|||||||||||";
                hash_string += ConfigurationManager.AppSettings["SALT"];// appending SALT

                hash1 = AppConstant.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(AppConstant.HASH, hash1);
                    data.Add(AppConstant.ORDER_ID, payU.ORDER_ID);
                    data.Add(AppConstant.MERCHANT_KEY, payU.MERCHANT_KEY);
                    string AmountForm = Convert.ToDecimal(payU.AMOUNT).ToString("g29");// eliminating trailing zeros
                    data.Add(AppConstant.AMOUNT, AmountForm);
                    data.Add(AppConstant.FIRST_NAME, payU.FIRSTNAME);
                    data.Add(AppConstant.EMAIL, payU.EMAIL);
                    data.Add(AppConstant.PHONE, payU.PHONE);
                    data.Add(AppConstant.PRODUCT_INFO, payU.PRODUCT_INFO.Trim());
                    data.Add(AppConstant.SUCCESS_URL, payU.SUCCESS_URL.Trim());
                    data.Add(AppConstant.FAILURE_URL, payU.FAILURE_URL.Trim());
                    data.Add(AppConstant.LAST_NAME, payU.lastName.Trim());
                    data.Add(AppConstant.CANCLE_URL, "");
                    data.Add(AppConstant.ADDRESS1, "");
                    data.Add(AppConstant.ADDRESS2, "");
                    data.Add(AppConstant.CITY, "");
                    data.Add(AppConstant.STATE, "");
                    data.Add(AppConstant.COUNTRY, "");
                    data.Add(AppConstant.ZIPCODE, "");
                    data.Add(AppConstant.EXTRA1, "");
                    data.Add(AppConstant.EXTRA2, "");
                    data.Add(AppConstant.EXTRA3, "");
                    data.Add(AppConstant.EXTRA4, "");
                    data.Add(AppConstant.EXTRA5, "");
                    data.Add(AppConstant.EXTRA6, "");
                    data.Add(AppConstant.SERVICE_PROVIDER, payU.SERVICE_PROVIDER);


                    string strForm = PreparePOSTForm(action1, data);
                    return strForm;

                }

                else
                {
                    //no hash
                    return "Data is not valid to process transaction";
                }
            }

            catch (Exception ex)
            {
                return "<span style='color:red'>" + ex.Message + "</span>";
            }
        }
 public static PayUMoneyHandler ResponseFromPayUMoney(HttpRequest request)
 {
     string[] merc_hash_vars_seq;
     PayUMoneyHandler payU = new PayUMoneyHandler();
     if (request.Form["status"] == "success")
     {
         merc_hash_vars_seq = ConfigurationManager.AppSettings["hashSequence"].Split('|');
         Array.Reverse(merc_hash_vars_seq);
         foreach (string merc_hash_var in merc_hash_vars_seq)
         {
             if (merc_hash_var == AppConstant.PHONE)
             {
                 payU.PHONE = request.Form[merc_hash_var];
             }
             else if (merc_hash_var == AppConstant.EMAIL)
             {
                 payU.EMAIL = request.Form[merc_hash_var];
             }
             else if (merc_hash_var.Equals(AppConstant.FIRST_NAME))
             {
                 payU.FIRSTNAME = request.Form[merc_hash_var];
             }
             else if (merc_hash_var.Equals(AppConstant.PRODUCT_INFO))
             {
                 payU.PRODUCT_INFO = request.Form[merc_hash_var];
             }
             else if (merc_hash_var.Equals(AppConstant.AMOUNT))
             {
                 payU.AMOUNT = request.Form[merc_hash_var];
             }
             else if (merc_hash_var.Equals(AppConstant.ORDER_ID))
             {
                 payU.ORDER_ID = request.Form[merc_hash_var];
             }
         }
         return payU;
     }
     else
     {
         return null;
     }
     
 }