public ActionResult RefundConfirmed(int id) { //Find Order Order order = db.Orders.Find(id); //Set API Credentials TwocheckoutConfig.ApiUsername = "******"; TwocheckoutConfig.ApiPassword = "******"; //Attempt Refund var dictionary = new Dictionary <string, string>(); dictionary.Add("sale_id", order.OrderNumber); dictionary.Add("comment", "Refunded"); dictionary.Add("category", "5"); TwocheckoutResponse result = TwocheckoutSale.Refund(dictionary); //If Successful, update order. if (result.response_code == "OK") { order.Refunded = "Yes"; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }
//Handle Fraud Status Changed INS Message public ActionResult Notification() { //Check MD5 Hash var dictionary = new Dictionary <string, string>(); dictionary.Add("vendor_id", Request.Params["vendor_id"]); dictionary.Add("sale_id", Request.Params["sale_id"]); dictionary.Add("invoice_id", Request.Params["invoice_id"]); dictionary.Add("md5_hash", Request.Params["md5_hash"]); TwocheckoutResponse result = TwocheckoutNotification.Check(dictionary, "tango"); //Check to insure MD5 Matches if (result.response_code == "Success") { //Get Order ID int ID = Convert.ToInt32(Request.Params["vendor_order_id"]); //Check Message Type and Fraud Status if (Request.Params["message_type"] == "FRAUD_STATUS_CHANGED" && Request.Params["fraud_status"] == "pass") { Order order = db.Orders.Find(ID); order.Refunded = ""; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); } else if (Request.Params["message_type"] == "FRAUD_STATUS_CHANGED" && Request.Params["fraud_status"] == "fail") { Order order = db.Orders.Find(ID); order.Refunded = "Yes"; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); } ViewBag.Message = "MD5 Hash Matched"; } else { ViewBag.Message = "MD5 Hash Mismatch"; } return(View()); }
//Passback from 2Checkout public ActionResult Return() { //Check MD5 Hash Returned var dictionary = new Dictionary <string, string>(); dictionary.Add("sid", Request.Params["sid"]); dictionary.Add("order_number", Request.Params["order_number"]); dictionary.Add("total", Request.Params["total"]); dictionary.Add("key", Request.Params["key"]); TwocheckoutResponse result = TwocheckoutReturn.Check(dictionary, "tango"); if (result.response_code == "Success") { //Get Timestamp DateTime date = DateTime.Now; String time = date.ToString("yyyyMMdd-HHmmss"); //Update Order as Paid int ID = Convert.ToInt32(Request.Params["merchant_order_id"]); Order order = db.Orders.Find(ID); order.OrderNumber = Request.Params["order_number"]; order.DatePlaced = time; order.CustomerName = Request.Params["card_holder_name"]; order.Total = Request.Params["total"]; order.Refunded = ""; db.Entry(order).State = EntityState.Modified; db.SaveChanges(); ViewBag.Message = "Thank you for your Order!"; } else { ViewBag.Message = "There was a problem with your order. Please contact the site owner to troubleshoot!"; } return(View()); }