示例#1
0
        protected void checkout_Click(object sender, EventArgs e)
        {
            CartList = (List <Section>)Session["ScItms"];
            var discount = Convert.ToDouble(Session["Discount"].ToString());

            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                String baseURI        = Request.Url.Scheme + "://" + Request.Url.Authority + "/site/student/processPayment.aspx?";
                var    guid           = Convert.ToString(new Random().Next(100000));
                var    createdPayment = PaypalPayment.CreatePayment(apiContext, baseURI + "guid=" + guid, CartList, discount);

                var    links             = createdPayment.links.GetEnumerator();
                String paypalRedirectUrl = String.Empty;

                while (links.MoveNext())
                {
                    Links link = links.Current;
                    if (link.rel.ToLower().Trim().Equals("approval_url"))
                    {
                        paypalRedirectUrl = link.href;
                    }
                }
                Session.Add(guid, createdPayment.id);
                Session["cartList"] = CartList;
                Response.Redirect(paypalRedirectUrl, false);
            }
            catch (Exception ex)
            {
                PaypalLogger.Log("Error: " + ex.Message);
                Response.Redirect("~/site/failedPaypal.aspx");
            }
        }
        public ActionResult PaymentWithPaypal(string Cancel = null)
        {
            //getting the apiContext
            var book = Session["booking"];

            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                //A resource representing a Payer that funds a payment Payment Method as paypal
                //Payer Id will be returned when payment proceeds or click to pay
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    //this section will be executed first because PayerID doesn't exist
                    //it is returned by the create function call of the payment class
                    // Creating a payment
                    // baseURL is the url on which paypal sendsback the data.
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Payment/PaymentWithPayPal?";
                    //here we are generating guid for storing the paymentID received in session
                    //which will be used in the payment execution
                    var guid = Convert.ToString((new Random()).Next(100000));
                    //CreatePayment function gives us the payment approval url
                    //on which payer is redirected for paypal account payment
                    var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid);
                    //get links returned from paypal in response to Create function call
                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = null;
                    while (links.MoveNext())
                    {
                        Links lnk = links.Current;
                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            //saving the payapalredirect URL to which user will be redirected for payment
                            paypalRedirectUrl = lnk.href;
                        }
                    }
                    // saving the paymentID in the key guid
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    // This function exectues after receving all parameters for the payment
                    var guid            = Request.Params["guid"];
                    var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    //If executed payment failed then we will show payment failure message to user
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(View("Failure"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(View("Failure"));
            }
            //on successful payment, show success page to user.
            return(RedirectToAction("MineUpcoming", "Booking"));
        }
示例#3
0
        public ActionResult PaymentWithPaypal(ShippingAddress shippingAddress)
        {
            if (!ModelState.IsValid)
            {
                return(View(shippingAddress));
            }

            // Getting context from the paypal bases on clientId and clientSecret for payment
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    // Creating a payment
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/ShoppingCart/PaymentWithPaypal";
                    var    guid    = Convert.ToString((new Random()).Next(100000));

                    var createdPayment = CreatePayment(apiContext, new List <Product>()
                    {
                        new Product()
                    }, shippingAddress, baseURI);


                    // Get links returned from paypal response to create call function
                    var    links = createdPayment.links.GetEnumerator();
                    string paypaylRedirectUrl = string.Empty;

                    while (links.MoveNext())
                    {
                        Links link = links.Current;
                        if (link.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypaylRedirectUrl = link.href;
                        }
                    }

                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypaylRedirectUrl));
                }
                else
                {
                    // This one will be executed when we have recieved all the payment params from previous call
                    var guid            = Request.Params["paymentId"];               // Request.Params["guid"];
                    var executedPayment = ExecutePayment(apiContext, payerId, guid); //Session[guid] as string);
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(View("Index", "Errors"));
                    }
                }
            }
            catch (Exception ex)
            {
                PaypalLogger.Log("Error : " + ex.Message);
                return(View("Index", "Errors"));
            }

            return(View("PaymentSuccess"));
        }
示例#4
0
        //create method
        public ActionResult PaymentWithPaypal()
        {
            var        usrDonate  = (UserDonateView)Session["ud"];
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerID = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerID))
                {
                    //create a payment
                    string baseUri        = Request.Url.Scheme + "://" + Request.Url.Authority + "/Paypal/PaymentWithPaypal?guid=";
                    string guid           = Convert.ToString((new Random()).Next(100000));
                    var    createdPayment = CreatePayment(apiContext, baseUri + guid);

                    var    link = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = string.Empty;
                    while (link.MoveNext())
                    {
                        Links links = link.Current;
                        if (links.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = links.href;
                        }
                    }
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    var guid           = Request.Params["guid"];
                    var executePayment = ExecutePayment(apiContext, payerID, Session[guid] as string);
                    if (executePayment.state.ToLower() != "approved")
                    {
                        TempData["error"] = "Donate Failed. Please try again!";
                        return(RedirectToAction("Donate", "Home"));
                    }
                }
            }
            catch (PayPal.PaymentsException ex)
            {
                TempData["error"] = "Donate Failed. Please try again!";
                PaypalLogger.Log("Error: " + ex.Message);
                return(RedirectToAction("Donate", "Home"));
            }
            var ud = new UserDonate {
                DonateID = usrDonate.DonateID, Money = usrDonate.Money, UserID = usrDonate.UserID, TypeCard = usrDonate.TypeCard
            };

            if (Repositories.InsertUD(ud) > 0)
            {
                TempData["success"] = "Donate Successfully! We appreciate it!";
            }
            else
            {
                TempData["error"] = "Donate Failed. Please try again!";
            }
            return(RedirectToAction("Donate", "Home"));
        }
