Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class MyGlobalVariables
- {
- public static int TokenChoice
- {
- get
- {
- if (System.Web.HttpContext.Current.Session["TokenChoice"] == null)
- {
- return -1;
- }
- else
- {
- return (int)System.Web.HttpContext.Current.Session["TokenChoice"];
- }
- }
- set
- {
- System.Web.HttpContext.Current.Session["TokenChoice"] = value;
- }
- }
- public static int PaymentChoice
- {
- get
- {
- if (System.Web.HttpContext.Current.Session["PaymentChoice"] == null)
- {
- return -1;
- }
- else
- {
- return (int)System.Web.HttpContext.Current.Session["PaymentChoice"];
- }
- }
- set
- {
- System.Web.HttpContext.Current.Session["PaymentChoice"] = value;
- }
- }
- public static string CurrentUser
- {
- get
- {
- System.Web.HttpContext.Current.Session["CurrentUser"] = System.Web.HttpContext.Current.User.Identity.Name;
- return (string)System.Web.HttpContext.Current.Session["CurrentUser"];
- }
- }
- }
- public ActionResult Payment(int tokenChoice, int paymentChoice)
- {
- ViewData["_CurrentUser"] =
- System.Web.HttpContext.Current.Session["_CurrentUser"] = User.Identity.Name;
- ViewBag.Payment = paymentChoice;
- MyGlobalVariables.PaymentChoice = paymentChoice;
- MyGlobalVariables.TokenChoice = tokenChoice;
- return View();
- }
- [HttpPost]
- public ActionResult Payment()
- {
- NameValueCollection nvc = Request.Form;
- Trace.WriteLine("Http_Hmac: " + HTTP_HMAC);
- Trace.WriteLine("ipn_mode: " + nvc["ipn_mode"]);
- Trace.WriteLine("currency1: " + nvc["currency1"]);
- Trace.WriteLine("txn id: " + nvc["txn_id"]);
- var merchant_id = "9750af22c5fb6321c05fb0b4befb9ac1";
- var ipn_secret = "xxkuki1212xx";
- var order_total = MyGlobalVariables.PaymentChoice;
- if (String.IsNullOrEmpty(nvc["ipn_mode"]) || nvc["ipn_mode"] != "hmac")
- {
- Trace.WriteLine("IPN Mode is not HMAC");
- return View();
- }
- if (String.IsNullOrEmpty(HTTP_HMAC))
- {
- Trace.WriteLine("No HMAC signature sent");
- return View();
- }
- if (String.IsNullOrEmpty(nvc["merchant"]) || nvc["merchant"] != merchant_id.Trim())
- {
- Trace.WriteLine("No or incorrect Merchant ID passed");
- return View();
- }
- //var hmac = hash_hmac("sha512", request, ipn_secret.Trim());
- var txn_id = nvc["txn_id"];
- var item_name = nvc["item_name"];
- var item_number = nvc["item_number"];
- var amount1 = nvc["amount1"];
- var amount2 = float.Parse(nvc["amount2"], CultureInfo.InvariantCulture.NumberFormat);
- var currency1 = nvc["currency1"];
- var currency2 = nvc["currency2"];
- var status = Convert.ToInt32(nvc["status"]);
- var status_text = nvc["status_text"];
- Trace.WriteLine(status);
- if (currency1 != "USD") {
- Trace.WriteLine("Original currency mismatch!");
- return View();
- }
- if (Convert.ToInt32(amount1) < Convert.ToInt32(order_total))
- {
- Trace.WriteLine("Amount is less than order total!");
- return View();
- }
- if (status >= 100 || status == 2) {
- using (MyDatabaseEntities1 dc = new MyDatabaseEntities1())
- {
- var account = dc.Users.Where(a => a.Username == MyGlobalVariables.CurrentUser).FirstOrDefault();
- if (account != null && account.Paid == 0)
- {
- Trace.WriteLine("Payment Completed");
- Trace.WriteLine("Tokens to add: " + MyGlobalVariables.TokenChoice);
- account.Tokens += MyGlobalVariables.TokenChoice;
- account.Paid = 1;
- dc.Configuration.ValidateOnSaveEnabled = false;
- dc.SaveChanges();
- }
- }
- } else if (status < 0)
- {
- Trace.WriteLine(
- "payment error, this is usually final but payments will sometimes be reopened if there was no exchange rate conversion or with seller consent");
- } else {
- using (MyDatabaseEntities1 dc = new MyDatabaseEntities1())
- {
- var account = dc.Users.Where(a => a.Username == MyGlobalVariables.CurrentUser).FirstOrDefault();
- if (account != null)
- {
- account.Paid = 0;
- dc.Configuration.ValidateOnSaveEnabled = false;
- dc.SaveChanges();
- }
- }
- Trace.WriteLine("Payment is pending");
- }
- return View();
- }
Add Comment
Please, Sign In to add comment