Beispiel #1
0
        public ActionResult ConfirmDuePaid(int?id, string transactionId, decimal?amount)
        {
            Response.NoCache();
            if (!id.HasValue)
            {
                return(View("Other/Unknown"));
            }

            if (!Util.HasValue(transactionId))
            {
                DbUtil.LogActivity("OnlineReg PayDueNoTransactionId");
                return(Message("error no transactionid"));
            }
            var ti = CurrentDatabase.Transactions.SingleOrDefault(tt => tt.Id == id);

            if (ti == null)
            {
                DbUtil.LogActivity("OnlineReg PayDueNoPendingTrans");
                return(Message("no pending transaction"));
            }
#if DEBUG
            ti.Testing = true;
#endif
            OnlineRegModel.ConfirmDuePaidTransaction(ti, transactionId, sendmail: true);
            ViewBag.amtdue = PaymentForm.AmountDueTrans(CurrentDatabase, ti).ToString("C");
            SetHeaders(ti.OrgId ?? 0);
            DbUtil.LogActivity("OnlineReg PayDueConfirm", ti.OrgId, ti.LoginPeopleId ?? ti.FirstTransactionPeopleId());
            return(View("PayAmtDue/Confirm", ti));
        }
Beispiel #2
0
        public ActionResult ConfirmDuePaid(int?id, string transactionId, decimal amount)
        {
            if (!id.HasValue)
            {
                return(View("Unknown"));
            }
            if (!transactionId.HasValue())
            {
                return(Message("error no transaction"));
            }

            var ti = DbUtil.Db.Transactions.SingleOrDefault(tt => tt.Id == id);

            if (ti == null)
            {
                return(Message("no pending transaction"));
            }
#if DEBUG
            ti.Testing = true;
#endif
            if (OnlineRegModel.GetTransactionGateway() == "serviceu")
            {
                ti = PaymentForm.CreateTransaction(DbUtil.Db, ti, amount);
            }
            ConfirmDuePaidTransaction(ti, transactionId, sendmail: true);
            ViewBag.amtdue = PaymentForm.AmountDueTrans(DbUtil.Db, ti).ToString("C");
            SetHeaders(ti.OrgId ?? 0);
            return(View("PayAmtDue/Confirm", ti));
        }
Beispiel #3
0
        public ActionResult PayAmtDue(string q)
        {
            // reached by the paylink in the confirmation email
            // which is produced in EnrollAndConfirm
            Response.NoCache();

            if (!Util.HasValue(q))
            {
                return(Message("unknown"));
            }

            var id = Util.Decrypt(q).ToInt2();
            var qq = from t in CurrentDatabase.Transactions
                     where t.OriginalId == id || t.Id == id
                     orderby t.Id descending
                     select new { t, email = t.TransactionPeople.FirstOrDefault().Person.EmailAddress };
            var i = qq.FirstOrDefault();

            if (i == null)
            {
                return(Message("no outstanding transaction"));
            }

            var ti     = i.t;
            var email  = i.email;
            var amtdue = PaymentForm.AmountDueTrans(CurrentDatabase, ti);

            if (amtdue == 0)
            {
                return(Message("no outstanding transaction"));
            }

#if DEBUG
            ti.Testing = true;
            if (!Util.HasValue(ti.Address))
            {
                ti.Address = "235 Riveredge";
                ti.City    = "Cordova";
                ti.Zip     = "38018";
                ti.State   = "TN";
            }
#endif
            var pf = PaymentForm.CreatePaymentFormForBalanceDue(ti, amtdue, email);

            SetHeaders(pf.OrgId ?? 0);

            DbUtil.LogActivity("OnlineReg PayDueStart", ti.OrgId, ti.LoginPeopleId ?? ti.FirstTransactionPeopleId());
            return(View("Payment/Process", pf));
        }