示例#5
0
        //Create PaymentWithPaypal method
        public ActionResult PaymentWithPaypal()
        {
            // Getting context from the paypal base on clientId and clientSecret for payment
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerId"];

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

                    //Get links returned from paypal response to create call function
                    var links = createdPayment.links.GetEnumerator();

                    string paypalRedirectUrl = string.Empty;

                    while (links.MoveNext())
                    {
                        Links link = links.Current;
                        if (link.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = link.href;
                        }
                    }
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    //this one will be executed when we have received all the payment params from previous call
                    var guid            = Request.Params["guid"];
                    var executedPayment = ExcutePayment(apiContext, payerId, Session[guid] as string);
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(View("PaypalFail"));
                    }
                }
            }
            catch (Exception ex)
            {
                ViewBag.message = ex.Message;
                return(View("PaypalFail"));
                //PaypalLogger.Log("Error: " + ex.Message);
                //return View("PaypalFail");
            }
            ApplicationUser currentUser = MyContext.Users.Where(u => u.Email == @User.Identity.Name).FirstOrDefault();

            currentUser.Bits += 10000;
            MyContext.SaveChanges();


            return(View("PaypalSuccess"));
        }
示例#6
0
        // Create PaymentWithPaypal method
        public ActionResult PaymentWithPaypal()
        {
            // Gettings context from the paypal bases on clientId and clientsecret for payment
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

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

                if (string.IsNullOrEmpty(payerId))
                {
                    //Creating a payment
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/NguoiMua/GioHang/PaymentWithPaypal?";
                    MessageBox.Show("tạo base URI");
                    var guid           = Convert.ToString((new Random()).Next(100000));
                    var createdPayment = CreatePayment(apiContext, baseURI + "guid=" + guid);

                    MessageBox.Show("tạo links");
                    //Get link returned from paypal respone to create call function
                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = string.Empty;

                    while (links.MoveNext())
                    {
                        Links link = links.Current;
                        if (link.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = link.href;
                        }
                    }

                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    //This one will be executed when we have received all the payment params from previous call
                    var guid           = Request.Params["guid"];
                    var executePayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    if (executePayment.state.ToLower() != "approved")
                    {
                        Session["CheckOut"] = 0;
                        return(RedirectToAction("TrangChu", "TaiKhoan_NguoiMua"));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                PaypalLogger.Log("Error:" + ex.Message);

                Session["CheckOut"] = 0;
                return(RedirectToAction("TrangChu", "TaiKhoan_NguoiMua"));
            }

            Session["CheckOut"] = 1;
            return(RedirectToAction("TrangChu", "TaiKhoan_NguoiMua"));
        }
示例#7
0
        //create method
        public ActionResult PaymentWithPaypal()
        {
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerID = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerID))
                {
                    //create a payment
                    string baseUri        = Request.Url.Scheme + "://" + Request.Url.Authority + "/Paypal/PaymentWithPaypal?guid=";
                    string guid           = Convert.ToString((new Random()).Next(100000));
                    var    createdPayment = CreatePayment(apiContext, baseUri + guid);

                    var    link = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = string.Empty;
                    while (link.MoveNext())
                    {
                        Links links = link.Current;
                        if (links.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = links.href;
                        }
                    }
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    var guid           = Request.Params["guid"];
                    var executePayment = ExecutePayment(apiContext, payerID, Session[guid] as string);
                    if (executePayment.state.ToLower() != "approved")
                    {
                        TempData["error"] = "Thanh toán bằng Paypal lỗi";
                        return(RedirectToAction("InformationBooking", "Booking", new { token = Session["token"].ToString() }));
                    }
                }
            }
            catch (PayPal.PaymentsException ex)
            {
                PaypalLogger.Log("Error: " + ex.Message);
                Console.WriteLine(ex);
                TempData["error"] = "Thanh toán bằng Paypal lỗi";
                return(RedirectToAction("InformationBooking", "Booking", new { token = Session["token"].ToString() }));
            }
            HttpResponseMessage res = GlobalVariables.client.GetAsync("CheckOut?token=" + Session["token"].ToString() + "&payment=" + false).Result;

            if (res.IsSuccessStatusCode)
            {
                TempData["success"] = "Thanh toán bằng Paypal thành công";
            }
            else
            {
                TempData["error"] = "Loi check out!";
            }
            return(RedirectToAction("InformationBooking", "Booking", new { token = Session["token"].ToString() }));
        }
