Ejemplo n.º 1
0
        public static void ResolvePrevDaysVirtualCheckRejects(CMSDataContext db, DateTime dt)
        {
            var gateway = db.Setting("TransactionGateway", "");

            if (gateway != "sage")
            {
                return;
            }
            var sage  = new SagePayments(db, false);
            var ds    = sage.VirtualCheckRejects(dt);
            var items = from r in ds.Tables[0].AsEnumerable()
                        let rejectdt = r["reject_date"].ToDate() ?? DateTime.MinValue
                                       where rejectdt > DateTime.MinValue
                                       select new
            {
                rejectdt,
                trantype   = r["trantype"],
                amt        = r["rejedt_amount"].ToString().ToDecimal(),
                tranid     = r["customer_number"].ToInt(),
                rejectcode = r["reject_code"].ToString(),
                message    = r["correction_info"].ToString(),
            };

            /*
             * Create a new transaction to reverse the original
             * If the transaction was for online giving or recurring giving, then reverse the contribution.
             * If the transaction contained an extra donation, then reverse that contribution.
             * Send an email to the payor.
             * Send an email notification to the online notify list for the associated organization
             */
        }
Ejemplo n.º 2
0
 public ActionResult DeleteVaultData(int id)
 {
     var sage = new SagePayments(DbUtil.Db, testing: true);
     sage.deleteVaultData(id);
     var p = DbUtil.Db.LoadPersonById(id);
     DbUtil.Db.RecurringAmounts.DeleteAllOnSubmit(p.RecurringAmounts);
     var mg = p.ManagedGiving();
     if (mg != null)
         DbUtil.Db.ManagedGivings.DeleteOnSubmit(mg);
     var pi = p.PaymentInfo();
     if (pi != null)
         DbUtil.Db.PaymentInfos.DeleteOnSubmit(pi);
     DbUtil.Db.SubmitChanges();
     return Content("ok");
 }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        private Transaction ProcessPaymentTransaction(OnlineRegModel m, PaymentForm pf)
        {
            Transaction ti = null;
            if (m != null && m.Transaction != null)
                ti = PaymentForm.CreateTransaction(DbUtil.Db, m.Transaction, pf.AmtToPay);
            else
                ti = pf.CreateTransaction(DbUtil.Db);

            int? pid = null;
            if (m != null)
            {
                m.ParseSettings();
                var terms = Util.PickFirst(m.Terms, "");
                if (terms.HasValue())
                    ViewData["Terms"] = terms;
                pid = m.UserPeopleId;
                if (m.TranId == null)
                    m.TranId = ti.Id;
            }

            if (!pid.HasValue)
            {
                var pds = DbUtil.Db.FindPerson(pf.First, pf.Last, null, pf.Email, pf.Phone);
                if (pds.Count() == 1)
                    pid = pds.Single().PeopleId.Value;
            }
            TransactionResponse tinfo;
            var gateway = OnlineRegModel.GetTransactionGateway();
            if (gateway == "authorizenet")
                if (pf.SavePayInfo == true)
                {
                    var anet = new AuthorizeNet(DbUtil.Db, pf.testing);
                    tinfo = anet.createCustomerProfileTransactionRequest(
                        pid ?? 0,
                        pf.AmtToPay ?? 0,
                        pf.Description,
                        pf.TranId ?? 0);
                }
                else
                    if (pf.Type == "B")
                        tinfo = OnlineRegModel.PostECheck(
                            pf.Routing, pf.Account,
                            pf.AmtToPay ?? 0,
                            ti.Id, pf.Description,
                            pid ?? 0, pf.First, pf.Last,
                            pf.Address, pf.City, pf.State, pf.Zip,
                            pf.testing);
                    else
                        tinfo = OnlineRegModel.PostTransaction(
                            pf.CreditCard, pf.CCV,
                            Payments.NormalizeExpires(pf.Expires),
                            pf.AmtToPay ?? 0,
                            ti.Id, pf.Description,
                            pid ?? 0, pf.Email, pf.First, pf.Last,
                            pf.Address, pf.City, pf.State, pf.Zip,
                            pf.testing);
            else if (gateway == "sage")
                if (pf.SavePayInfo == true)
                {
                    var sage = new SagePayments(DbUtil.Db, pf.testing);
                    tinfo = sage.createVaultTransactionRequest(
                        pid ?? 0,
                        pf.AmtToPay ?? 0,
                        pf.Description,
                        ti.Id,
                        pf.Type);
                }
                else
                    if (pf.Type == "B")
                        tinfo = OnlineRegModel.PostVirtualCheckTransactionSage(
                            pf.Routing, pf.Account,
                            pf.AmtToPay ?? 0,
                            ti.Id, pf.Description,
                            pid ?? 0, pf.Email, pf.First, pf.MiddleInitial, pf.Last, pf.Suffix,
                            pf.Address, pf.City, pf.State, pf.Zip, pf.Phone,
                            pf.testing);
                    else
                        tinfo = OnlineRegModel.PostTransactionSage(
                            pf.CreditCard, pf.CCV,
                            Payments.NormalizeExpires(pf.Expires),
                            pf.AmtToPay ?? 0,
                            ti.Id, pf.Description,
                            pid ?? 0, pf.Email, pf.First, pf.MiddleInitial, pf.Last, pf.Suffix,
                            pf.Address, pf.City, pf.State, pf.Zip, pf.Phone,
                            pf.testing);

            else
                throw new Exception("unknown gateway " + gateway);

            ti.TransactionId = tinfo.TransactionId;
            if (ti.Testing == true && !ti.TransactionId.Contains("(testing)"))
                ti.TransactionId += "(testing)";
            ti.Approved = tinfo.Approved;
            if (ti.Approved == false)
            {
                ti.Amtdue += ti.Amt;
                if (m != null && m.OnlineGiving())
                    ti.Amtdue = 0;
            }
            ti.Message = tinfo.Message;
            ti.AuthCode = tinfo.AuthCode;
            ti.TransactionDate = DateTime.Now;
            DbUtil.Db.SubmitChanges();
            return ti;
        }