Beispiel #4
0
        public ActionResult PayAmtDue(string q)
        {
            // reached by the paylink in the confirmation email
            // which is produced in EnrollAndConfirm
            Response.NoCache();

            if (!Util.HasValue(q))
            {
                return(Message("unknown"));
            }

            var id = Util.Decrypt(q).ToInt2();
            var qq = from t in CurrentDatabase.Transactions
                     where t.OriginalId == id || t.Id == id
                     orderby t.Id descending
                     select new { t, email = t.TransactionPeople.FirstOrDefault().Person.EmailAddress };
            var i = qq.FirstOrDefault();

            if (i == null)
            {
                return(Message("no outstanding transaction"));
            }

            var ti     = i.t;
            var email  = i.email;
            var amtdue = PaymentForm.AmountDueTrans(CurrentDatabase, ti);

            if (amtdue == 0)
            {
                return(Message("no outstanding transaction"));
            }

            int?GatewayId = MultipleGatewayUtils.GatewayId(CurrentDatabase, PaymentProcessTypes.OnlineRegistration);

            if ((int)GatewayTypes.Pushpay == GatewayId)
            {
                ViewBag.Header = "Payment Process";
                if (string.IsNullOrEmpty(MultipleGatewayUtils.Setting(CurrentDatabase, "PushpayMerchant", "", (int)PaymentProcessTypes.OnlineRegistration)))
                {
                    return(View("OnePageGiving/NotConfigured"));
                }

                Session["PaymentProcessType"] = PaymentProcessTypes.OnlineRegistration;
                return(Redirect($"/Pushpay/PayAmtDue/{ti.Id}/{amtdue}"));
            }
#if DEBUG
            ti.Testing = true;
            if (!Util.HasValue(ti.Address))
            {
                ti.Address = "235 Riveredge";
                ti.City    = "Cordova";
                ti.Zip     = "38018";
                ti.State   = "TN";
            }
#endif
            var pf = PaymentForm.CreatePaymentFormForBalanceDue(CurrentDatabase, ti, amtdue, email);
            pf.ProcessType = PaymentProcessTypes.OnlineRegistration;

            SetHeaders(pf.OrgId ?? 0);

            DbUtil.LogActivity("OnlineReg PayDueStart", ti.OrgId, ti.LoginPeopleId ?? ti.FirstTransactionPeopleId());
            return(View("Payment/Process", pf));
        }
