Example #1
0
        public ActionResult ManageGiving(ManageGivingModel m)
        {
            m.SetCurrentDatabase(CurrentDatabase);
            SetHeaders(m.orgid);

            // only validate if the amounts are greater than zero.
            if (m.FundItemsChosen().Sum(f => f.amt) > 0)
            {
                m.ValidateModel(ModelState);
                if (!ModelState.IsValid)
                {
                    if (m.person == null)
                    {
                        return(Message("person not found"));
                    }
                    m.total = 0;
                    foreach (var ff in m.FundItemsChosen())
                    {
                        m.total += ff.amt;
                    }
                    return(View("ManageGiving/Setup", m));
                }
            }
            else
            {
                ModelState.AddModelError("funds", "You must choose at least one fund to give to.");
                return(View("ManageGiving/Setup", m));
            }
            if (CurrentDatabase.Setting("UseRecaptchaForManageGiving"))
            {
                if (!GoogleRecaptcha.IsValidResponse(HttpContext, CurrentDatabase))
                {
                    ModelState.AddModelError("TranId", "ReCaptcha validation failed.");
                    return(View("ManageGiving/Setup", m));
                }
            }

            try
            {
                m.Update();
            }
            catch (Exception ex)
            {
                if (ex.Message == "InvalidVaultId")
                {
                    m = ClearPaymentInfo(m, ModelState);
                }
                else
                {
                    ModelState.AddModelError("form", ex.Message);
                }
            }
            if (!ModelState.IsValid)
            {
                return(View("ManageGiving/Setup", m));
            }

            RequestManager.SessionProvider.Add("managegiving", m);
            return(Redirect("/OnlineReg/ConfirmRecurringGiving"));
        }
Example #2
0
        public ActionResult ManageGiving(ManageGivingModel m)
        {
            SetHeaders(m.orgid);

            // only validate if the amounts are greater than zero.
            if (m.FundItemsChosen().Sum(f => f.amt) > 0)
            {
                m.ValidateModel(ModelState);
                if (!ModelState.IsValid)
                {
                    if (m.person == null)
                    {
                        return(Message("person not found"));
                    }
                    m.total = 0;
                    foreach (var ff in m.FundItemsChosen())
                    {
                        m.total += ff.amt;
                    }
                    return(View("ManageGiving/Setup", m));
                }
            }
            if (CurrentDatabase.Setting("UseRecaptchaForManageGiving"))
            {
                if (!GoogleRecaptcha.IsValidResponse(HttpContext, CurrentDatabase))
                {
                    ModelState.AddModelError("TranId", "ReCaptcha validation failed.");
                    return(View("ManageGiving/Setup", m));
                }
            }

            try
            {
                m.Update();
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("form", ex.Message);
            }
            if (!ModelState.IsValid)
            {
                return(View("ManageGiving/Setup", m));
            }

            TempData["managegiving"] = m;
            return(Redirect("/OnlineReg/ConfirmRecurringGiving"));
        }
        public async Task <IActionResult> EnviarMensagem([FromForm] ContatoDTO contatoDto)
        {
            if (!await GoogleRecaptcha.IsReCaptchaPassedAsync(Request.Form["g-recaptcha-response"], _config["GoogleReCaptcha:SecretKey"]))
            {
                return(BadRequest(new { error = "Captcha inválido" }));
            }

            var contato = Mapper.Map <Contato>(contatoDto);

            bool enviouEmail = _emailSender.EnviarEmail(contato.Nome, contato.Email, contato.Mensagem);

            if (enviouEmail)
            {
                return(Ok(contatoDto));
            }

            return(BadRequest(new { error = "Falha ao enviar email" }));
        }
