Beispiel #1
0
//        public static TransactionResponse PostTransactionTnb(
//            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 tnb = new TNBTransactionSaleCC()
//            {
//                CCNumber = "",
//            };
//            return TNBHelper.Transaction(tnb).getTransactionRespose();
////            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;
//        }
        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);
        }
Beispiel #2
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);
        }
Beispiel #3
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"));
        }
        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)
                {
                    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)" : ""),
                    Name               = t.Name,
                    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(t.FullName, 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));
        }
Beispiel #5
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();
            }
        }
Beispiel #6
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();
        }
Beispiel #7
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)
                {
                    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,
                        DbUtil.NormalizeExpires(pf.Expires).ToString2("MMyy"),
                        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)
                {
                    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,
                        DbUtil.NormalizeExpires(pf.Expires).ToString2("MMyy"),
                        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);
        }
Beispiel #8
0
        public ActionResult processGiving(string data)
        {
            // Authenticate first
            var authError = Authenticate();

            if (authError != null)
            {
                return(authError);
            }

            // Check to see if type matches
            BaseMessage dataIn = BaseMessage.createFromString(data);

            if (dataIn.type != BaseMessage.API_TYPE_GIVING_GIVE)
            {
                return(BaseMessage.createTypeErrorReturn());
            }

            // Everything is in order, start the return
            MobilePostTransaction mpt = JsonConvert.DeserializeObject <MobilePostTransaction>(dataIn.data);

            if (mpt.amount == 0 || mpt.paymentType == 0 || mpt.peopleID == 0)
            {
                return(BaseMessage.createErrorReturn("Missing information!"));
            }

            Transaction ti = createTransaction(mpt);

            if (ti != null && ti.Id > 0)
            {
                SagePayments        sp = new SagePayments(DbUtil.Db, false);
                TransactionResponse tr = null;

                switch (mpt.paymentType)
                {
                case MobilePostTransaction.TYPE_BANK_ACCOUNT:
                    tr = sp.createVaultTransactionRequest(mpt.peopleID, mpt.amount, mpt.description, ti.Id, "B");
                    break;

                case MobilePostTransaction.TYPE_CREDIT_CARD:
                    tr = sp.createVaultTransactionRequest(mpt.peopleID, mpt.amount, mpt.description, ti.Id, "C");
                    break;
                }

                // Build return
                BaseMessage br = new BaseMessage();
                br.type = BaseMessage.API_TYPE_GIVING_GIVE;

                if (tr != null && tr.Approved)
                {
                    br.error = 0;
                    br.id    = mpt.transactionID = ti.Id;

                    sendConfirmation(mpt);
                }
                else
                {
                    DbUtil.Db.Transactions.DeleteOnSubmit(ti);
                    DbUtil.Db.SubmitChanges();

                    br.error = 1;
                    br.data  = tr.Message;
                }

                return(br);
            }
            else
            {
                return(BaseMessage.createErrorReturn("Transaction creation failed!"));
            }
        }
        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"));
        }