Beispiel #5
0
        private static void ConfirmDuePaidTransaction(Transaction ti, string transactionId, bool sendmail)
        {
            var Db  = DbUtil.Db;
            var org = Db.LoadOrganizationById(ti.OrgId);

            ti.TransactionId = transactionId;
            if (ti.Testing == true && !ti.TransactionId.Contains("(testing)"))
            {
                ti.TransactionId += "(testing)";
            }

            var amt = ti.Amt;

            foreach (var pi in ti.OriginalTrans.TransactionPeople)
            {
                var p = Db.LoadPersonById(pi.PeopleId);
                if (p != null)
                {
                    var om = Db.OrganizationMembers.SingleOrDefault(m => m.OrganizationId == ti.OrgId && m.PeopleId == pi.PeopleId);
                    if (om == null)
                    {
                        continue;
                    }
                    Db.SubmitChanges();
                    if (org.IsMissionTrip == true)
                    {
                        Db.GoerSenderAmounts.InsertOnSubmit(
                            new GoerSenderAmount
                        {
                            Amount      = ti.Amt,
                            GoerId      = pi.PeopleId,
                            Created     = DateTime.Now,
                            OrgId       = org.OrganizationId,
                            SupporterId = pi.PeopleId,
                        });
                        var setting = new Settings(org.RegSetting, Db, org.OrganizationId);
                        var fund    = setting.DonationFundId;
                        p.PostUnattendedContribution(Db, ti.Amt ?? 0, fund,
                                                     "SupportMissionTrip: org={0}; goer={1}".Fmt(org.OrganizationId, pi.PeopleId), typecode: BundleTypeCode.Online);
                    }
                    var pay = amt;
                    if (org.IsMissionTrip != true)
                    {
                        ti.Amtdue = PaymentForm.AmountDueTrans(Db, ti);
                    }

                    var sb = new StringBuilder();
                    sb.AppendFormat("{0:g} ----------\n", Util.Now);
                    sb.AppendFormat("{0:c} ({1} id) transaction amount\n", ti.Amt, ti.Id);
                    sb.AppendFormat("{0:c} applied to this registrant\n", pay);
                    sb.AppendFormat("{0:c} total due all registrants\n", ti.Amtdue);

                    om.AddToMemberData(sb.ToString());
                    var reg = p.RecRegs.Single();
                    reg.AddToComments(sb.ToString());
                    reg.AddToComments("{0} ({1})".Fmt(org.OrganizationName, org.OrganizationId));

                    amt -= pay;
                }
                else
                {
                    Db.Email(Db.StaffEmailForOrg(org.OrganizationId),
                             Db.PeopleFromPidString(org.NotifyIds),
                             "missing person on payment due",
                             "Cannot find {0} ({1}), payment due completed of {2:c} but no record".Fmt(pi.Person.Name, pi.PeopleId, pi.Amt));
                }
            }
            Db.SubmitChanges();
            var names = string.Join(", ", ti.OriginalTrans.TransactionPeople.Select(i => i.Person.Name).ToArray());

            var pid = ti.FirstTransactionPeopleId();
            var p0  = Db.LoadPersonById(pid);

//todo: should we be sending to all TransactionPeople?
            if (sendmail)
            {
                if (p0 == null)
                {
                    Util.SendMsg(Util.SysFromEmail, Util.Host, Util.TryGetMailAddress(Db.StaffEmailForOrg(org.OrganizationId)),
                                 "Payment confirmation", "Thank you for paying {0:c} for {1}.<br/>Your balance is {2:c}<br/>{3}".Fmt(
                                     ti.Amt, ti.Description, ti.Amtdue, names),
                                 Util.ToMailAddressList(Util.FirstAddress(ti.Emails)), 0, pid);
                }
                else
                {
                    Db.Email(Db.StaffEmailForOrg(org.OrganizationId), p0, Util.ToMailAddressList(ti.Emails),
                             "Payment confirmation", "Thank you for paying {0:c} for {1}.<br/>Your balance is {2:c}<br/>{3}".Fmt(
                                 ti.Amt, ti.Description, ti.Amtdue, names), false);
                    Db.Email(p0.FromEmail,
                             Db.PeopleFromPidString(org.NotifyIds),
                             "payment received for " + ti.Description,
                             "{0} paid {1:c} for {2}, balance of {3:c}\n({4})".Fmt(
                                 Transaction.FullName(ti), ti.Amt, ti.Description, ti.Amtdue, names));
                }
            }
        }
Beispiel #6
0
        public ActionResult PayAmtDue(string q)
        {
            Response.NoCache();

            if (!q.HasValue())
            {
                return(Message("unknown"));
            }
            var id = Util.Decrypt(q).ToInt2();
            var qq = from t in DbUtil.Db.Transactions
                     where t.OriginalId == id || t.Id == id
                     orderby t.Id descending
                     select new { t, email = t.TransactionPeople.FirstOrDefault().Person.EmailAddress };
            var i = qq.FirstOrDefault();

            if (i == null)
            {
                return(Message("no outstanding transaction"));
            }

            var ti     = i.t;
            var email  = i.email;
            var amtdue = PaymentForm.AmountDueTrans(DbUtil.Db, ti);

            if (amtdue == 0)
            {
                return(Message("no outstanding transaction"));
            }

#if DEBUG
            ti.Testing = true;
            if (!ti.Address.HasValue())
            {
                ti.Address = "235 Riveredge";
                ti.City    = "Cordova";
                ti.Zip     = "38018";
                ti.State   = "TN";
            }
#endif
            var pf = PaymentForm.CreatePaymentFormForBalanceDue(ti, amtdue, email);

            SetHeaders(pf.OrgId ?? 0);

            if (OnlineRegModel.GetTransactionGateway() != "serviceu")
            {
                return(View("Payment/Process", pf));
            }


            ViewBag.TranId = ti.Id;
            var pm = new PaymentModel
            {
                NameOnAccount = pf.FullName(),
                Address       = pf.Address,
                Amount        = pf.Amtdue,
                City          = pf.City,
                Email         = pf.Email,
                Phone         = pf.Phone.FmtFone(),
                State         = pf.State,
                PostalCode    = pf.Zip,
                testing       = pf.testing,
                PostbackURL   = DbUtil.Db.ServerLink("/OnlineReg/ConfirmServiceU/" + id),
                Misc2         = pf.Description,
                Misc1         = pf.FullName(),
                _URL          = pf.URL,
                _timeout      = new PaymentForm().TimeOut,
            };

            return(View("PayAmtDue/ServiceU", pm));
        }
