示例#1
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"));
        }
示例#2
0
        public static int InsertUD(UserDonate ud)
        {
            NGOEntities e = new NGOEntities();

            ud.TypeCard   = "VISA";
            ud.DateCreate = DateTime.Now;
            e.UserDonates.Add(ud);
            if (e.SaveChanges() > 0)
            {
                var donate = e.Donates.Find(ud.DonateID);
                donate.TotalMoney += ud.Money;
                var user = e.Users.Find(ud.UserID);
                user.MoneyDonate += ud.Money;
                e.SaveChanges();
                return(1);
            }
            return(0);
        }
示例#3
0
 public static int InsertUD(UserDonate ud)
 {
     return(UserDonateDAO.InsertUD(ud));
 }