示例#8
0
        // GET: Paypal
        public ActionResult metodoPaypal()
        {
            if (Session["sesion"] != null)
            {
                APIContext apiContext = PaypalConfiguration.GetAPIContext();
                try
                {
                    string payerId = Request.Params["PayerID"];
                    if (string.IsNullOrEmpty(payerId))
                    {
                        string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Paypal/metodoPaypal?";
                        var    Guid    = Convert.ToString((new Random()).Next(100000));

                        var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + Guid);

                        var    link = createdPayment.links.GetEnumerator();
                        string paypalRedirectUrl = null;
                        while (link.MoveNext())
                        {
                            Links lnk = link.Current;
                            if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                            {
                                paypalRedirectUrl = lnk.href;
                            }
                        }

                        // saving the paymentID in the key guid
                        Session.Add(Guid, createdPayment.id);
                        return(Redirect(paypalRedirectUrl));
                    }
                    else
                    {
                        var guid            = Request.Params["guid"];
                        var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);

                        if (executedPayment.state.ToLower() != "approved")
                        {
                            return(View("ErrorTransaccion"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.Result = ex.Message;
                    return(View("ErrorTransaccion"));
                }

                ViewBag.Result = "Exitoo";
                return(View("Exito"));
            }
            else
            {
                return(Redirect("~/Clientes/IniciarSesion?mensaje=1"));
            }
        }
示例#9
0
        public ActionResult BuyNow(Data.Models.Plan plan)
        {
            if (Session["UserId"] != null)
            {
                APIContext apiContext = PaypalConfiguration.GetAPIContext();
                try
                {
                    string payerId = Request.Params["PayerID"];
                    if (string.IsNullOrEmpty(payerId))
                    {
                        string baseURI        = Request.Url.Scheme + "://" + Request.Url.Authority + "/home/paypaldetail?pd=" + plan.PlanID + "&";
                        var    guid           = Convert.ToString(new Random().Next(100000));
                        var    createdPayment = CreatePayment(apiContext, baseURI + "guid=" + guid, plan);

                        var    links             = createdPayment.links.GetEnumerator();
                        string paypalRedirectUrl = string.Empty;
                        while (links.MoveNext())
                        {
                            Links link = links.Current;
                            if (link.rel.ToLower().Trim().Equals("approval_url"))
                            {
                                paypalRedirectUrl = link.href;
                            }
                        }
                        Session.Add(guid, createdPayment.id);
                        Session["guid"] = createdPayment.id;
                        return(Redirect(paypalRedirectUrl));
                    }
                    else
                    {
                        //var guid = Request.Params["guid"];
                        PayPal.Api.Payment executePayment = ExecutePayment(apiContext, payerId, Session["guid"] as string);
                        if (executePayment.state.ToLower() != "approved")
                        {
                            return(View("Failure"));
                        }
                        else
                        {
                            string planId = Request.Params["pd"];
                            string token  = Request.Params["token"];
                            AddPaymentDetail(planId, payerId, Session["guid"] as string, token);
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(View("Failure"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account", new { plan_id = plan.PlanID }));
            }
            return(View());
        }
示例#10
0
        //Create PaymentWithPaypal method
        public ActionResult PaymentWithPaypal()
        {
            //Get context from the paypal bases on clientId and clientSecret for payment
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    //Creating payment
                    string baseURI        = Request.Url.Scheme + "://" + Request.Url.Authority + "/Users/PaymentWithPaypal?";
                    var    guid           = Convert.ToString((new Random()).Next(100000));
                    var    createdPayment = CreatePayment(apiContext, baseURI + "guid=" + guid);

                    //Get links returned from paypal response to create call function
                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = string.Empty;
                    while (links.MoveNext())
                    {
                        Links link = links.Current;
                        if (link.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = link.href;
                        }
                    }
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    //This one will be executed when we have received all payment params from previous call
                    var guid           = Request.Params["guid"];
                    var executePayment = ExecutePayment(apiContext, payerId /*, guid as string*/, Session[guid] as string);
                    if (executePayment.state.ToLower() != "approved")
                    {
                        return(View("Failure"));
                    }
                }
            }
            catch (Exception ex)
            {
                //PaypalLogger.Log("Error: " + ex.Message);
                return(View("Failure"));
            }
            string loggedInUser = User.Identity.GetUserId();
            var    userFound    = db.Users.Find(loggedInUser);

            //Set his payment as true and the exact time he paid.
            userFound.IsPaid  = 1;
            userFound.SubDate = DateTime.UtcNow;
            db.SaveChanges();
            return(View("Success"));
        }
示例#11
0
        public ActionResult PaymentWithPaypal()
        {
            Reservation reservation  = (Reservation)Session[strReservation];
            Reservation reservation1 = new Reservation
            {
                ArrivalDate   = reservation.ArrivalDate,
                DepartureDate = reservation.DepartureDate,
                RoomId        = reservation.RoomId,
                UserId        = reservation.UserId,
            };

            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    string baseURI        = Request.Url.Scheme + "://" + Request.Url.Authority + "/reservations/paymentwithpaypal?";
                    var    guid           = Convert.ToString((new Random()).Next(100000));
                    var    createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid);

                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = string.Empty;
                    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
                {
                    //this one will be executed when we have received all the payment params from previous call
                    var guid           = Request.Params["guid"];
                    var executePayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    if (executePayment.state.ToLower() != "approved")
                    {
                        return(View("Failure"));
                    }
                }
            }
            catch (Exception ex)
            {
                PaypalLogger.Log("Error: " + ex.Message);
                return(View("Failure"));
            }
            _reservationsRepository.AddReservation(reservation1);
            return(View("Success"));
        }
示例#12
0
        // Create PaymentWithPaypal method
        public ActionResult PaymentWithPaypal()
        {
            // Getting context from the paypal bases on clientID and clientSecret for payment
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    //Creating a payment
                    string baseURI        = Request.Url.Scheme + "://" + Request.Url.Authority + "/ShoppingCart/PaymentwithPaypal?";
                    var    guid           = Convert.ToString((new Random()).Next(100000));
                    var    createdPayment = CreatePayment(apiContext, baseURI + "guid=" + guid);

                    //Get links returned from paypal response to create
                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = string.Empty;

                    while (links.MoveNext())
                    {
                        Links link = links.Current;
                        if (link.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = link.href;
                        }
                    }
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    //This one will be executed when  we have  received all the payment params from previous call
                    string guid            = Request.Params["guid"];
                    string paymentID       = Request.Params["paymentId"];
                    var    executedPayment = ExecutePayment(apiContext, payerId, paymentID);
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(View("Failure"));
                    }
                }
            }
            catch (Exception ex)
            {
                PaypalLogger.log("Error: " + ex.Message);
                return(View("Failure"));
            }

            string TCount = "1";
            string Tday   = DateTime.Today.ToString("yyyy-MM-dd");

            return(RedirectToAction("Create", "Transacaos", new { Tday, TCount }));
        }