Beispiel #7
0
        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.RegistrationDatas.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);
                    var z = DbUtil.Db.ZipCodes.SingleOrDefault(zc => zc.Zip == pf.Zip.Zip5());
                    if (z != null && !z.State.HasValue())
                    {
                        pf.State = r.State = z.State;
                        pf.City  = r.City = z.City;
                    }
                    if (r.Line1 != "error" && r.Line1.HasValue())
                    {
                        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);

                ViewBag.amtdue = PaymentForm.AmountDueTrans(DbUtil.Db, ti).ToString("C");
                return(View("PayAmtDue/Confirm", ti));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("form", ex.Message);
                return(View("Payment/Process", pf));
            }
        }
Beispiel #8
0
        public ActionResult ProcessPayment(PaymentForm pf)
        {
            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 = DbUtil.Db.RegistrationDatas.SingleOrDefault(e => e.Id == pf.DatumId);
            if (ed != null)
            {
                m = Util.DeSerialize <OnlineRegModel>(ed.Data);
            }

            var peopleId = 0;
            if (m != null)
            {
                peopleId = m.UserPeopleId ?? 0;
            }

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

            if (m != null && m.OnlineGiving())
            {
                var previousTransaction =
                    (from t in DbUtil.Db.Transactions
                     where t.Amt == pf.AmtToPay
                     where t.OrgId == m.Orgid
                     where t.TransactionDate > DateTime.Now.AddMinutes(-60)
                     where DbUtil.Db.Contributions.Any(cc => cc.PeopleId == m.List[0].PeopleId && cc.TranId == t.Id)
                     select t).FirstOrDefault();
                if (previousTransaction != null)
                {
                    return(Message("You have already submitted a gift in this amount a short while ago. Please let us know if you saw an error and what the message said."));
                }
            }

            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
            {
                ValidatePaymentForm(pf);

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

                if (m != null && pf.IsLoggedIn.GetValueOrDefault() && pf.SavePayInfo)
                {
                    var gateway = DbUtil.Db.Gateway(m.testing ?? false);
                    // we need to perform a $1 auth if this is a brand new credit card that we are going to store it in the vault.
                    // otherwise we skip doing an auth just call store in vault just like normal.
                    if (!VerifyCardWithAuth(gateway, pf, peopleId))
                    {
                        return(View("Payment/Process", pf));
                    }

                    InitializePaymentInfo(peopleId, pf);
                    StoreInVault(gateway, pf, peopleId);
                }

                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.HistoryAdd("ProcessPayment");
                    ed.Data      = Util.Serialize(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)
                    {
                        Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                        TempData["error"] = ex.Message;
                        return(Redirect("/Error"));
                    }
                }

                ConfirmDuePaidTransaction(ti, ti.TransactionId, sendmail: true);

                ViewBag.amtdue = PaymentForm.AmountDueTrans(DbUtil.Db, ti).ToString("C");
                return(View("PayAmtDue/Confirm", ti));
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                ModelState.AddModelError("form", ex.Message);
                return(View("Payment/Process", pf));
            }
        }