protected void Page_Load(object sender, EventArgs e) { //Random rand = new Random((int)DateTime.Now.Ticks); //int numIterations = 0; //numIterations = rand.Next(1, 10000); //vpc_MerchTxnRef.Text = numIterations.ToString(); vpc_MerchTxnRef.Text = (CIBDonor.GetMaxId() + 1).ToString(); }
protected void Page_Load(object sender, EventArgs e) { string merchant_reference = Request.QueryString["merchant_reference"]; Label_MerchTxnRef.Text = merchant_reference; string customer_email = Request.QueryString["customer_email"]; Label_OrderInfo.Text = customer_email; string amount = Request.QueryString["amount"]; decimal FinalAmount = decimal.Parse(amount) / 100; Label_Amount.Text = FinalAmount.ToString() + "EGP"; string response_message = Request.QueryString["response_message"]; Label_Message.Text = response_message; string payment_option = Request.QueryString["payment_option"]; Label_CardType.Text = payment_option; string currency = Request.QueryString["currency"]; Label_HashValidation.Text = currency; string Name = Request.QueryString["customer_name"]; string valdate = ""; valdate += string.Format("PASSaccess_code={0}", Request.QueryString["access_code"]); valdate += string.Format("amount={0}", Request.QueryString["amount"]); valdate += string.Format("authorization_code={0}", Request.QueryString["authorization_code"]); valdate += string.Format("card_number={0}", Request.QueryString["card_number"]); valdate += string.Format("command=PURCHASE"); valdate += string.Format("currency=EGP"); valdate += string.Format("customer_email={0}", Request.QueryString["customer_email"]); valdate += string.Format("customer_ip={0}", Request.QueryString["customer_ip"]); valdate += string.Format("eci={0}", Request.QueryString["eci"]); valdate += string.Format("expiry_date={0}", Request.QueryString["expiry_date"]); valdate += string.Format("fort_id={0}", Request.QueryString["fort_id"]); valdate += string.Format("language=en"); valdate += string.Format("merchant_identifier=KllumJVP"); valdate += string.Format("merchant_reference={0}", Request.QueryString["merchant_reference"]); valdate += string.Format("order_description={0}", Request.QueryString["order_description"]); valdate += string.Format("payment_option={0}", Request.QueryString["payment_option"]); valdate += string.Format("response_code={0}", Request.QueryString["response_code"]); valdate += string.Format("response_message={0}", Request.QueryString["response_message"]); valdate += string.Format("status={0}PASS", Request.QueryString["status"]); if (Page.Request.QueryString["response_message"] == "Success") { if (GetSha256FromString(valdate) == Page.Request.QueryString["signature"]) { Literal2.Text = "Correct"; CIBDonor obj = new CIBDonor(); obj.Amount = FinalAmount; obj.IsApproved = true; obj.MerchAddress = ""; obj.MerchCountry = ""; obj.MerchEmail = customer_email; obj.MerchName = Name; obj.MerchPhone = ""; obj.MerchPostCode = ""; obj.MerchRef = int.Parse(merchant_reference); obj.MerchState = ""; obj.Project = Request.QueryString["order_description"]; obj.DonateTime = DateTime.Now; obj.Insert(); } else { Literal3.Text = "Mismatch"; } } else { Literal3.Text = "The operation failed"; CIBDonor obj = new CIBDonor(); obj.Amount = FinalAmount; obj.IsApproved = false; obj.MerchAddress = ""; obj.MerchCountry = ""; obj.MerchEmail = customer_email; obj.MerchName = Name; obj.MerchPhone = ""; obj.MerchPostCode = ""; obj.MerchRef = int.Parse(merchant_reference); obj.MerchState = ""; obj.Project = Request.QueryString["order_description"]; obj.DonateTime = DateTime.Now; obj.Insert(); } }
protected void SubButL_Click(object sender, EventArgs e) { string clientIp = (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? Request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim(); bool isHuman = ExampleCaptcha.Validate(CaptchaCodeTextBox.Text); CaptchaCodeTextBox.Text = null; // clear previous user input if (!isHuman) { // TODO: Captcha validation failed, show error message lbl_capcha.Text = "من فضلك ادخل الحروف مرة اخرى"; lbl_capcha.ForeColor = System.Drawing.Color.Red; } else { if (Visa.Checked == false && Master.Checked == false) { lbl_ERROR.Text = "من فضلك إختر نوع الكارت"; } else { if (Visa.Checked) { Radio.Text = "Visa"; } else if (Master.Checked) { Radio.Text = "MasterCard"; } //Dictionary of the parameters sent with the http request. var parameters = new Dictionary <string, string>(); decimal FinalAmount = decimal.Parse(Amount.Text) * 100; parameters.Add("amount", FinalAmount.ToString()); parameters.Add("currency", "EGP"); parameters.Add("merchant_identifier", "vftBmzKl"); parameters.Add("access_code", "X9nbMqo2ZSyXdQwoqBkT"); parameters.Add("order_description", drop_Project.SelectedValue); int refe = CIBDonor.GetMaxId() + 5; string refrence = refe.ToString(); parameters.Add("merchant_reference", refrence); parameters.Add("customer_email", txtmail.Text); //parameters.Add("customer_ip", clientIp); parameters.Add("language", "en"); //parameters.Add("Project", drop_Project.SelectedItem.ToString()); parameters.Add("command", "PURCHASE"); //parameters.Add("return_url", "http://www.dar-alorman.com/donateCIB/CS_VPC_3Party_DR.aspx"); //parameters.Add("customer_name", txtname.Text); var sortedParameters = parameters.OrderBy(x => x.Key); var stringSortedParameteres = sortedParameters.Aggregate("PASS", (current, item) => current + (item.Key + "=" + item.Value)); stringSortedParameteres += "PASS"; string hashedSignature = String.Empty; var crypt = SHA256.Create(); string hash = string.Empty; var crypto = crypt.ComputeHash(Encoding.ASCII.GetBytes(stringSortedParameteres), 0, Encoding.ASCII.GetByteCount(stringSortedParameteres)); hash = crypto.Aggregate(hash, (current, b) => current + b.ToString("x2")); parameters.Add("signature", hash); var temp = parameters.Select(d => string.Format("\"{0}\": \"{1}\"", d.Key, string.Join(",", d.Value))); var jsonRequestString = "{" + string.Join(",", temp) + "}"; var data = Encoding.ASCII.GetBytes(jsonRequestString); var parameterValues = new NameValueCollection(); foreach (var item in parameters) { parameterValues.Add(item.Key, item.Value); } RedirectWithData("https://checkout.payfort.com/FortAPI/paymentPage", parameterValues); } } }