示例#1
0
        public ActionResult PaymentPaypal()
        {
            if (SessionUtility.GetBookingSession() == null || SessionUtility.GetPassengerSession() == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            APIContext apiContext = PaypalUtility.GetAPIContext();

            try
            {
                var payerId = Request.Params["PayerID"];

                if (string.IsNullOrEmpty(payerId))
                {
                    var baseURI        = Request.Url.Scheme + "://" + Request.Url.Authority + "/Ticket/PaymentPaypal?";
                    var guid           = Convert.ToString((new Random()).Next(100000));
                    var createdPayment = PaypalUtility.CreatePayment(apiContext, baseURI + "guid=" + guid);

                    //Get id payment for refund
                    var boookingSession = SessionUtility.GetBookingSession();
                    boookingSession.PaymentID = createdPayment.id;
                    SessionUtility.SetBookingSession(boookingSession);

                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = null;

                    while (links.MoveNext())
                    {
                        Links lnk = links.Current;

                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = lnk.href;
                        }
                    }

                    Session.Add(guid, createdPayment.id);

                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    var guid            = Request.Params["guid"];
                    var executedPayment = PaypalUtility.ExecutePayment(apiContext, payerId, Session[guid] as string);

                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(View("Failed"));
                    }
                }
            }
            catch
            {
                return(View("Failed"));
            }

            return(RedirectToAction("BookingSuccess"));
        }
示例#2
0
        public JsonResult RefundTicket(string ticketId, string admin = null)
        {
            var result = new JsonResult {
                ContentType = "text"
            };
            var currentTicket = this.TicketService.Find(int.Parse(ticketId));

            if (currentTicket == null)
            {
                result.Data = new { type = "error" };
                return(result);
            }

            var firstFlight  = this.FlightService.FindByTicket(currentTicket.ID).First();
            var departFlight = this.FlightService.FindByTicket(currentTicket.ID).ToList();
            var returnFlight = this.FlightService.FindByTicket(currentTicket.ID, true).ToList();
            var flightTicket = departFlight.First().Departure.City + " to " + departFlight.Last().Arrival.City + (returnFlight.Count() > 0 ? " (Roundtrip)" : "");

            var        refundPrice = currentTicket.Price.Value / 2;
            APIContext apiContext  = PaypalUtility.GetAPIContext();

            if ((firstFlight.DepartureDate.Value - DateTime.Now).TotalDays > 30 && !currentTicket.Status.Equals(Constant.CONST_DB_TICKET_STATUS_RETURN))
            {
                if (PaypalUtility.RefundPayment(apiContext, currentTicket.PaymentID, refundPrice))
                {
                    result.Data               = new { type = "success", refund = string.Format("{0:0.00}", refundPrice) };
                    currentTicket.Status      = Constant.CONST_DB_TICKET_STATUS_RETURN;
                    currentTicket.UpdateDate  = DateTime.Now;
                    currentTicket.Description = "Refund $" + string.Format("{0:0.00}", refundPrice);

                    EmailSender.SendMailReturnTicket(currentTicket.Account.Email, flightTicket, currentTicket.Price.ToString(), string.Format("{0:0.00}", refundPrice), admin);
                    this.TicketService.Update(currentTicket);
                }
                else
                {
                    result.Data = new { type = "error" }
                }
            }
            ;