// GET: Paypal public ActionResult Confirmacion(string codigo) { int clave = int.Parse(Session["CodigoTarea"].ToString()); int estudiante = int.Parse(codigo); ViewData["CodigoTarea"] = clave; if (Request.HttpMethod != "POST") { authToken = "UQZqpZAq_ZGRCh_3d__MLmA4IxIBkIm1U4AowLfjqYQ47C_Y7hUZsX94_3a"; ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.UseNagleAlgorithm = true; ServicePointManager.Expect100Continue = true; ServicePointManager.CheckCertificateRevocationList = true; ServicePointManager.DefaultConnectionLimit = ServicePointManager.DefaultPersistentConnectionLimit; txToken = Request.QueryString.Get("tx"); query = string.Format("cmd=_notify-synch&tx={0}&at={1}", txToken, authToken); string url = "https://www.sandbox.paypal.com/cgi-bin/webscr"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = query.Length; StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(query); stOut.Close(); StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); strResponse = stIn.ReadToEnd(); stIn.Close(); if (strResponse.StartsWith("SUCCESS")) { PDTHolder pdt = PDTHolder.Parse(strResponse); ViewBag.mensaje = string.Format("Cuenta en la que se realizo el pago {0} {1} [{2}] Monto del pago {3} {4}!", pdt.PayerFirstName, pdt.PayerLastName, pdt.PayerEmail, pdt.GrossTotal, pdt.Currency); if (pdt.PaymentStatus == "Completed") { int empleador = int.Parse(Session["Codigo"].ToString()); ObjDAO.Aceptarpostulados(estudiante, clave); msg.AgregarPago(empleador, pdt.GrossTotal, pdt.PayerEmail, clave, estudiante); } } else { PDTHolder pdt = PDTHolder.Parse(strResponse); ViewBag.mensaje = string.Format("Cuenta en la que se realizo el pago {0} {1} [{2}] Monto del pago {3} {4}! no fue correcta, por favor contacta al administrador", pdt.PayerFirstName, pdt.PayerLastName, pdt.PayerEmail, pdt.GrossTotal, pdt.Currency); } } //return Redirect("~/Tareas/DetalleTareaDispo?Codigo='" + clave + "'"); return(View()); }
protected void Page_Load(object sender, EventArgs e) { getCompanyName(); if (!Page.IsPostBack) { string strToken = string.Empty; string strSubmitUrl = string.Empty; DataSet dsGetPaymentOption = new DataSet(); dsGetPaymentOption = dbInfo.GetPaymentOptionDetails(); if (dsGetPaymentOption.Tables.Count > 0) { if (dsGetPaymentOption != null && dsGetPaymentOption.Tables.Count > 0 && dsGetPaymentOption.Tables[0].Rows.Count > 0) { foreach (DataRow dtrow in dsGetPaymentOption.Tables[0].Rows) { ViewState["PaymentOption"] = Convert.ToString(dtrow["payment_Id"]); //PayPalIpn //ViewState["PayPalUrl"] = Convert.ToString(dtrow["PaypalUrl"]); //ViewState["BusinessEmail"] = Convert.ToString(dtrow["PaypalEmail"]); strSubmitUrl = Convert.ToString(dtrow["PaypalSubUrl"]); strToken = Convert.ToString(dtrow["PDTToken"]); } } } // authToken = ConfigurationManager.AppSettings["PDTToken"]; authToken = strToken; //EmailGenerator _emailGenerator = new EmailGenerator(); //bool mailStatus = _emailGenerator.userForgotPasswordEmail("Ritu", "", "*****@*****.**"); //read in txn token from querystring txToken = Request.QueryString.Get("tx"); query = string.Format("cmd=_notify-synch&tx={0}&at={1}", txToken, authToken); // Create the request back string url = strSubmitUrl; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); // Set values for the request back req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = query.Length; // Write the request back IPN strings StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(query); stOut.Close(); // Do the request to PayPal and get the response StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); strResponse = stIn.ReadToEnd(); stIn.Close(); // sanity check // Label2.Text = strResponse; // If response was SUCCESS, parse response string and output details if (strResponse.StartsWith("SUCCESS")) { int orderNum = 0; string strTransId = string.Empty; int insertOrder = 0; string strOrdPayType = string.Empty; PDTHolder pdt = PDTHolder.Parse(strResponse); lblResponse.Text = string.Format("Thank you {0} {1} [{2}] for your payment of {3} {4}!", pdt.PayerFirstName, pdt.PayerLastName, pdt.PayerEmail, pdt.GrossTotal, pdt.Custom); orderNum = Convert.ToInt32(pdt.Custom); strTransId = Convert.ToString(pdt.TransactionId); if (Request.Cookies["DepositFund"] != null && Request.Cookies["DepositFund"].Value != "") { string StrFund = Convert.ToString(Request.Cookies["DepositFund"].Value); string[] splitter = { "|@|" }; string[] dateInfo = StrFund.Split(splitter, StringSplitOptions.None); int i = 0; string strfirst = dateInfo[i]; if (Convert.ToString(strfirst) == "NoFund") { string StrShop = Convert.ToString(Request.Cookies["ShoppingCart"].Value); SplitShopString(StrShop); string StrShipping = Convert.ToString(Request.Cookies["UserShopAddInfo"].Value); SplitUserShopAddInfo(StrShipping); getPaymentDropDown(); double totFinal = Convert.ToDouble(ViewState["intGroceryTot"]) + Convert.ToDouble(ViewState["strTippingAmt"]); ViewState["TotalFinal"] = Convert.ToString(totFinal); if (Request.Cookies["PaypalShopping"] != null && Request.Cookies["PaypalShopping"].Value != "") { strOrdPayType = Convert.ToString(Request.Cookies["PaypalShopping"].Value); insertOrder = dbInfo.InsertOrderInformation(Convert.ToInt32(Request.Cookies["userId"].Value), Convert.ToString(ViewState["strAddress1"]), Convert.ToString(ViewState["strAddress2"]), Convert.ToString(ViewState["strCity"]), Convert.ToString(ViewState["strState"]), Convert.ToString(ViewState["strZip"]), Convert.ToString(ViewState["strSpecial"]), DateTime.Now, Convert.ToDateTime(ViewState["strDelDate"]), Convert.ToString(ViewState["strTimeValue"]), Convert.ToDouble(ViewState["TotalFinal"]), Convert.ToDouble(ViewState["grocerytotal"]), Convert.ToDouble(ViewState["strTippingAmt"]), Convert.ToDouble(ViewState["OrdSoda"]), Convert.ToDouble(ViewState["OrdDelFee"]), Convert.ToDouble(ViewState["CompCost"]), orderNum, Convert.ToString(strOrdPayType), Convert.ToDouble(ViewState["OrdTax"]), 1, 1, 1, 1, 1); if (insertOrder > 0) { //Insert order product Information InsertProductOrderInfo(insertOrder); //Insert Transaction Information if (strOrdPayType == Convert.ToString(AppConstants.strAFCC)) { InsertTransactionDetails(strOrdPayType, insertOrder, strTransId); } //Insert Loyality Fund Information //InsertLoyalityFund(insertOrder); //update delivery capacity information UpdateDeliveryTime(); HttpCookie DepositFund = new HttpCookie("DepositFund", null); Response.Cookies.Add(DepositFund); Response.Redirect("OrderConfirmation.aspx?orderId=" + insertOrder, false); } } else { int intAdd = AddTransaction(strTransId, Convert.ToString(Request.Cookies["DepositFund"].Value)); if (intAdd == 1) { HttpCookie DepositFund = new HttpCookie("DepositFund", null); Response.Cookies.Add(DepositFund); Response.Redirect("AccountFunds.aspx?checkDep=1", false); } // Response.Redirect("AccountFunds.aspx?checkDep=1&id=" + strTransId, false); } } else { int intAdd = AddTransaction(strTransId, Convert.ToString(Request.Cookies["DepositFund"].Value)); if (intAdd == 1) { HttpCookie DepositFund = new HttpCookie("DepositFund", null); Response.Cookies.Add(DepositFund); Response.Redirect("AccountFunds.aspx?checkDep=1", false); } // Response.Redirect("AccountFunds.aspx?checkDep=1&id=" + strTransId, false); } } } } }
public ActionResult Success() { string authToken, txToken, query; string strResponse; if (Request.HttpMethod != "POST") { authToken = WebConfigurationManager.AppSettings["PDTToken"]; // read in txn token from querystring txToken = Request.QueryString.Get("tx"); query = string.Format("cmd=_notify-synch&tx={0}&at={1}", txToken, authToken); // crate the request back string url = WebConfigurationManager.AppSettings["PayPalSubmitUrl"]; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); // Set values for the request back req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = query.Length; // Write the request back IPN strings StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(query); stOut.Close(); // Do the request to PayPal and get the response StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream()); strResponse = stIn.ReadToEnd(); stIn.Close(); // If response was SUCCESS, parse response string and output details if (strResponse.StartsWith("SUCCESS")) { PDTHolder pdt = PDTHolder.Parse(strResponse); int pTicketId = int.Parse(pdt.Custom); // ViewBag.Text = string.Format("Thank you {0} {1} [{2}] for your payment of {3} {4}!", // pdt.PayerFirstName, pdt.PayerLastName, pdt.PayerEmail, pdt.GrossTotal, pdt.Custom); Ticket ticket = this.unitOfWork.TicketRepository.Get(t => t.TicketId == pTicketId).FirstOrDefault(); Ticket oldTicket = (Ticket)Session["BuyingTicket"]; if (oldTicket != null) { if (oldTicket.EventId != ticket.EventId || oldTicket.SeriesNumber != ticket.SeriesNumber || oldTicket.Status != ticket.Status || oldTicket.Seat != ticket.Seat || oldTicket.SellPrice != ticket.SellPrice) { return(View("Changed")); } } ViewBag.PayerFirstName = pdt.PayerFirstName; ViewBag.User = ticket.User.UserName; ViewBag.PayerLastName = pdt.PayerLastName; ViewBag.OrderId = pdt.TransactionId; ViewBag.Name = ticket.Event.EventName; ViewBag.Price = pdt.GrossTotal; ViewBag.Currency = pdt.Currency; if (ModelState.IsValid) { if (ticket.TranStatus == null) { if (ticket.TranType == (int)Statuses.TranType.InstantPayment) { Ticket checkout = new Ticket() { TicketId = ticket.TicketId, SeriesNumber = ticket.SeriesNumber, TranUserId = ticket.TranUserId, TranFullName = ticket.TranFullName, TranAddress = ticket.TranAddress, TranType = ticket.TranType, TranStatus = (int)Statuses.Transaction.Paid, EventId = ticket.EventId, UserId = ticket.UserId, SellPrice = ticket.SellPrice, ReceiveMoney = ticket.ReceiveMoney, ShippingCost = ticket.ShippingCost, Seat = ticket.Seat, Status = ticket.Status, Description = ticket.Description, CreatedDate = ticket.CreatedDate, TranCreatedDate = ticket.TranCreatedDate, TranModifiedDate = DateTime.Now, TranDescription = ticket.TranDescription, TranPaymentStatus = (int)Statuses.Payment.Transfered }; this.unitOfWork.TicketRepository.AddOrUpdate(checkout); this.unitOfWork.Save(); } else { Ticket checkout = new Ticket() { TicketId = ticket.TicketId, SeriesNumber = ticket.SeriesNumber, TranUserId = ticket.TranUserId, TranFullName = ticket.TranFullName, TranAddress = ticket.TranAddress, TranType = ticket.TranType, TranStatus = (int)Statuses.Transaction.Paid, EventId = ticket.EventId, UserId = ticket.UserId, SellPrice = ticket.SellPrice, ReceiveMoney = ticket.ReceiveMoney, ShippingCost = ticket.ShippingCost, Seat = ticket.Seat, Status = ticket.Status, Description = ticket.Description, CreatedDate = ticket.CreatedDate, TranCreatedDate = ticket.TranCreatedDate, TranModifiedDate = DateTime.Now, TranDescription = ticket.TranDescription }; this.unitOfWork.TicketRepository.AddOrUpdate(checkout); this.unitOfWork.Save(); } } else { return(View("Error")); } } } else { ViewBag.Text = "Cố lỗi xảy ra"; } } return(View()); }