Exemplo n.º 1
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"));
        }
        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"));
        }
Exemplo n.º 3
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");
            }
        }
Exemplo n.º 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"));
        }
Exemplo n.º 5
0
        private void ConfigurePayPal(IServiceCollection services)
        {
            PaypalConfiguration paypalConfiguration = Configuration.GetSection(nameof(PaypalConfiguration))
                                                      .Get <PaypalConfiguration>();

            services.AddSingleton(paypalConfiguration);
            services.AddTransient <PaypalService>();
        }
Exemplo n.º 6
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"));
        }
Exemplo n.º 7
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"));
        }
Exemplo n.º 8
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() }));
        }
Exemplo n.º 9
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"));
            }
        }
Exemplo n.º 10
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());
        }
Exemplo n.º 11
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"));
        }
Exemplo n.º 12
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"));
        }
Exemplo n.º 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"));
        }
Exemplo n.º 14
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 }));
        }
        // 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"));
        }
Exemplo n.º 17
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"));
        }
Exemplo n.º 18
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 }));
        }
Exemplo n.º 19
0
        // 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"));
        }
Exemplo n.º 20
0
        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 }));
        }
Exemplo n.º 21
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"));
        }
Exemplo n.º 22
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"));
        }
Exemplo n.º 24
0
 /// <summary>
 /// Payment Deduct through Carditcard ID
 /// </summary>
 /// <param name="BookingID"></param>
 /// <returns></returns>
 public ActionResult PaypalValutthroughDeductPayment(int BookingID = 0)
 {
     if (BookingID != 0)
     {
         var    db               = GetDb();
         String UserID           = User.Identity.GetUserId();
         PayPalbusinessLogic obj = new PayPalbusinessLogic();
         // Token Get;
         string Token             = PaypalConfiguration.GetAccessToken();
         var    UserAccountDetail = db.UserAccountDetail.Where(x => x.UserId == UserID && x.BookingID == BookingID).FirstOrDefault();
         var    response          = obj.GetCraditCardPaypalValut(Token, UserAccountDetail.CraditcardID);
         var    _AmountViewModel  = (from ep in db.UserAccountDetail
                                     join e in db.Booking on ep.BookingID equals e.ID
                                     join see in db.SessionType on e.SessionType equals see.ID
                                     where ep.UserId == UserID && ep.BookingID == BookingID
                                     select new AmountViewModel
         {
             ID = ep.ID,
             Amount = see.Price,
             UserID = ep.UserId,
             CraditcardID = ep.CraditcardID,
             Email = ep.Email,
             BookingID = ep.BookingID,
             SessionType = e.SessionType,
             UserDetailID = ep.ID
         }).FirstOrDefault();
         if (_AmountViewModel != null)
         {
             var PapalvalutAmountDeductResponse = obj.AmountDeduct(_AmountViewModel);
             if (PapalvalutAmountDeductResponse.state != "created")
             {
                 PaymentDetails PaymentDetails = new PaymentDetails();
                 PaymentDetails.BookingID        = _AmountViewModel.BookingID;
                 PaymentDetails.Createddate      = DateTime.Now;
                 PaymentDetails.Updateddate      = DateTime.Now;
                 PaymentDetails.Status           = "Success";
                 PaymentDetails.UserId           = _AmountViewModel.UserID;
                 PaymentDetails.TotalAmount      = PapalvalutAmountDeductResponse.Amount;
                 PaymentDetails.Intent           = PapalvalutAmountDeductResponse.intent;
                 PaymentDetails.ResponseID       = PapalvalutAmountDeductResponse.id;
                 PaymentDetails.UserDetailID     = _AmountViewModel.UserDetailID;
                 PaymentDetails.PaymentProcessed = true;
                 db.PaymentDetail.Add(PaymentDetails);
             }
         }
     }
     return(View());
 }
        //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"));
        }
Exemplo n.º 26
0
        public ActionResult PaymentWithPaypal(string cancel = null)
        {
            var apiContext = PaypalConfiguration.GetApiContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    var baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + "Paypal/PaymentWithPaypal?";

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

                    var createdPayment = CreatePayment(apiContext, baseUrl + "guid=" + guid);

                    var links = createdPayment.links.GetEnumerator();

                    string paypalRedirectUrl = null;
                    while (links.MoveNext())
                    {
                        var link = links.Current;
                        if (link.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            paypalRedirectUrl = link.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("failed"));
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            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"));
        }
Exemplo n.º 28
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;
            }
        }
Exemplo n.º 29
0
        public IActionResult PaymentWithPaypal()
        {
            var apicontext = PaypalConfiguration.GetAPIContext();

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


            return(View());
        }
Exemplo n.º 30
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");
        }