Ejemplo n.º 5
0
 public ActionResult CreditVoid(int id, string type, decimal? amt, TransactionsModel m)
 {
     var t = DbUtil.Db.Transactions.SingleOrDefault(tt => tt.Id == id);
     if (t == null)
         return Content("notran");
     var qq = from tt in DbUtil.Db.Transactions
              where tt.OriginalId == id || tt.Id == id
              orderby tt.Id descending
              select tt;
     var t0 = qq.First();
     var sage = new SagePayments(DbUtil.Db, t.Testing ?? false);
     TransactionResponse resp = null;
     var re = t.TransactionId;
     if (re.Contains("(testing"))
         re = re.Substring(0, re.IndexOf("(testing)"));
     if (type == "Void")
     {
         resp = sage.voidTransactionRequest(re);
         if (!resp.Approved)
             resp = sage.voidCheckRequest(re);
         if (resp.Approved)
             t.Voided = true;
         amt = t.Amt;
     }
     else
     {
         if (t.Batchtyp == "eft")
             resp = sage.creditCheckTransactionRequest(re, amt ?? 0);
         else if (t.Batchtyp == "bankcard")
             resp = sage.creditTransactionRequest(re, amt ?? 0);
         if (resp.Approved)
             t.Credited = true;
     }
     if(!resp.Approved)
     {
         return Content("error: " + resp.Message);
     }
     else // approved
     {
         var tt = new Transaction
         {
             TransactionId = resp.TransactionId + (t.Testing == true ? "(testing)" : ""),
             First = t.First,
             MiddleInitial = t.MiddleInitial,
             Last = t.Last,
             Suffix = t.Suffix,
             Amt = -amt,
             Amtdue = t0.Amtdue + amt,
             Approved = true,
             AuthCode = t.AuthCode,
             Message = t.Message,
             Donate = -t.Donate,
             Regfees = -t.Regfees,
             TransactionDate = DateTime.Now,
             TransactionGateway = t.TransactionGateway,
             Testing = t.Testing,
             Description = t.Description,
             OrgId = t.OrgId,
             OriginalId = t.OriginalId,
             Participants = t.Participants,
             Financeonly = t.Financeonly,
         };
         DbUtil.Db.Transactions.InsertOnSubmit(tt);
         DbUtil.Db.SubmitChanges();
         Util.SendMsg(Util.SysFromEmail, Util.Host,
             Util.TryGetMailAddress(DbUtil.Db.StaffEmailForOrg(tt.OrgId ?? 0)),
             "Void/Credit Transaction Type: " + type,
     @"<table>
     <tr><td>Name</td><td>{0}</td></tr>
     <tr><td>Email</td><td>{1}</td></tr>
     <tr><td>Address</td><td>{2}</td></tr>
     <tr><td>Phone</td><td>{3}</td></tr>
     <tr><th colspan=""2"">Transaction Info</th></tr>
     <tr><td>Description</td><td>{4}</td></tr>
     <tr><td>Amount</td><td>{5:N2}</td></tr>
     <tr><td>Date</td><td>{6}</td></tr>
     <tr><td>TranIds</td><td>Org: {7} {8}, Curr: {9} {10}</td></tr>
     <tr><td>User</td><td>{11}</td></tr>
     </table>".Fmt(Transaction.FullName(t), t.Emails, t.Address, t.Phone,
      t.Description,
      -amt,
      t.TransactionDate.Value.FormatDateTm(),
      t.Id, t.TransactionId, tt.Id, tt.TransactionId, Util.UserFullName
      ), Util.EmailAddressListFromString(DbUtil.Db.StaffEmailForOrg(tt.OrgId ?? 0)),
             0, 0);
     }
     DbUtil.LogActivity("CreditVoid for " + t.TransactionId);
     return View("List", m);
 }