示例#13
0
        //Create PaymentWithPaypal method
        public ActionResult PaymentWithPaypal()
        {
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Perfume/PaymentWithPayPal?";

                    var guid           = Convert.ToString((new Random()).Next(100000));
                    var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid);

                    //get links returned from paypal in response to Create function call
                    var links = createdPayment.links.GetEnumerator();
                    //string paypalRedirectUrl = null;
                    string paypalRedirectUrl = string.Empty;

                    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
                {
                    // This section is executed when we have received all the payments parameters
                    var guid            = Request.Params["guid"];
                    var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        Session["ShoppingCart"] = null;
                        return(View("FailureView"));
                    }
                }
            }
            catch (Exception ex)
            {
                PaypalLogger.Log("Error" + ex.Message);

                Session["ShoppingCart"] = null;
                return(View("FailureView"));
            }

            Session["ShoppingCart"] = null;
            return(View("SuccessView"));
        }
        // GET: Payment (Create payment with Paypal method)
        public ActionResult PaymentWithPaypal()
        {
            // Getting context from the paypal based on clientId and clientsecret for payment
            APIContext apicontext = PaypalConfiguration.GetAPIContext();

            try
            {
                string PayerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(PayerId) && PayerId != null)
                {
                    string baseURi = Request.Url.Scheme + "://" + Request.Url.Authority +
                                     "/Payment/PaymentWithPaypal?";

                    var Guid          = Convert.ToString((new Random()).Next(100000000));
                    var createPayment = this.CreatePayment(apicontext, baseURi + "guid=" + Guid);

                    // Get links returned from paypal response to create call function
                    var    links             = createPayment.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, createPayment.id);
                    return(Redirect(paypalRedirectURL));
                }

                else
                {
                    // This one will be executed when we have received all the payment params from previous call
                    var guid           = Request.Params["guid"];
                    var executedPaymnt = ExecutePayment(apicontext, PayerId, Session[guid] as string);


                    if (executedPaymnt.ToString().ToLower() != "approved")
                    {
                        return(View("FailureView"));
                    }
                }
            }
            catch (Exception ex)
            {
                PaypalLogger.Log("Error: " + ex.Message);
                return(View("FailureView"));
            }
            return(View("SuccessView"));
        }
        public ActionResult PaymentWithPaypal(string Cancel = null)
        {
            APIContext apiContext = PaypalConfiguration.GetAPIContext();
            //try
            //{

            string payerId = Request.Params["PayerID"];

            if (string.IsNullOrEmpty(payerId))
            {
                string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Payment/PaymentWithPayPal?";

                var guid = Convert.ToString((new Random()).Next(100000));

                var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid);

                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 = ExecutePayment(apiContext, payerId, Session[guid] as string);

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

            //}
            //catch (Exception ex)
            //{
            //    return View("FailureView");
            //}

            //on successful payment, show success page to user.
            return(View("SuccessView"));
        }
示例#16
0
        public ActionResult PaymentWithPaypal(string Cancel = null)
        {
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/PaymentWithPayPal/PaymentWithPayPal?";
                    //here we are generating guid for storing the paymentID received in session
                    //which will be used in the payment execution
                    var guid = Convert.ToString((new Random()).Next(100000));
                    //CreatePayment function gives us the payment approval url
                    //on which payer is redirected for paypal account payment
                    var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid);
                    //get links returned from paypal in response to Create function call
                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = null;
                    while (links.MoveNext())
                    {
                        Links lnk = links.Current;
                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            //saving the payapalredirect URL to which user will be redirected for payment
                            paypalRedirectUrl = lnk.href;
                        }
                    }
                    // saving the paymentID in the key guid
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    // This function exectues after receving all parameters for the payment
                    var guid            = Request.Params["guid"];
                    var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    //If executed payment failed then we will show payment failure message to user
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(View("SuccessView"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(View("SuccessView"));
            }
            //on successful payment, show success page to user.
            return(View("FailureView"));
        }
