Exemple #1
0
        public ActionResult ProcessPayment(PaymentForm pf)
        {
            if (Session["FormId"] != null)
                if ((Guid)Session["FormId"] == pf.FormId)
                    return Content("Already submitted");
            OnlineRegModel m = null;
            var ed = DbUtil.Db.ExtraDatas.SingleOrDefault(e => e.Id == pf.DatumId);
            if (ed != null)
                m = Util.DeSerialize<OnlineRegModel>(ed.Data);

            if(m != null && m.History.Contains("ProcessPayment"))
                    return Content("Already submitted");

            if (pf.AmtToPay < 0) pf.AmtToPay = 0;
            if (pf.Donate < 0) pf.Donate = 0;

            pf.AllowCoupon = false;

            SetHeaders(pf.OrgId ?? 0);
            ViewBag.Url = pf.Url;
            ViewBag.timeout = INT_timeout;

            if ((pf.AmtToPay ?? 0) <= 0 && (pf.Donate ?? 0) <= 0)
            {
                DbUtil.Db.SubmitChanges();
                ModelState.AddModelError("form", "amount zero");
                return View("ProcessPayment", pf);
            }

            try
            {
                if (pf.Type == "B")
                    Payments.ValidateBankAccountInfo(ModelState, pf.Routing, pf.Account);
                if (pf.Type == "C")
                    Payments.ValidateCreditCardInfo(ModelState, pf.CreditCard, pf.Expires, pf.CCV);

                if (!ModelState.IsValid)
                    return View("ProcessPayment", pf);

                if (pf.IsLoggedIn == true && pf.SavePayInfo == true)
                {
                    var gateway = OnlineRegModel.GetTransactionGateway();
                    if (gateway == "authorizenet")
                    {
                        var au = new AuthorizeNet(DbUtil.Db, m.testing ?? false);
                        if ((pf.Type == "B" && !pf.Routing.StartsWith("X") && !pf.Account.StartsWith("X"))
                            || (pf.Type == "C" && !pf.CreditCard.StartsWith("X")))
                            au.AddUpdateCustomerProfile(m.UserPeopleId.Value,
                                pf.Type,
                                pf.CreditCard,
                                Payments.NormalizeExpires(pf.Expires),
                                pf.MaskedCCV != null && pf.MaskedCCV.StartsWith("X") ? pf.CCV : pf.MaskedCCV,
                                pf.Routing,
                                pf.Account);
                    }
                    else if (gateway == "sage")
                    {
                        var sg = new CmsData.SagePayments(DbUtil.Db, m.testing ?? false);
                        if ((pf.Type == "B" && !pf.Routing.StartsWith("X") && !pf.Account.StartsWith("X"))
                            || (pf.Type == "C" && !pf.CreditCard.StartsWith("X")))
                            sg.storeVault(m.UserPeopleId.Value,
                                          pf.Type,
                                          pf.CreditCard,
                                          Payments.NormalizeExpires(pf.Expires),
                                          pf.MaskedCCV != null && pf.MaskedCCV.StartsWith("X") ? pf.CCV : pf.MaskedCCV,
                                          pf.Routing,
                                          pf.Account,
                                          pf.IsGiving == true);
                    }
                    else
                        throw new Exception("ServiceU not supported");

                }
                var ti = ProcessPaymentTransaction(m, pf);

                if (ti.Approved == false)
                {
                    ModelState.AddModelError("form", ti.Message);
                    return View("ProcessPayment", pf);
                }
                if (m != null)
                {
                    m.TranId = ti.Id;
                    m.History.Add("ProcessPayment");
                    ed.Data = Util.Serialize<OnlineRegModel>(m);
                    ed.Completed = true;
                    DbUtil.Db.SubmitChanges();
                }
                Session["FormId"] = pf.FormId;
                if (pf.DatumId > 0)
                {
                    confirm = ConfirmTransaction(m, ti.TransactionId);
                    if (confirm.StartsWith("error:"))
                    {
                        TempData["error"] = confirm.Substring(6);
                        return Redirect("/Error");
                    }
                    return View(confirm);
                }

                ConfirmDuePaidTransaction(ti, ti.TransactionId, sendmail: true);
                return View("ConfirmDuePaid", ti);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("form", ex.Message);
                return View("ProcessPayment", pf);
            }
        }
        public ActionResult ManageGiving(ManageGivingModel m)
        {
            SetHeaders(m.orgid);
            RemoveNonDigitsIfNecessary(m);
            m.ValidateModel(ModelState);
            if (!ModelState.IsValid)
                return View(m);
            try
            {
                var gateway = OnlineRegModel.GetTransactionGateway();
                if (gateway == "authorizenet")
                {
                    var au = new AuthorizeNet(DbUtil.Db, m.testing);
                    au.AddUpdateCustomerProfile(m.pid,
                        m.Type,
                        m.Cardnumber,
                        m.Expires,
                        m.Cardcode,
                        m.Routing,
                        m.Account);

                }
                else if (gateway == "sage")
                {
                    var sg = new SagePayments(DbUtil.Db, m.testing);
                    sg.storeVault(m.pid,
                        m.Type,
                        m.Cardnumber,
                        m.Expires,
                        m.Cardcode,
                        m.Routing,
                        m.Account,
                        giving: true);
                }
                else
                    throw new Exception("ServiceU not supported");

                var mg = m.person.ManagedGiving();
                if (mg == null)
                {
                    mg = new ManagedGiving();
                    m.person.ManagedGivings.Add(mg);
                }
                mg.SemiEvery = m.SemiEvery;
                mg.Day1 = m.Day1;
                mg.Day2 = m.Day2;
                mg.EveryN = m.EveryN;
                mg.Period = m.Period;
                mg.StartWhen = m.StartWhen;
                mg.StopWhen = m.StopWhen;
                mg.NextDate = mg.FindNextDate(DateTime.Today);

                var pi = m.person.PaymentInfo();
                pi.FirstName = m.firstname.Truncate(50);
                pi.MiddleInitial = m.middleinitial.Truncate(10);
                pi.LastName = m.lastname.Truncate(50);
                pi.Suffix = m.suffix.Truncate(10);
                pi.Address = m.address.Truncate(50);
                pi.City = m.city.Truncate(50);
                pi.State = m.state.Truncate(10);
                pi.Zip = m.zip.Truncate(15);
                pi.Phone = m.phone.Truncate(25);

                var q = from ra in DbUtil.Db.RecurringAmounts
                        where ra.PeopleId == m.pid
                        select ra;
                DbUtil.Db.RecurringAmounts.DeleteAllOnSubmit(q);
                DbUtil.Db.SubmitChanges();
                foreach (var c in m.FundItemsChosen())
                {
                    var ra = new RecurringAmount
                    {
                        PeopleId = m.pid,
                        FundId = c.fundid,
                        Amt = c.amt
                    };
                    DbUtil.Db.RecurringAmounts.InsertOnSubmit(ra);
                }
                DbUtil.Db.SubmitChanges();
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("form", ex.Message);
            }
            if (!ModelState.IsValid)
                return View(m);
            TempData["managegiving"] = m;
            return Redirect("ConfirmRecurringGiving");
        }