Ejemplo n.º 6
0
        private void CheckBatchDates(DateTime start, DateTime end)
        {
            if (OnlineRegModel.GetTransactionGateway() != "sage")
                return;
            var sage = new SagePayments(DbUtil.Db, false);
            var bds = sage.SettledBatchSummary(start, end, true, true);
            var batches = from batch in bds.Tables[0].AsEnumerable()
                          select new
                          {
                              date = batch["date"].ToDate().Value.AddHours(4),
                              reference = batch["reference"].ToString(),
                              type = batch["type"].ToString()
                          };
            foreach (var batch in batches)
            {
                if (DbUtil.Db.CheckedBatches.Any(tt => tt.BatchRef == batch.reference))
                    continue;

                var ds = sage.SettledBatchListing(batch.reference, batch.type);

                var items = from r in ds.Tables[0].AsEnumerable()
                            select new
                            {
                                settled = r["settle_date"].ToDate().Value.AddHours(4),
                                tranid = r["order_number"],
                                reference = r["reference"].ToString(),
                                approved = r["approved"].ToString().ToBool(),
                                name = r["name"].ToString(),
                                message = r["message"].ToString(),
                                amount = r["total_amount"].ToString(),
                                date = r["date"].ToDate(),
                                type = r["transaction_code"].ToInt()
                            };
                var settlelist = items.ToDictionary(ii => ii.reference, ii => ii);

                var q = from t in DbUtil.Db.Transactions
                        where settlelist.Keys.Contains(t.TransactionId)
                        where t.Approved == true
                        select t;
                var tlist = q.ToDictionary(ii => ii.TransactionId, ii => ii); // transactions that are found in setteled list;
                var q2 = from st in settlelist
                         where !tlist.Keys.Contains(st.Key)
                         select st.Value;
                var notbefore = DateTime.Parse("6/1/12");
                foreach (var st in q2)
                {
                    var t = DbUtil.Db.Transactions.SingleOrDefault(j => j.TransactionId == st.reference && st.date >= notbefore);
                    string first, last;
                    Util.NameSplit(st.name, out first, out last);
                    var tt = new Transaction
                    {
                        Name = st.name,
                        First = first,
                        Last = last,
                        TransactionId = st.reference,
                        Amt = st.amount.ToDecimal(),
                        Approved = st.approved,
                        Message = st.message,
                        TransactionDate = st.date,
                        TransactionGateway = "sage",
                        Settled = st.settled,
                        Batch = batch.date,
                        Batchref = batch.reference,
                        Batchtyp = batch.type,
                        OriginalId = t != null ? (t.OriginalId ?? t.Id) : (int?)null,
                        Fromsage = true,
                        Description = t != null ? t.Description : "no description from sage, id=" + st.tranid,
                    };
                    if (st.type == 6) // credit transaction
                        tt.Amt = -tt.Amt;
                    DbUtil.Db.Transactions.InsertOnSubmit(tt);
                }

                foreach (var t in q)
                {
                    if (!settlelist.ContainsKey(t.TransactionId))
                        continue;
                    t.Batch = batch.date;
                    t.Batchref = batch.reference;
                    t.Batchtyp = batch.type;
                    t.Settled = settlelist[t.TransactionId].settled;
                }
                var cb = DbUtil.Db.CheckedBatches.SingleOrDefault(bb => bb.BatchRef == batch.reference);
                if (cb == null)
                {
                    DbUtil.Db.CheckedBatches.InsertOnSubmit(
                        new CheckedBatch()
                        {
                            BatchRef = batch.reference,
                            CheckedX = DateTime.Now
                        });
                }
                else
                    cb.CheckedX = DateTime.Now;
                DbUtil.Db.SubmitChanges();
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
        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");
        }
Ejemplo n.º 9
0
 public static TransactionResponse PostVirtualCheckTransactionSage(
     string routing, string acct,
     decimal amt, int tranid, string description,
     int PeopleId, string email, string first, string middle, string last, string suffix,
     string addr, string city, string state, string zip, string phone,
     bool testing)
 {
     var t = new SagePayments(DbUtil.Db, testing);
     var resp = t.createCheckTransactionRequest(PeopleId, amt, routing, acct, description, tranid,
         email, first, middle, last, suffix, addr, city, state, zip, phone);
     return resp;
 }
Ejemplo n.º 10
0
 public static TransactionResponse PostTransactionSage(
     string card, string ccv, string expdate,
     decimal amt, int tranid, string description,
     int PeopleId, string email, string first, string middle, string last, string suffix,
     string addr, string city, string state, string zip, string phone,
     bool testing)
 {
     var t = new SagePayments(DbUtil.Db, testing);
     var resp = t.createTransactionRequest(PeopleId, amt, card, expdate, description, tranid, ccv,
         email, first, last, addr, city, state, zip, phone);
     return resp;
 }
Ejemplo n.º 11
0
        public int DoGiving(CMSDataContext Db)
        {
            var          gateway = Db.Setting("TransactionGateway", "");
            AuthorizeNet anet    = null;
            SagePayments sage    = null;

            if (gateway == "AuthorizeNet")
            {
                anet = new AuthorizeNet(Db, testing: false);
            }
            else if (gateway == "Sage")
            {
                sage = new SagePayments(Db, testing: false);
            }
            else
            {
                return(0);
            }

            TransactionResponse ret = null;
            var total = (from a in Db.RecurringAmounts
                         where a.PeopleId == PeopleId
                         where a.ContributionFund.FundStatusId == 1
                         select a.Amt).Sum();

            if (!total.HasValue || total == 0)
            {
                return(0);
            }

            var preferredtype = (from pi in Db.PaymentInfos
                                 where pi.PeopleId == PeopleId
                                 select pi.PreferredGivingType).Single();

            var t = new Transaction
            {
                TransactionDate    = DateTime.Now,
                TransactionId      = "started",
                First              = Person.FirstName,
                MiddleInitial      = Person.MiddleName.Truncate(1) ?? "",
                Last               = Person.LastName,
                Suffix             = Person.SuffixCode,
                Amt                = total,
                Description        = "Recurring Giving",
                Testing            = false,
                TransactionGateway = gateway,
                Financeonly        = true
            };

            Db.Transactions.InsertOnSubmit(t);
            Db.SubmitChanges();

            if (gateway == "AuthorizeNet")
            {
                ret = anet.createCustomerProfileTransactionRequest(PeopleId, total ?? 0, "Recurring Giving", t.Id);
            }
            else
            {
                ret = sage.createVaultTransactionRequest(PeopleId, total ?? 0, "Recurring Giving", t.Id, preferredtype);
            }
            t.TransactionPeople.Add(new TransactionPerson {
                PeopleId = PeopleId, Amt = total
            });

            t.Message       = ret.Message;
            t.AuthCode      = ret.AuthCode;
            t.Approved      = ret.Approved;
            t.TransactionId = ret.TransactionId;
            var systemEmail = Db.Setting("SystemEmailAddress", "*****@*****.**");

            var contributionemail = (from ex in Person.PeopleExtras
                                     where ex.Field == "ContributionEmail"
                                     select ex.Data).SingleOrDefault();

            if (contributionemail.HasValue())
            {
                contributionemail = contributionemail.Trim();
            }
            if (!Util.ValidEmail(contributionemail))
            {
                contributionemail = Person.FromEmail;
            }
            var gift   = Db.Setting("NameForPayment", "gift");
            var church = Db.Setting("NameOfChurch", Db.CmsHost);

            if (ret.Approved)
            {
                var q = from a in Db.RecurringAmounts
                        where a.PeopleId == PeopleId
                        select a;

                foreach (var a in q)
                {
                    if (a.ContributionFund.FundStatusId == 1 && a.Amt > 0)
                    {
                        Person.PostUnattendedContribution(Db,
                                                          a.Amt ?? 0,
                                                          a.FundId,
                                                          "Recurring Giving", pledge: false);
                    }
                }
                var tot = q.Where(aa => aa.ContributionFund.FundStatusId == 1).Sum(aa => aa.Amt);
                NextDate = FindNextDate(DateTime.Today.AddDays(1));
                Db.SubmitChanges();
                if (tot > 0)
                {
                    Util.SendMsg(systemEmail, Db.CmsHost, Util.TryGetMailAddress(contributionemail),
                                 "Recurring {0} for {1}".Fmt(gift, church),
                                 "Your payment of ${0:N2} was processed this morning.".Fmt(tot),
                                 Util.ToMailAddressList(contributionemail), 0, null);
                }
            }
            else
            {
                Db.SubmitChanges();
                var failedGivingMessage = Db.ContentHtml("FailedGivingMessage", Resources.ManagedGiving_FailedGivingMessage);
                var adminEmail          = Db.Setting("AdminMail", systemEmail);
                Util.SendMsg(systemEmail, Db.CmsHost, Util.TryGetMailAddress(contributionemail),
                             "Recurring {0} failed for {1}".Fmt(gift, church),
                             failedGivingMessage.Replace("{first}", Person.PreferredName),
                             Util.ToMailAddressList(contributionemail), 0, null);
                foreach (var p in Db.FinancePeople())
                {
                    Util.SendMsg(systemEmail, Db.CmsHost, Util.TryGetMailAddress(adminEmail),
                                 "Recurring Giving Failed on " + Db.CmsHost,
                                 "<a href='{0}Manage/Transactions/Index/{2}'>message: {1}, tranid:{2}</a>".Fmt(Db.CmsHost, ret.Message, t.Id),
                                 Util.ToMailAddressList(p.EmailAddress), 0, null);
                }
            }
            return(1);
        }
Ejemplo n.º 12
0
        public int DoGiving(CMSDataContext Db)
        {
            var gateway = Db.Setting("TransactionGateway", "");
            AuthorizeNet anet = null;
            SagePayments sage = null;
            if (gateway == "AuthorizeNet")
                anet = new AuthorizeNet(Db, testing: false);
            else if (gateway == "Sage")
                sage = new SagePayments(Db, testing: false);
            else
                return 0;

            TransactionResponse ret = null;
            var total = (from a in Db.RecurringAmounts
                         where a.PeopleId == PeopleId
                         where a.ContributionFund.FundStatusId == 1
                         select a.Amt).Sum();

            if (!total.HasValue || total == 0)
                return 0;

            var preferredtype = (from pi in Db.PaymentInfos
                                 where pi.PeopleId == PeopleId
                                 select pi.PreferredGivingType).Single();

            var t = new Transaction
            {
                TransactionDate = DateTime.Now,
                TransactionId = "started",
                First = Person.FirstName,
                MiddleInitial = Person.MiddleName.Truncate(1) ?? "",
                Last = Person.LastName,
                Suffix = Person.SuffixCode,
                Amt = total,
                Description = "Recurring Giving",
                Testing = false,
                TransactionGateway = gateway,
                Financeonly = true
            };
            Db.Transactions.InsertOnSubmit(t);
            Db.SubmitChanges();

            if (gateway == "AuthorizeNet")
                ret = anet.createCustomerProfileTransactionRequest(PeopleId, total ?? 0, "Recurring Giving", t.Id);
            else
                ret = sage.createVaultTransactionRequest(PeopleId, total ?? 0, "Recurring Giving", t.Id, preferredtype);
            t.TransactionPeople.Add(new TransactionPerson { PeopleId = PeopleId, Amt = total });

            t.Message = ret.Message;
            t.AuthCode = ret.AuthCode;
            t.Approved = ret.Approved;
            t.TransactionId = ret.TransactionId;
            var systemEmail = Db.Setting("SystemEmailAddress", "*****@*****.**");

            var contributionemail = (from ex in Person.PeopleExtras
                                     where ex.Field == "ContributionEmail"
                                     select ex.Data).SingleOrDefault();
            if (contributionemail.HasValue())
                contributionemail = contributionemail.Trim();
            if (!Util.ValidEmail(contributionemail))
                contributionemail = Person.FromEmail;
            var gift = Db.Setting("NameForPayment", "gift");
            var church = Db.Setting("NameOfChurch", Db.CmsHost);
            if (ret.Approved)
            {
                var q = from a in Db.RecurringAmounts
                        where a.PeopleId == PeopleId
                        select a;

                foreach (var a in q)
                {
                    if (a.ContributionFund.FundStatusId == 1 && a.Amt > 0)
                        Person.PostUnattendedContribution(Db,
                            a.Amt ?? 0,
                            a.FundId,
                            "Recurring Giving", pledge: false);
                }
                var tot = q.Where(aa => aa.ContributionFund.FundStatusId == 1).Sum(aa => aa.Amt);
                NextDate = FindNextDate(DateTime.Today.AddDays(1));
                Db.SubmitChanges();
                if (tot > 0)
                {
                    Util.SendMsg(systemEmail, Db.CmsHost, Util.TryGetMailAddress(contributionemail),
                                 "Recurring {0} for {1}".Fmt(gift, church),
                                 "Your payment of ${0:N2} was processed this morning.".Fmt(tot),
                                 Util.ToMailAddressList(contributionemail), 0, null);
                }
            }
            else
            {
                Db.SubmitChanges();
                var failedGivingMessage = Db.ContentHtml("FailedGivingMessage", Resources.ManagedGiving_FailedGivingMessage);
                var adminEmail = Db.Setting("AdminMail", systemEmail);
                Util.SendMsg(systemEmail, Db.CmsHost, Util.TryGetMailAddress(contributionemail),
                        "Recurring {0} failed for {1}".Fmt(gift, church),
                        failedGivingMessage.Replace("{first}", Person.PreferredName),
                        Util.ToMailAddressList(contributionemail), 0, null);
                foreach (var p in Db.FinancePeople())
                    Util.SendMsg(systemEmail, Db.CmsHost, Util.TryGetMailAddress(adminEmail),
                        "Recurring Giving Failed on " + Db.CmsHost,
                        "<a href='{0}Transactions/{2}'>message: {1}, tranid:{2}</a>".Fmt(Db.CmsHost, ret.Message, t.Id),
                        Util.ToMailAddressList(p.EmailAddress), 0, null);
            }
            return 1;
        }
Ejemplo n.º 13
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));
            }
        }
Ejemplo n.º 14
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();
        }
Ejemplo n.º 15
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 (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,
                                                        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,
                                          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;
                    ed.Data  = Util.Serialize <OnlineRegModel>(m);
                    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));
            }
        }