示例#17
0
        //create method
        public ActionResult PaymentWithPaypal()
        {
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            var order = (OrderVipDTO)Session["ordervip"];

            try
            {
                string payerID = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerID))
                {
                    //create a payment
                    string baseUri        = Request.Url.Scheme + "://" + Request.Url.Authority + "/Client/Payment/PaymentWithPaypal?guid=";
                    string guid           = Convert.ToString((new Random()).Next(100000));
                    var    createdPayment = CreatePayment(apiContext, baseUri + guid, order);

                    var    link = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = string.Empty;
                    while (link.MoveNext())
                    {
                        Links links = link.Current;
                        if (links.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = links.href;
                        }
                    }
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    var guid           = Request.Params["guid"];
                    var executePayment = ExecutePayment(apiContext, payerID, Session[guid] as string);
                    if (executePayment.state.ToLower() != "approved")
                    {
                        SetAlert("Mua gói vip không thành công", "error");
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (PayPal.PaymentsException ex)
            {
                PaypalLogger.Log("Error: " + ex.Message);
                SetAlert("Mua gói vip không thành công", "error");
                return(RedirectToAction("Index"));
            }

            ApiService.AcceptOrder(order);
            SetAlert("Mua gói vip thành công", "success");
            return(RedirectToAction("Success", "Payment", new { code = apiContext.AccessToken }));
        }
        // GET: Payment
        public ActionResult PaymentWithPapal()
        {
            APIContext apicontext = PaypalConfiguration.GetAPIContext();

            try
            {
                string PayerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(PayerId) && PayerId != null)
                {
                    string baseURi = Request.Url.Scheme + "://" + Request.Url.Authority +
                                     "PaymentWithPapal/PaymentWithPapal?";

                    var Guid          = Convert.ToString((new Random()).Next(100000000));
                    var createPayment = this.CreatePayment(apicontext, baseURi + "guid=" + Guid);

                    var    links             = createPayment.links.GetEnumerator();
                    string paypalRedirectURL = null;

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

                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectURL = lnk.href;
                        }
                    }
                }
                else
                {
                    var guid           = Request.Params["guid"];
                    var executedPaymnt = ExecutePayment(apicontext, PayerId, Session[guid] as string);


                    if (executedPaymnt.ToString().ToLower() != "approved")
                    {
                        return(View("FailureView"));
                    }
                }
            }
            catch (Exception)
            {
                return(View("FailureView"));


                //throw;
            }

            return(View("SuccessView"));
        }
        public ActionResult PaymentWithPaypal(string Cancel = null)
        {
            string orderBill = "";
            //getting the apiContext
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Order/PaymentWithPayPal?";
                    var    guid    = Guid.NewGuid().ToString();
                    //CreatePayment function gives us the payment approval url on which payer is redirected for paypal account payment
                    var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid);
                    //get links returned from paypal in response to Create function call
                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = null;
                    while (links.MoveNext())
                    {
                        Links link = links.Current;
                        if (link.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            //saving the payapalredirect URL to which user will be redirected for payment
                            paypalRedirectUrl = link.href;
                        }
                    }
                    // saving the paymentID in the key guid
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    var guid            = Request.Params["guid"];
                    var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    orderBill = executedPayment.transactions.First().invoice_number;
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(RedirectToAction("ReleaseOrder", "Order"));
                    }
                    Session.Remove(guid);
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("ReleaseOrder", "Order"));
            }
            //on successful payment, redirect to save order action.
            return(RedirectToAction("SaveOrder", "Order", new { invoiceId = orderBill }));
        }
示例#20
0
        //create method
        public ActionResult PaymentWithPaypal()
        {
            var apiContext = PaypalConfiguration.GetAPIContext();
            var order      = (OrderData)Session[MessageConst.USER_SESSION];

            try
            {
                string payerID = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerID))
                {
                    //create a payment
                    string baseUri        = Request.Url.Scheme + "://" + Request.Url.Authority + "/home/PaymentWithPaypal?guid=";
                    string guid           = Convert.ToString((new Random()).Next(100000));
                    var    createdPayment = CreatePayment(apiContext, baseUri + guid, order);

                    var    link = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = string.Empty;
                    while (link.MoveNext())
                    {
                        Links links = link.Current;
                        if (links.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = links.href;
                        }
                    }
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    var guid           = Request.Params["guid"];
                    var executePayment = ExecutePayment(apiContext, payerID, Session[guid] as string);
                    if (executePayment.state.ToLower() != "approved")
                    {
                        TempData[MessageConst.ERROR] = "Donate Failed !";
                        return(RedirectToAction("Donate"));
                    }
                }
            }
            catch (PayPal.PaymentsException ex)
            {
                PaypalLogger.Log("Error: " + ex.Message);
                TempData[MessageConst.ERROR] = "Donate Failed !";
                return(RedirectToAction("Donate"));
            }
            //save donate
            new DonateDao(_provider).AddUserDonate(order);
            TempData[MessageConst.SUCCESS] = "Donate Successfully!";
            return(RedirectToAction("Donate"));
        }