Exemple #3
0
        //private string confirm;
        public ActionResult ProcessPayment(PaymentForm pf)
        {
            #if DEBUG
            #else
            if (Session["FormId"] != null)
                if ((Guid)Session["FormId"] == pf.FormId)
                    return Content("Already submitted");
            #endif
            OnlineRegModel m = null;
            var ed = DbUtil.Db.ExtraDatas.SingleOrDefault(e => e.Id == pf.DatumId);
            if (ed != null)
                m = Util.DeSerialize<OnlineRegModel>(ed.Data);

            #if DEBUG
            #else
            if(m != null && m.History.Contains("ProcessPayment") && !pf.PayBalance)
                    return Content("Already submitted");
            #endif

            if (pf.AmtToPay < 0) pf.AmtToPay = 0;
            if (pf.Donate < 0) pf.Donate = 0;

            pf.AllowCoupon = false;

            SetHeaders(pf.OrgId ?? 0);

            if ((pf.AmtToPay ?? 0) <= 0 && (pf.Donate ?? 0) <= 0)
            {
                DbUtil.Db.SubmitChanges();
                ModelState.AddModelError("form", "amount zero");
                return View("Payment/Process", pf);
            }

            try
            {
                if (pf.Type == "B")
                    Payments.ValidateBankAccountInfo(ModelState, pf.Routing, pf.Account);
                if (pf.Type == "C")
                    Payments.ValidateCreditCardInfo(ModelState, pf);

                if (!ModelState.IsValid)
                    return View("Payment/Process", pf);

                if (pf.IsLoggedIn == true && pf.SavePayInfo)
                {
                    var gateway = OnlineRegModel.GetTransactionGateway();
                    if (gateway == "authorizenet")
                    {
                        var au = new AuthorizeNet(DbUtil.Db, m.testing ?? false);
                        if ((pf.Type == "B" && !pf.Routing.StartsWith("X") && !pf.Account.StartsWith("X"))
                            || (pf.Type == "C" && !pf.CreditCard.StartsWith("X")))
                            au.AddUpdateCustomerProfile(m.UserPeopleId.Value,
                                pf.Type,
                                pf.CreditCard,
                                DbUtil.NormalizeExpires(pf.Expires).ToString2("MMyy"),
                                pf.MaskedCCV != null && pf.MaskedCCV.StartsWith("X") ? pf.CCV : pf.MaskedCCV,
                                pf.Routing,
                                pf.Account);
                    }
                    else if (gateway == "sage")
                    {
                        var sg = new CmsData.SagePayments(DbUtil.Db, m.testing ?? false);
                        if ((pf.Type == "B" && !pf.Routing.StartsWith("X") && !pf.Account.StartsWith("X"))
                            || (pf.Type == "C" && !pf.CreditCard.StartsWith("X")))
                            sg.storeVault(m.UserPeopleId.Value,
                                          pf.Type,
                                          pf.CreditCard,
                                          DbUtil.NormalizeExpires(pf.Expires).ToString2("MMyy"),
                                          pf.MaskedCCV != null && pf.MaskedCCV.StartsWith("X") ? pf.CCV : pf.MaskedCCV,
                                          pf.Routing,
                                          pf.Account,
                                          pf.IsGiving == true);
                    }
                    else
                        throw new Exception("ServiceU not supported");

                }
                if (pf.UseBootstrap)
                {
                    var r = AddressVerify.LookupAddress(pf.Address, "", "", "", pf.Zip);
                    if (r.Line1 != "error")
                    {
                        if (r.found == false)
                        {
                            ModelState.AddModelError("Zip",
                                r.address + ", to skip address check, Change the country to USA, Not Validated");
                            return View("Payment/Process", pf);
                        }
                        if (r.Line1 != pf.Address)
                            pf.Address = r.Line1;
                        if (r.City != (pf.City ?? ""))
                            pf.City = r.City;
                        if (r.State != (pf.State ?? ""))
                            pf.State = r.State;
                        if (r.Zip != (pf.Zip ?? ""))
                            pf.Zip = r.Zip;
                    }
                }
                var ti = ProcessPaymentTransaction(m, pf);

                if (ti.Approved == false)
                {
                    ModelState.AddModelError("form", ti.Message);
                    return View("Payment/Process", pf);
                }
                if (m != null)
                {
                    m.TranId = ti.Id;
                    m.History.Add("ProcessPayment");
                    ed.Data = Util.Serialize<OnlineRegModel>(m);
                    ed.Completed = true;
                    DbUtil.Db.SubmitChanges();
                }
                Session["FormId"] = pf.FormId;
                if (pf.DatumId > 0)
                {
                    try
                    {
                        var view = ConfirmTransaction(m, ti.TransactionId);
                        switch (view)
                        {
                            case ConfirmEnum.Confirm:
                                return View("Confirm", m);
                            case ConfirmEnum.ConfirmAccount:
                                return View("ConfirmAccount");
                        }
                    }
                    catch (Exception ex)
                    {
                        TempData["error"] = ex.Message;
                        return Redirect("/Error");
                    }
                }

                ConfirmDuePaidTransaction(ti, ti.TransactionId, sendmail: true);
                return View("PayAmtDue/Confirm", ti);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("form", ex.Message);
                return View("Payment/Process", pf);
            }
        }