Example #4
0
        public ActionResult OnePageGiving(PaymentForm pf, Dictionary <int, decimal?> fundItem)
        {
            // need save off the original amt to pay if there is an error later on.
            var amtToPay = pf.AmtToPay;

            var id = pf.OrgId;

            if (id == null)
            {
                return(Message("Missing OrgId"));
            }

            if (!Util.ValidEmail(pf.Email))
            {
                ModelState.AddModelError("Email", "Need a valid email address");
            }
            if (pf.IsUs && !pf.Zip.HasValue())
            {
                ModelState.AddModelError("Zip", "Zip is Required for US");
            }
            if (pf.ShowCampusOnePageGiving)
            {
                if ((pf.CampusId ?? 0) == 0)
                {
                    ModelState.AddModelError("CampusId", "Campus is Required");
                }
            }

            var m = new OnlineRegModel(Request, CurrentDatabase, pf.OrgId, pf.testing, null, null, pf.source)
            {
                URL = $"/OnePageGiving/{pf.OrgId}"
            };

            var pid = Util.UserPeopleId;

            if (pid.HasValue)
            {
                PrePopulate(m, pid.Value);
            }

            // we need to always retrieve the entire list of funds for one page giving calculations.
            m.List[0].RetrieveEntireFundList = true;

            // first re-build list of fund items with only ones that contain a value (amt).
            var fundItems = fundItem.Where(f => f.Value.GetValueOrDefault() > 0).ToDictionary(f => f.Key, f => f.Value);

            var designatedFund = m.settings[id.Value].DonationFundId ?? 0;

            if (designatedFund != 0)
            {
                fundItems.Add(designatedFund, pf.AmtToPay);
            }

            // set the fund items on online reg person if there are any.
            if (fundItems.Any())
            {
                m.List[0].FundItem = fundItems;
                pf.AmtToPay        = m.List[0].FundItemsChosen().Sum(f => f.Amt);
            }

            if (pf.AmtToPay.GetValueOrDefault() == 0)
            {
                ModelState.AddModelError("AmtToPay", "Invalid Amount");
            }

            SetHeaders(m);
            SetInstructions(m);

            var p = m.List[0];

            if (pf.ShowCampusOnePageGiving)
            {
                pf.Campuses = p.Campuses().ToList();
            }

            if (!ModelState.IsValid)
            {
                m.List[0].FundItem = fundItem;
                pf.AmtToPay        = amtToPay;
                return(View("OnePageGiving/Index", new OnePageGivingModel()
                {
                    OnlineRegPersonModel = m.List[0], PaymentForm = pf
                }));
            }

            if (CheckAddress(pf) == false)
            {
                m.List[0].FundItem = fundItem;
                pf.AmtToPay        = amtToPay;
                return(View("OnePageGiving/Index", new OnePageGivingModel()
                {
                    OnlineRegPersonModel = m.List[0], PaymentForm = pf
                }));
            }


            if (!ModelState.IsValid)
            {
                m.List[0].FundItem = fundItem;
                pf.AmtToPay        = amtToPay;
                return(View("OnePageGiving/Index", new OnePageGivingModel()
                {
                    OnlineRegPersonModel = m.List[0], PaymentForm = pf
                }));
            }

            p.orgid          = m.Orgid;
            p.FirstName      = pf.First;
            p.LastName       = pf.Last;
            p.EmailAddress   = pf.Email;
            p.Phone          = pf.Phone;
            p.AddressLineOne = pf.Address;
            p.City           = pf.City;
            p.State          = pf.State;
            p.ZipCode        = pf.Zip;
            p.Country        = pf.Country;
            if (pf.ShowCampusOnePageGiving)
            {
                p.Campus = pf.CampusId.ToString();
            }

            p.IsNew = p.person == null;

            if (pf.testing)
            {
                pf.CheckTesting();
            }

            if (pf.Country.HasValue() && !pf.Zip.HasValue())
            {
                pf.Zip = "NA";
            }

            pf.ValidatePaymentForm(ModelState, false);
            if (!ModelState.IsValid)
            {
                m.List[0].FundItem = fundItem;
                pf.AmtToPay        = amtToPay;
                return(View("OnePageGiving/Index", new OnePageGivingModel()
                {
                    OnlineRegPersonModel = m.List[0], PaymentForm = pf
                }));
            }


            if (m?.UserPeopleId != null && m.UserPeopleId > 0)
            {
                pf.CheckStoreInVault(ModelState, m.UserPeopleId.Value);
            }
            if (!ModelState.IsValid)
            {
                m.List[0].FundItem = fundItem;
                pf.AmtToPay        = amtToPay;
                return(View("OnePageGiving/Index", new OnePageGivingModel()
                {
                    OnlineRegPersonModel = m.List[0], PaymentForm = pf
                }));
            }

            if (CurrentDatabase.Setting("UseRecaptcha"))
            {
                if (!GoogleRecaptcha.IsValidResponse(HttpContext, CurrentDatabase))
                {
                    m.List[0].FundItem = fundItem;
                    pf.AmtToPay        = amtToPay;
                    ModelState.AddModelError("TranId", "ReCaptcha validation failed.");
                    return(View("OnePageGiving/Index", new OnePageGivingModel {
                        OnlineRegPersonModel = m.List[0],
                        PaymentForm = pf
                    }));
                }
            }

            var ti = pf.ProcessPaymentTransaction(m);

            if ((ti.Approved ?? false) == false)
            {
                ModelState.AddModelError("TranId", ti.Message);

                m.List[0].FundItem = fundItem;
                pf.AmtToPay        = amtToPay;
                return(View("OnePageGiving/Index", new OnePageGivingModel()
                {
                    OnlineRegPersonModel = m.List[0], PaymentForm = pf
                }));
            }
            if (pf.Zip == "NA")
            {
                pf.Zip = null;
            }

            var ret = m.ConfirmTransaction(ti);

            switch (ret.Route)
            {
            case RouteType.ModelAction:
                if (ti.Approved == true)
                {
                    var url = $"/OnePageGiving/ThankYou/{id}{(pf.testing ? $"?testing=true&source={pf.source}" : $"?source={pf.source}")}";
                    return(Redirect(url));
                }
                ErrorSignal.FromCurrentContext().Raise(new Exception(ti.Message));
                ModelState.AddModelError("TranId", ti.Message);

                m.List[0].FundItem = fundItem;
                pf.AmtToPay        = amtToPay;
                return(View("OnePageGiving/Index", new OnePageGivingModel()
                {
                    OnlineRegPersonModel = m.List[0], PaymentForm = pf
                }));
Example #5
0
        public ActionResult ProcessPayment(PaymentForm pf)
        {
            if (pf.ProcessType == PaymentProcessTypes.EmpytProcess)
            {
                pf.ProcessType = PaymentProcessTypes.OnlineRegistration;
            }
            // One time or Reg...
            Response.NoCache();

#if DEBUG
#else
            if (Session["FormId"] != null)
            {
                if ((Guid)Session["FormId"] == pf.FormId)
                {
                    return(Message("Already submitted"));
                }
            }
#endif

            OnlineRegModel m  = null;
            var            ed = CurrentDatabase.RegistrationDatas.SingleOrDefault(e => e.Id == pf.DatumId);
            if (ed != null)
            {
                m = Util.DeSerialize <OnlineRegModel>(ed.Data);
            }

#if DEBUG
#else
            if (m != null && m.History.Any(h => h.Contains("ProcessPayment")))
            {
                return(Content("Already submitted"));
            }
#endif

            int?datumid = null;
            if (m != null)
            {
                m.TermsSignature = pf.TermsSignature;
                datumid          = m.DatumId;
                var msg = m.CheckDuplicateGift(pf.AmtToPay);
                if (Util.HasValue(msg))
                {
                    return(Message(msg));
                }
            }
            if (IsCardTester(pf, "Payment Page"))
            {
                return(Message("Found Card Tester"));
            }

            int?GatewayId = MultipleGatewayUtils.GatewayId(CurrentDatabase, m?.ProcessType ?? pf.ProcessType);

            if (CurrentDatabase.Setting("UseRecaptcha") && GatewayId != (int)GatewayTypes.Pushpay)
            {
                if (!GoogleRecaptcha.IsValidResponse(HttpContext, CurrentDatabase))
                {
                    CurrentDatabase.LogActivity("OnlineReg Error ReCaptcha validation failed.", pf.OrgId, did: datumid);
                    ModelState.AddModelError("form", "ReCaptcha validation failed.");
                    return(View("Payment/Process", pf));
                }
            }

            RouteModel ret;

            if ((int)GatewayTypes.Pushpay == GatewayId)
            {
                int orgId;
                ret      = pf.ProcessExternalPayment(m, out orgId);
                pf.OrgId = orgId;
            }
            else
            {
                ret = pf.ProcessPayment(ModelState, m);
            }
            SetHeaders(pf.OrgId ?? 0);

            switch (ret.Route)
            {
            case RouteType.ModelAction:
                return(View(ret.View, ret.Model));

            case RouteType.AmtDue:
                ViewBag.amtdue = ret.AmtDue;
                return(View(ret.View, ret.Transaction));

            case RouteType.Error:
                CurrentDatabase.LogActivity("OnlineReg Error " + ret.Message, pf.OrgId, did: datumid);
                return(Message(ret.Message));

            case RouteType.ValidationError:
                return(View(ret.View, pf));

            default:     // unexptected Route
                if (ModelState.IsValid)
                {
                    ErrorSignal.FromCurrentContext().Raise(new Exception("OnlineReg Unexpected route datum= " + datumid));
                    CurrentDatabase.LogActivity("OnlineReg Unexpected Route " + ret.Message, oid: pf.OrgId, did: datumid);
                    ModelState.AddModelError("form", "unexpected error in payment processing");
                }
                return(View(ret.View ?? "Payment/Process", pf));
            }
        }