示例#21
0
        //create Payment Whit Paypal method
        public ActionResult PaymentWithPaypal()
        {
            //getying context from the paypal bases on clientId and clientSecret
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    string baseUrl       = Request.Url.Scheme + "://" + Request.Url.Authority + "/Home/PaymentWithPaypal?";
                    var    guid          = Convert.ToString((new Random()).Next(100000));
                    var    createPayment = CreatePayment(apiContext, baseUrl + "guid=" + guid);

                    //get links returned from paypal response to create cal function
                    var    links             = createPayment.links.GetEnumerator();
                    string paypalRedirectUrl = null;

                    while (links.MoveNext())
                    {
                        Links link = links.Current;
                        if (link.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = link.href;
                        }
                    }
                    Session.Add(guid, createPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    var guid            = Request.Params["guid"];
                    var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(View("FailureView"));
                    }
                }
            }
            catch (Exception ex)
            {
                PaypalLogger.Log("Error: " + ex.Message);
                Session["Cart"] = null;
                return(View("FailureView"));
            }

            Session["Cart"] = null;
            return(RedirectToAction("SuccessView"));
        }
        //Create PaymentWithPaypal method
        public ActionResult PaymentWithPaypal()
        {
            //gettings context from the paypal bases on clientId and clientSecret for payment
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    //Create a payment
                    string baseURI        = Request.Url.Scheme + "://" + Request.Url.Authority + "/PaymentbyPayPal/PaymentWithPaypal?";
                    var    guid           = Convert.ToString((new Random()).Next(100000));
                    var    createdPayment = CreatePayment(apiContext, baseURI + "guid=" + guid);
                    //Get links returned from paypal response to create call function
                    var    links            = createdPayment.links.GetEnumerator();
                    string paypalRedirecUrl = string.Empty;

                    while (links.MoveNext())
                    {
                        Links link = links.Current;
                        if (link.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirecUrl = link.href;
                        }
                    }

                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirecUrl));
                }
                else
                {
                    // This one will be executed when we have received all payment params from previous call
                    var guid           = Request.Params["guid"];
                    var executePayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    if (executePayment.state.ToLower() != "approved")
                    {
                        return(View("Failure"));
                    }
                }
            }
            catch (Exception ex)
            {
                PaypalLogger.Log("Error: " + ex.Message);
                return(View("Failure"));
            }

            return(RedirectToAction("PaymentSuccess", "Manage"));
        }
        //Payment with Paypal main method
        public ActionResult PaymentWithPaypal()
        {
            //Get Client credentials
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];//"FHTFDERQPUYRC";
                if (string.IsNullOrEmpty(payerId))
                {
                    //Create a payment
                    string baseURI       = Request.Url.Scheme + "://" + Request.Url.Authority + "/PaypalPayment/PaymentWithPaypal?";
                    var    guid          = Convert.ToString((new Random()).Next(100000));
                    var    createPayment = CreatePayment(apiContext, baseURI + "guid=" + guid);

                    //Response calling
                    var    links             = createPayment.links.GetEnumerator();
                    string paypalRedirectUrl = string.Empty;

                    while (links.MoveNext())
                    {
                        Links link = links.Current;
                        if (link.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = link.href;
                        }
                    }
                    Session.Add(guid, createPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    // this will execute when payment
                    var guid           = Request.Params["guid"];
                    var executePayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    if (executePayment.state.ToLower() != "approved")
                    {
                        return(View("Failure"));
                    }
                }
            }
            catch (Exception ex)
            {
                PaypalLogger.Log("Error:" + ex.Message);
                return(View("Failure"));
            }
            return(View("Success"));
        }
        //create method
        public ActionResult PaymentWithPaypal()
        {
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerID = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerID))
                {
                    //create a payment
                    string baseUri        = Request.Url.Scheme + "://" + Request.Url.Authority + "/Paypal/PaymentWithPaypal?guid=";
                    string guid           = Convert.ToString((new Random()).Next(100000));
                    var    createdPayment = CreatePayment(apiContext, baseUri + guid);

                    var    link = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = string.Empty;
                    while (link.MoveNext())
                    {
                        Links links = link.Current;
                        if (links.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = links.href;
                        }
                    }
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    var guid           = Request.Params["guid"];
                    var executePayment = ExecutePayment(apiContext, payerID, Session[guid] as string);
                    if (executePayment.state.ToLower() != "approved")
                    {
                        return(View("Failure"));
                    }
                }
            }
            catch (PayPal.PaymentsException ex)
            {
                PaypalLogger.Log("Error: " + ex.Message);
                return(View("Failure"));
            }

            AddCustomerPolicy();
            return(RedirectToAction("Success"));
        }
示例#25
0
        // Create paymentWithPaypal method

        public ActionResult PaymentWithPaypal()
        {
            // Get apiContext from paypal using clientId and clientSecret
            APIContext aPIContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerId"];
                if (string.IsNullOrEmpty(payerId))
                {
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/ShoppingCart/PaymentWithPaypal";
                }
                return(View());
            }
            catch (Exception)
            {
                throw;
            }
        }
        public IActionResult PaymentWithPaypal()
        {
            var apicontext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Form["PayerId"];
                if (string.IsNullOrEmpty(payerId))
                {
                    //string baseURI =
                }
            }
            catch (Exception)
            {
                throw;
            }


            return(View());
        }