Exemple #4
0
        public void Update()
        {
            var gateway = OnlineRegModel.GetTransactionGateway();
            if (gateway == "authorizenet")
            {
                var au = new AuthorizeNet(DbUtil.Db, testing);
                au.AddUpdateCustomerProfile(pid,
                    Type,
                    Cardnumber,
                    Expires,
                    Cardcode,
                    Routing,
                    Account);
            }
            else if (gateway == "sage")
            {
                var sg = new SagePayments(DbUtil.Db, testing);
                sg.storeVault(pid,
                    Type,
                    Cardnumber,
                    Expires,
                    Cardcode,
                    Routing,
                    Account,
                    giving: true);
            }
            else
                throw new Exception("ServiceU not supported");

            var mg = person.ManagedGiving();
            if (mg == null)
            {
                mg = new ManagedGiving();
                person.ManagedGivings.Add(mg);
            }
            mg.SemiEvery = SemiEvery;
            mg.Day1 = Day1;
            mg.Day2 = Day2;
            mg.EveryN = EveryN;
            mg.Period = Period;
            mg.StartWhen = StartWhen;
            mg.StopWhen = StopWhen;
            mg.NextDate = mg.FindNextDate(DateTime.Today);

            var pi = person.PaymentInfo();
            pi.FirstName = FirstName.Truncate(50);
            pi.MiddleInitial = Middle.Truncate(10);
            pi.LastName = LastName.Truncate(50);
            pi.Suffix = Suffix.Truncate(10);
            pi.Address = Address.Truncate(50);
            pi.City = City.Truncate(50);
            pi.State = State.Truncate(10);
            pi.Zip = Zip.Truncate(15);
            pi.Phone = Phone.Truncate(25);

            var q = from ra in DbUtil.Db.RecurringAmounts
                    where ra.PeopleId == pid
                    select ra;
            DbUtil.Db.RecurringAmounts.DeleteAllOnSubmit(q);
            DbUtil.Db.SubmitChanges();
            foreach (var c in FundItemsChosen())
            {
                var ra = new RecurringAmount
                {
                    PeopleId = pid,
                    FundId = c.fundid,
                    Amt = c.amt
                };
                DbUtil.Db.RecurringAmounts.InsertOnSubmit(ra);
            }
            DbUtil.Db.SubmitChanges();
        }