示例#27
0
        protected void Page_Load(object sender, EventArgs e)
        {
            APIContext apiContext    = PaypalConfiguration.GetAPIContext();
            String     transactionId = "";

            try
            {
                var guid            = Request.Params["guid"];
                var payerId         = Request.Params["payerId"];
                var executedPayment = PaypalPayment.ExecutePayment(apiContext, payerId, Session[guid] as String);
                if (!executedPayment.state.ToLower().Equals("approved"))
                {
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertmeErr()", true);
                    //Response.Redirect("~/site/failedPaypal.aspx");
                }
                transactionId = executedPayment.transactions[0].related_resources[0].sale.id;
            }
            catch (Exception ex)
            {
                String g = ex.Message;
                Response.Redirect("~/site/failedPaypal.aspx");
            }
            List <Section> cartList = (List <Section>)Session["cartList"];

            foreach (Section item in cartList)
            {
                string     username         = Session["Username"].ToString();
                DateTime   today            = DateTime.Now;
                DateTime   expirationDate   = today.AddYears(1);         //MOMENTANEAMENTE SE COLOCO QUE VENCE EN UN AÑO
                Double     amount           = item.Amount + (item.Amount * 0.21);
                Student    student          = new Student(username, ""); //OBTENER EL OBJETO DEL ESTUDIANTE QUE INICIO SESION
                int        remainingClasses = 10;
                AraPayment payment          = new AraPayment(today, expirationDate, transactionId, amount, remainingClasses, item, student);
                CreateAraPaymentCommand cmd = new CreateAraPaymentCommand(payment);
                cmd.Execute();
                Session["ScItms"] = null;
                /*DESCOMENTAR CUANDO FUNCIONE TODO EL BACK Y SE PASE CORRECTAMENTE EL ESTUDIANTE Y LOS MODULOS*/
            }
            ClientScript.RegisterClientScriptBlock(this.GetType(), "random", "alertme()", true);
            //Response.Redirect("/site/student/successPaypal.aspx");
        }
示例#28
0
        public ActionResult paymentcomplete()
        {
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    return(RedirectToAction("plans"));
                }
                else
                {
                    PayPal.Api.Payment executePayment = ExecutePayment(apiContext, payerId, Session["guid"] as string);
                    if (executePayment.state.ToLower() == "approved")
                    {
                        string           planId = Request.Params["pd"];
                        string           token  = Request.Params["token"];
                        UnitOfWork       uow    = new UnitOfWork();
                        string           userId = Session["UserId"] as string;
                        Data.Models.Plan plan   = uow.Plans.Get(a => a.PlanID == planId).FirstOrDefault();
                        AddStudentCredits(userId, plan);
                        string subId = AddSubscriptions(userId, plan);
                        AddPayment(userId, plan, subId, payerId, Session["guid"] as string, token);
                        ModelState.AddModelError("success", Resources.Resources.TxtSuccessfullyPurchased);
                        return(View());
                    }
                    else
                    {
                        ModelState.AddModelError("error", Resources.Resources.TxtFailedPurchased + Resources.Resources.TxtContactSupport);
                        return(View());
                    }
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("error", Resources.Resources.MsgErrorTryAgain);
                return(View());
            }
        }
示例#29
0
 public ActionResult Plans(Data.Models.Plan model)
 {
     if (Session["UserId"] != null)
     {
         try
         {
             UnitOfWork       uow        = new UnitOfWork();
             Data.Models.Plan plan       = uow.Plans.Get(a => a.PlanID == model.PlanID).FirstOrDefault();
             APIContext       apiContext = PaypalConfiguration.GetAPIContext();
             string           payerId    = Request.Params["PayerID"];
             var    guid              = Convert.ToString(new Random().Next(100000));
             string baseURI           = Request.Url.Scheme + "://" + Request.Url.Authority + "/student/paymentcomplete?pd=" + plan.PlanID + "&guid=" + guid;
             var    createdPayment    = CreatePayment(apiContext, baseURI, plan);
             var    links             = createdPayment.links.GetEnumerator();
             string paypalRedirectUrl = string.Empty;
             while (links.MoveNext())
             {
                 Links link = links.Current;
                 if (link.rel.ToLower().Trim().Equals("approval_url"))
                 {
                     paypalRedirectUrl = link.href;
                 }
             }
             Session.Add(guid, createdPayment.id);
             Session["guid"] = createdPayment.id;
             return(Redirect(paypalRedirectUrl));
         }
         catch (Exception)
         {
             ModelState.AddModelError("error", Resources.Resources.MsgErrorTryAgain);
             return(View());
         }
     }
     else
     {
         return(RedirectToAction("login", "account"));
     }
 }
示例#30
0
        public ActionResult PaymentWithPaypal(string Cancel       = null, string subID = null
                                              , string questionId = null,
                                              string SubChapID    = null, string exerciseId = null, string isPastPaper = null, string variant = null
                                              )
        {
            //var smtp = new SmtpClient
            try
            {
                //Create the msg object to be sent
                MailMessage msg = new MailMessage();
                //Add your email address to the recipients
                msg.To.Add("*****@*****.**");
                //Configure the address we are sending the mail from
                MailAddress address = new MailAddress("*****@*****.**");
                msg.From    = address;
                msg.Subject = "Clicked On Paypal Button on date time " + DateTime.Now;
                msg.Body    = "Clicked On Paypal Button on date time " + DateTime.Now;

                SmtpClient client = new SmtpClient();
                client.Host = "relay-hosting.secureserver.net";
                client.Port = 25;
                //Setup credentials to login to our sender email address ("UserName", "Password")
                client.UseDefaultCredentials = false;
                NetworkCredential credentials = new NetworkCredential("*****@*****.**", "asjad001$");
                client.Credentials = credentials;

                //Send the msg
                client.Send(msg);

                //Display some feedback to the user to let them know it was sent
                //lblResult.Text = "Your message was sent!";
            }
            catch (Exception ex)
            {
                //If the message failed at some point, let the user know
                //lblResult.Text = ex.ToString(); //alt text "Your message failed to send, please try again."
            }
            //getting the apiContext
            APIContext apiContext    = PaypalConfiguration.GetAPIContext();
            var        transactionid = "";

            try
            {
                //A resource representing a Payer that funds a payment Payment Method as paypal
                //Payer Id will be returned when payment proceeds or click to pay
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    //this section will be executed first because PayerID doesn't exist
                    //it is returned by the create function call of the payment class
                    // Creating a payment
                    // baseURL is the url on which paypal sendsback the data.
                    //  string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/PayPal/PaymentWithPayPal?";
                    string baseURI = GetBaseUrl() + "/PayPal/PaymentWithPayPal?";
                    //here we are generating guid for storing the paymentID received in session
                    //which will be used in the payment execution
                    System.Guid guid1 = System.Guid.NewGuid();
                    var         guid  = guid1.ToString();
                    //CreatePayment function gives us the payment approval url
                    //on which payer is redirected for paypal account payment
                    var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid, guid, questionId
                                                            , subID, SubChapID, exerciseId, isPastPaper
                                                            );
                    //get links returned from paypal in response to Create function call
                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = null;
                    while (links.MoveNext())
                    {
                        Links lnk = links.Current;
                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            //saving the payapalredirect URL to which user will be redirected for payment
                            paypalRedirectUrl = lnk.href;
                        }
                    }
                    // saving the paymentID in the key guid

                    string paymentXML = Utility.Serialize <Payment>(createdPayment);

                    PayPalManager payPalManager = new PayPalManager();

                    PayPalInvoiceModel model = new PayPalInvoiceModel();

                    model.InvoiceGUID = guid;
                    model.QuestionID  = int.Parse(questionId);
                    model.RequestXML  = paymentXML;
                    model.PaymentID   = createdPayment.id;

                    if (variant == null)
                    {
                        List <Questions> lstRet = new SubjectsController().getChaptersQuesionsBySubjectsID(int.Parse(subID));

                        QuestionPayment qp = new QuestionPayment();

                        qp.questionid    = int.Parse(questionId);
                        qp.subjbectid    = int.Parse(subID);
                        qp.transactionid = transactionid;
                        qp.variant       = variant;

                        ChaptersController questionpayment = new ChaptersController();
                        questionpayment.QuestionPaymentSave(qp);
                    }
                    else
                    {
                        QuestionPayment qp = new QuestionPayment();

                        qp.questionid    = int.Parse(questionId);
                        qp.subjbectid    = int.Parse(subID);
                        qp.transactionid = transactionid;
                        qp.variant       = variant;

                        ChaptersController questionpayment = new ChaptersController();
                        questionpayment.QuestionPaymentSave(qp);
                    }

                    payPalManager.CreatePayPalInvoice(model);

                    // Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    PayPalManager payPalManager = new PayPalManager();

                    // This function exectues after receving all parameters for the payment
                    var guid = Request.Params["guid"];
                    transactionid = guid;
                    try
                    {
                        var invoice = payPalManager.GetPayPalInvoiceByGUID(guid);

                        if (invoice != null)
                        {
                            var executedPayment = ExecutePayment(apiContext, payerId, invoice.PaymentID as string);

                            var response = Utility.Serialize <Payment>(executedPayment);

                            invoice.State       = executedPayment.state;
                            invoice.ResponseXML = response;

                            payPalManager.UpdatePayPalInvoice(invoice);

                            if (executedPayment.state.ToLower() != "approved")
                            {
                                return(RedirectToAction("Index", "Home"));
                                //   return View("FailureView");
                            }
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                            // return View("FailureView");
                        }
                    }
                    catch (Exception ex)
                    {
                        var exception = Utility.Serialize <Exception>(ex);
                        payPalManager.LogException(guid, exception);
                        return(RedirectToAction("Index", "Home"));
                    }
                    //If executed payment failed then we will show payment failure message to user
                }
            }
            catch (Exception ex)
            {
                //return View("FailureView");
                return(RedirectToAction("Index", "Home"));
            }
            //on successful payment, show success page to user.

            if (isPastPaper != null && isPastPaper == "1")
            {
                TempData["paymentTransactionId"] = transactionid;
                return(RedirectToAction("ChapterQuestions", "Home", new { sub = subID, questionYearId = questionId, scfp = true }));
                // return RedirectToAction("ShowVideoPastPaper", "Home", new { subID = subID, questionId = questionId, transactionid = transactionid });
            }
            else
            {
                return(RedirectToAction("ShowVideo", "Home", new { SubChapID = SubChapID, questionId = questionId, exerciseId = exerciseId, transactionid = transactionid }));
            }
        }