Ejemplo n.º 1
0
        private static void SummarizePayment(Transaction ti, OrganizationMember om, StringBuilder sb)
        {
            if ((ti.Amt ?? 0) == 0 || om == null)
                return;

            var ts = om.TransactionSummary(DbUtil.Db);
            if (ts != null)
                sb.AppendFormat(@"
            <tr><td colspan='2'>
            <table cellpadding=4>
            <tr>
            <td>Registrant Fee</td>
            <td>Amount Paid</td>
            <td>Amount Due</td>
            </tr>
            <tr>
            <td align='right'>{0}</td>
            <td align='right'>{1}</td>
            <td align='right'>{2}</td>
            </tr>
            </table>
            </td></tr>
            ", ts.IndAmt.ToString2("c"),
                    om.TotalPaid(DbUtil.Db).ToString("c"),
                    om.AmountDue(DbUtil.Db).ToString("c"));
        }
Ejemplo n.º 2
0
        public RouteModel FinishRegistration(Transaction ti)
        {
            TranId = ti.Id;
            HistoryAdd("ProcessPayment");
            var ed = DbUtil.Db.RegistrationDatas.Single(dd => dd.Id == DatumId);
            ed.Data = Util.Serialize(this);
            ed.Completed = true;
            DbUtil.Db.SubmitChanges();

            try
            {
                LogOutOfOnlineReg();
                var view = ConfirmTransaction(ti.TransactionId);
                switch (view)
                {
                    case ConfirmEnum.Confirm:
                        return RouteModel.ViewAction("Confirm", this);
                    case ConfirmEnum.ConfirmAccount:
                        return RouteModel.ViewAction("ConfirmAccount", this);
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return RouteModel.ErrorMessage(ex.Message);
            }
            return null;
        }
Ejemplo n.º 3
0
        public ActionResult Adjust(int id, decimal amt, string desc, TransactionsModel m)
        {
            var qq = from tt in DbUtil.Db.Transactions
                     where tt.OriginalId == id || tt.Id == id
                     orderby tt.Id descending
                     select tt;
            var t = qq.FirstOrDefault();

            if (t == null)
                return Content("notran");

            var t2 = new Transaction
                {
                    TransactionId = "Adjustment",
                    First = t.First,
                    MiddleInitial = t.MiddleInitial,
                    Last = t.Last,
                    Suffix = t.Suffix,
                    Amt = amt,
                    Emails = t.Emails,
                    Amtdue = t.Amtdue - amt,
                    Approved = true,
                    AuthCode = "",
                    Message = desc,
                    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(t2);
                DbUtil.Db.SubmitChanges();
                Util.SendMsg(Util.SysFromEmail, Util.Host,
                    Util.TryGetMailAddress(DbUtil.Db.StaffEmailForOrg(t2.OrgId ?? 0)),
                    "Adjustment Transaction",
            @"<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>
            </table>".Fmt(Transaction.FullName(t), t.Emails, t.Address, t.Phone,
             t.Description,
             t.Amt,
             t.TransactionDate.Value.FormatDateTm(),
             t.Id, t.TransactionId, t2.Id, t2.TransactionId
             ), Util.EmailAddressListFromString(DbUtil.Db.StaffEmailForOrg(t2.OrgId ?? 0)),
                    0, 0);
            DbUtil.LogActivity("Adjust for " + t.TransactionId);
            return View("List", m);
        }
Ejemplo n.º 4
0
        public string PrepareSummaryText(Transaction ti)
        {
            if (RecordFamilyAttendance())
                return SummarizeFamilyAttendance();

            var om = GetOrgMember();
            var si = new SummaryInfo(DbUtil.Db, om.PeopleId, om.OrganizationId);
            return si.ToString();
        }
Ejemplo n.º 5
0
        public RouteModel FinishRegistration(Transaction ti)
        {
            TranId = ti.Id;
            HistoryAdd("ProcessPayment");
            var ed = DbUtil.Db.RegistrationDatas.Single(dd => dd.Id == DatumId);
            ed.Data = Util.Serialize(this);
            ed.Completed = true;
            DbUtil.Db.SubmitChanges();

            return ConfirmTransaction(ti);
        }
Ejemplo n.º 6
0
        public string PrepareSummaryText(Transaction ti)
        {
            if (RecordFamilyAttendance())
                return SummarizeFamilyAttendance();

            var om = GetOrgMember();
            var sb = StartSummary();
            SummarizePayment(ti, om, sb);
            if(Parent.SupportMissionTrip)
                SummarizeSupportMissionTrip(sb);
            else
                SummarizeAnswers(sb, om);
            return FinishSummary(sb);
        }
Ejemplo n.º 7
0
        public string PrepareSummaryText(Transaction ti)
        {
            if (RecordFamilyAttendance())
                return SummarizeFamilyAttendance();

            var om = GetOrgMember();
            if (Util2.UseNewDetails)
            {
                var si = new SummaryInfo(DbUtil.Db, om.PeopleId, om.OrganizationId);
                return si.ToString();
            }
            var sb = StartSummary();
            SummarizePayment(ti, om, sb);
            if (Parent.SupportMissionTrip)
                SummarizeSupportMissionTrip(sb);
            else
                SummarizeAnswers(sb, om);
            return FinishSummary(sb);
        }
Ejemplo n.º 8
0
        public OrganizationMember Enroll(Transaction transaction, string payLink)
        {
            var om = GetOrganizationMember(transaction);

            if (Parent.SupportMissionTrip)
                return AddSender(om);

            if (RecordFamilyAttendance())
                return RecordAllFamilyAttends(om);

            om.Amount = TotalAmount();

            SaveAnswers(om);
            SaveAgeGroupChoice(om);
            DoLinkGroupsFromOrgs(om);
            LogRegistrationOnOrgMember(transaction, om, payLink);

            DbUtil.Db.SubmitChanges();
            return om;
        }
Ejemplo n.º 9
0
 public RouteModel ConfirmTransaction(Transaction ti)
 {
     try
     {
         LogOutOfOnlineReg();
         var view = ConfirmTransaction(ti.TransactionId);
         switch (view)
         {
             case ConfirmEnum.Confirm:
                 return RouteModel.ViewAction("Confirm", this);
             case ConfirmEnum.ConfirmAccount:
                 return RouteModel.ViewAction("ConfirmAccount", this);
         }
     }
     catch (Exception ex)
     {
         Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
         return RouteModel.ErrorMessage(ex.Message);
     }
     return null;
 }
Ejemplo n.º 10
0
        private void LogRegistrationOnOrgMember(Transaction transaction, OrganizationMember om, string paylink)
        {
            var reg = person.GetRecReg();
            var sb = new StringBuilder();

            sb.AppendFormat("{0:g} ----------------\n", DateTime.Now);
            if (om.AmountPaid > 0)
            {
                var others = GetOthersInTransaction(transaction);
                sb.AppendFormat("{0:c} ({1} id) transaction amount\n", transaction.Amt, transaction.Id);
                sb.AppendFormat("{0:c} applied to this registrant\n", AmountToPay());
                sb.AppendFormat("{0:c} total due all registrants\n", transaction.Amtdue);
                if (others.HasValue())
                    sb.AppendFormat("Others: {0}\n", others);
            }
            om.AddToMemberDataBelowComments(sb.ToString());

            var sbreg = new StringBuilder();
            sbreg.Append($"{org.OrganizationName}\n");
            sbreg.AppendFormat("{0:g} ----------------\n", DateTime.Now);
            if (om.AmountPaid > 0)
            {
                sbreg.AppendFormat("{0:c} ({1} id) transaction amount\n", transaction.Amt, transaction.Id);
                sbreg.AppendFormat("{0:c} applied to this registrant\n", AmountToPay());
                sbreg.AppendFormat("{0:c} total due all registrants\n", transaction.Amtdue);
            }
            if (paylink.HasValue())
            {
                sbreg.AppendLine(paylink);
                om.PayLink = paylink;
            }
            if (request.HasValue())
            {
                sbreg.AppendFormat("Request: {0}\n", request);
                om.Request = request.Truncate(140);
            }
            sbreg.AppendFormat("{0}\n", EmailAddress);

            reg.AddToComments(sbreg.ToString());
        }
Ejemplo n.º 11
0
        public int DoGiving(CMSDataContext db)
        {
            var total = (from a in db.RecurringAmounts
                         where a.PeopleId == PeopleId
                         where a.ContributionFund.FundStatusId == 1
                         where a.ContributionFund.OnlineSort != null
                         select a.Amt).Sum();

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

            var paymentInfo = db.PaymentInfos.Single(x => x.PeopleId == PeopleId);
            var preferredType = paymentInfo.PreferredGivingType;

            var gw = GetGateway(db, paymentInfo);

            var orgid = (from o in db.Organizations
                             where o.RegistrationTypeId == RegistrationTypeCode.ManageGiving
                             select o.OrganizationId).FirstOrDefault();

            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 = gw.GatewayType,
                Financeonly = true,
                PaymentType = preferredType,
                LastFourCC = preferredType == PaymentType.CreditCard ? paymentInfo.MaskedCard.Last(4) : null,
                LastFourACH = preferredType == PaymentType.Ach ? paymentInfo.MaskedAccount.Last(4) : null,
                OrgId = orgid,
            };

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

            var ret = gw.PayWithVault(PeopleId, total ?? 0, "Recurring Giving", t.Id, preferredType);

            t.Message = ret.Message;
            t.AuthCode = ret.AuthCode;
            t.Approved = ret.Approved;
            t.TransactionId = ret.TransactionId;

            var gift = db.Setting("NameForPayment", "gift");
            var church = db.Setting("NameOfChurch", db.CmsHost);
            var q = from a in db.RecurringAmounts
                    where a.PeopleId == PeopleId
                    select a;
            var tot = q.Where(aa => aa.ContributionFund.FundStatusId == 1).Sum(aa => aa.Amt);
            t.TransactionPeople.Add(new TransactionPerson
            {
                PeopleId = Person.PeopleId,
                Amt = tot,
            });
            var notify = db.RecurringGivingNotifyPersons();
            var from = Util.TryGetMailAddress(notify[0].EmailAddress);
            if (ret.Approved)
            {
                foreach (var a in q)
                {
                    if (a.ContributionFund.FundStatusId == 1 && a.ContributionFund.OnlineSort != null && a.Amt > 0)
                        Person.PostUnattendedContribution(db, a.Amt ?? 0, a.FundId, "Recurring Giving", tranid: t.Id);
                }

                NextDate = FindNextDate(Util.Now.Date.AddDays(1));
                db.SubmitChanges();
                if (tot > 0)
                {
                    var msg = db.Content("RecurringGiftNotice") ?? new Content
                              { Title = $"Recurring {gift} for {{church}}",
                                Body = "Your gift of {total} was processed this morning." };
                    var subject = msg.Title.Replace("{church}", church);
                    var body = msg.Body.Replace("{total}", $"${tot:N2}");
                    var m = new EmailReplacements(db, body, from);
                    body = m.DoReplacements(db, Person);
                    db.EmailFinanceInformation(from, Person, null, subject, body);
                }
            }
            else
            {
                db.SubmitChanges();
                var msg = db.Content("RecurringGiftFailedNotice") ?? new Content
                          { Title = $"Recurring {gift} for {{church}} did not succeed",
                            Body = @"Your payment of {total} failed to process this morning.<br>
            The message was '{message}'.
            Please contact the Finance office at the church." };
                var subject = msg.Title.Replace("{church}", church);
                var body = msg.Body.Replace("{total}", $"${tot:N2}")
                    .Replace("{message}", ret.Message);
                var m = new EmailReplacements(db, body, from);
                body = m.DoReplacements(db, Person);

                db.Email(from, Person, null, subject, body, false);
                foreach (var p in db.RecurringGivingNotifyPersons())
                    db.EmailFinanceInformation(from, p, null,
                        $"Recurring Giving Failed on {db.CmsHost}",
                        $"<a href='{db.CmsHost}/Transactions/{t.Id}'>message: {ret.Message}, tranid:{t.Id}</a>");
            }
            return 1;
        }
Ejemplo n.º 12
0
        public Transaction AddTransaction(CMSDataContext db, string reason, decimal payment, string description, decimal? amount = null, bool? adjustFee = false, string pmtDescription = null)
        {
            var ts = TransactionSummary(db);
            var ti = db.Transactions.SingleOrDefault(tt => tt.Id == TranId);
            if (ti == null)
            {
                ti = (from t in db.Transactions
                      where t.OriginalTransaction.TransactionPeople.Any(pp => pp.PeopleId == PeopleId)
                      where t.OriginalTransaction.OrgId == OrganizationId
                      orderby t.Id descending
                      select t).FirstOrDefault();
                if (ti != null)
                    TranId = ti.Id;
            }

            var ti2 = new Transaction
            {
                TransactionId = $"{reason} ({Util.UserPeopleId ?? Util.UserId1})",
                Description = Util.PickFirst(pmtDescription, Organization.OrganizationName),
                TransactionDate = DateTime.Now,
                OrgId = OrganizationId,
                Name = Person.Name,
                First = Person.PreferredName,
                Last = Person.LastName,
                MiddleInitial = Person.MiddleName.Truncate(1),
                Suffix = Person.SuffixCode,
                Address = Person.PrimaryAddress,
                City = Person.PrimaryCity,
                Emails = Person.EmailAddress,
                State = Person.PrimaryState,
                Zip = Person.PrimaryZip,
                LoginPeopleId = Util.UserPeopleId,
                Approved = true,
                Amt = payment,
                //Amtdue = (amount ?? payment) - payment,
                Amtdue = (amount ?? 0) - payment,
                AdjustFee = adjustFee,
                Message = description,
            };

            db.Transactions.InsertOnSubmit(ti2);
            db.SubmitChanges();
            if (ts == null)
            {
                TranId = ti2.Id;
                ti2.TransactionPeople.Add(new TransactionPerson { PeopleId = PeopleId, OrgId = OrganizationId, Amt = amount ?? payment });
                if (ti != null)
                    ti.OriginalId = ti.Id;
            }
            ti2.OriginalId = TranId;
            db.SubmitChanges();

            //            if (Organization.IsMissionTrip == true)
            //            {
            //                var settings = Settings.CreateSettings(Organization.RegSetting, db, OrganizationId);
            //            }

            return ti2;
        }
Ejemplo n.º 13
0
        public 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;
            var due = PaymentForm.AmountDueTrans(db, ti);
            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 = db.CreateRegistrationSettings(org.OrganizationId);
                        var fund = setting.DonationFundId;
                        p.PostUnattendedContribution(db, ti.Amt ?? 0, fund,
                            $"SupportMissionTrip: org={org.OrganizationId}; goer={pi.PeopleId}", typecode: BundleTypeCode.Online);
                    }
                    var pay = amt;
                    if (org.IsMissionTrip == true)
                        ti.Amtdue = due;

                    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", due);

                    om.AddToMemberDataBelowComments(sb.ToString());
                    var reg = p.SetRecReg();
                    reg.AddToComments(sb.ToString());
                    reg.AddToComments($"{org.OrganizationName} ({org.OrganizationId})");

                    amt -= pay;
                }
                else
                    db.Email(db.StaffEmailForOrg(org.OrganizationId),
                        db.PeopleFromPidString(org.NotifyIds),
                        "missing person on payment due",
                        $"Cannot find {pi.Person.Name} ({pi.PeopleId}), payment due completed of {pi.Amt:c} but no record");
            }
            db.SubmitChanges();

            dynamic d = new DynamicData();
            d.Name = Transaction.FullName(ti);
            d.Amt = ti.Amt;
            d.Description = ti.Description;
            d.Amtdue = PaymentForm.AmountDueTrans(db, ti);
            d.names = string.Join(", ", ti.OriginalTrans.TransactionPeople.Select(i => i.Person.Name));

            var msg = DbUtil.Db.RenderTemplate(@"
            <p>
            Thank you {{Name}}, for your payment of {{Fmt Amt 'c'}} on {{Description}}.<br/>
            {{#if Amtdue}}
            Your balance is {{Fmt Amtdue 'c'}}<br/>
            {{/if}}
            {{names}}
            </p>", d);
            var msgstaff = DbUtil.Db.RenderTemplate(@"
            <p>
            {{Name}} paid {{Fmt Amt 'c'}} on {{Description}}.<br/>
            {{#if Amtdue}}
            The balance is {{Fmt Amtdue 'c'}}<br/>
            {{/if}}
            {{names}}
            </p>", d);

            var pid = ti.FirstTransactionPeopleId();
            var p0 = db.LoadPersonById(pid);
            // question: should we be sending to all TransactionPeople?
            if (sendmail)
            {
                if (p0 == null)
                    db.SendEmail(Util.TryGetMailAddress(db.StaffEmailForOrg(org.OrganizationId)),
                        "Payment confirmation", msg, Util.ToMailAddressList(Util.FirstAddress(ti.Emails)), pid: pid).Wait();
                else
                {
                    db.Email(db.StaffEmailForOrg(org.OrganizationId), p0, Util.ToMailAddressList(ti.Emails),
                        "Payment confirmation", msg, false);
                    db.Email(p0.FromEmail, db.PeopleFromPidString(org.NotifyIds),
                        "payment received for " + ti.Description, msgstaff);
                }
            }
        }
Ejemplo n.º 14
0
 public static Transaction CreateTransaction(CMSDataContext Db, Transaction t, decimal? amount)
 {
     var amtdue = t.Amtdue != null ? t.Amtdue - (amount ?? 0) : null;
     var ti = new Transaction
              {
                  Name = t.Name,
                  First = t.First,
                  MiddleInitial = t.MiddleInitial,
                  Last = t.Last,
                  Suffix = t.Suffix,
                  Donate = t.Donate,
                  Amtdue = amtdue,
                  Amt = amount,
                  Emails = Util.FirstAddress(t.Emails).Address,
                  Testing = t.Testing,
                  Description = t.Description,
                  OrgId = t.OrgId,
                  Url = t.Url,
                  Address = t.Address,
                  TransactionGateway = OnlineRegModel.GetTransactionGateway(),
                  City = t.City,
                  State = t.State,
                  Zip = t.Zip,
                  DatumId = t.DatumId,
                  Phone = t.Phone,
                  OriginalId = t.OriginalId ?? t.Id,
                  Financeonly = t.Financeonly,
                  TransactionDate = DateTime.Now,
              };
     Db.Transactions.InsertOnSubmit(ti);
     Db.SubmitChanges();
     return ti;
 }
Ejemplo n.º 15
0
 public Transaction CreateTransaction(CMSDataContext Db, decimal? amount = null)
 {
     if (!amount.HasValue)
         amount = AmtToPay;
     decimal? amtdue = null;
     if (Amtdue > 0)
         amtdue = Amtdue - (amount ?? 0);
     var ti = new Transaction
              {
                  First = First,
                  MiddleInitial = MiddleInitial.Truncate(1) ?? "",
                  Last = Last,
                  Suffix = Suffix,
                  Donate = Donate,
                  Regfees = AmtToPay,
                  Amt = amount,
                  Amtdue = amtdue,
                  Emails = Email,
                  Testing = testing,
                  Description = Description,
                  OrgId = OrgId,
                  Url = Url,
                  TransactionGateway = OnlineRegModel.GetTransactionGateway(),
                  Address = Address.Truncate(50),
                  City = City,
                  State = State,
                  Zip = Zip,
                  DatumId = DatumId,
                  Phone = Phone.Truncate(20),
                  OriginalId = OriginalId,
                  Financeonly = FinanceOnly,
                  TransactionDate = DateTime.Now
              };
     Db.Transactions.InsertOnSubmit(ti);
     Db.SubmitChanges();
     if (OriginalId == null) // first transaction
         ti.OriginalId = ti.Id;
     return ti;
 }
Ejemplo n.º 16
0
 private OrganizationMember GetOrganizationMember(Transaction transaction)
 {
     var membertype = setting.AddAsProspect ? MemberTypeCode.Prospect : MemberTypeCode.Member;
     var om = OrganizationMember.InsertOrgMembers(DbUtil.Db, org.OrganizationId, person.PeopleId,
         membertype, DateTime.Now, null, false);
     if (om.TranId == null)
         om.TranId = transaction.OriginalId;
     om.RegisterEmail = EmailAddress;
     om.RegistrationDataId = Parent.DatumId;
     Log("JoinedOrg");
     return om;
 }
Ejemplo n.º 17
0
 internal string GetOthersInTransaction(Transaction transaction)
 {
     var TransactionPeopleIds = transaction.OriginalTrans.TransactionPeople.Select(tt => tt.PeopleId);
     var q = from pp in DbUtil.Db.People
         where TransactionPeopleIds.Contains(pp.PeopleId)
         where pp.PeopleId != PeopleId
         select pp.Name;
     var others = string.Join(",", q.ToArray());
     return others;
 }
Ejemplo n.º 18
0
 private TransactionResponse PayWithCreditCard(IGateway gateway, int? peopleId, Transaction transaction)
 {
     return gateway.PayWithCreditCard(peopleId ?? 0, AmtToPay ?? 0, CreditCard,
         DbUtil.NormalizeExpires(Expires).ToString2("MMyy"), Description, transaction.Id,
         CVV, Email, First, Last, Address, Address2,
         City, State, Country, Zip, Phone);
 }
Ejemplo n.º 19
0
        public static PaymentForm CreatePaymentFormForBalanceDue(Transaction ti, decimal amtdue, string email)
        {
            PaymentInfo pi = null;
            if (ti.Person != null)
                pi = ti.Person.PaymentInfos.FirstOrDefault();
            if (pi == null)
                pi = new PaymentInfo();

            var pf = new PaymentForm
            {
                URL = ti.Url,
                PayBalance = true,
                AmtToPay = amtdue,
                Amtdue = 0,
                AllowCoupon = true,
                AskDonation = false,
                Description = ti.Description,
                OrgId = ti.OrgId,
                OriginalId = ti.OriginalId,
                Email = Util.FirstAddress(ti.Emails ?? email).Address,
                FormId = Guid.NewGuid(),
                First = ti.First,
                MiddleInitial = ti.MiddleInitial.Truncate(1) ?? "",
                Last = ti.Last,
                Suffix = ti.Suffix,
                Phone = ti.Phone,
                Address = ti.Address,
                Address2 = ti.Address2,
                City = ti.City,
                State = ti.State,
                Country = ti.Country,
                Zip = ti.Zip,
                testing = ti.Testing ?? false,
                TranId = ti.Id
            };

            if (pi.PeopleId == Util.UserPeopleId) // Is this the logged in user?
            {
                pf.CreditCard = pi.MaskedCard;
                pf.Expires = pi.Expires;
                pf.Account = pi.MaskedAccount;
                pf.Routing = pi.Routing;
                pf.SavePayInfo =
                    (pi.MaskedAccount != null && pi.MaskedAccount.StartsWith("X"))
                    || (pi.MaskedCard != null && pi.MaskedCard.StartsWith("X"));
            }

            ClearMaskedNumbers(pf, pi);

            pf.Type = pf.NoEChecksAllowed ? PaymentType.CreditCard : "";
            var org = DbUtil.Db.LoadOrganizationById(ti.OrgId);
            return pf;
        }
Ejemplo n.º 20
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.º 21
0
 private TransactionResponse PayWithCheck(IGateway gw, int? pid, Transaction ti)
 {
     return gw.PayWithCheck(pid ?? 0, AmtToPay ?? 0, Routing, Account, Description, ti.Id, Email,
         First, MiddleInitial, Last, Suffix, Address, Address2, City, State, Country,
         Zip, Phone);
 }
Ejemplo n.º 22
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.º 23
0
        public 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;
            var due = PaymentForm.AmountDueTrans(Db, ti);
            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 = Db.CreateRegistrationSettings(org.OrganizationId);
                        var fund = setting.DonationFundId;
                        p.PostUnattendedContribution(Db, ti.Amt ?? 0, fund,
                            $"SupportMissionTrip: org={org.OrganizationId}; goer={pi.PeopleId}", typecode: BundleTypeCode.Online);
                    }
                    var pay = amt;
                    if (org.IsMissionTrip == true)
                        ti.Amtdue = due;

                    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", due);

                    om.AddToMemberDataBelowComments(sb.ToString());
                    var reg = p.SetRecReg();
                    reg.AddToComments(sb.ToString());
                    reg.AddToComments($"{org.OrganizationName} ({org.OrganizationId})");

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

            var pid = ti.FirstTransactionPeopleId();
            var p0 = Db.LoadPersonById(pid);
            // question: 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 {ti.Amt:c} for {ti.Description}.<br/>Your balance is {ti.Amtdue:c}<br/>{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 {ti.Amt:c} for {ti.Description}.<br/>Your balance is {ti.Amtdue:c}<br/>{names}", false);
                    Db.Email(p0.FromEmail,
                        Db.PeopleFromPidString(org.NotifyIds),
                        "payment received for " + ti.Description,
                        $"{Transaction.FullName(ti)} paid {ti.Amt:c} for {ti.Description}, balance of {due:c}\n({names})");
                }
            }
        }
Ejemplo n.º 24
0
 private void attach_Transactions(Transaction entity)
 {
     this.SendPropertyChanging();
     entity.OriginalTransaction = this;
 }
Ejemplo n.º 25
0
 public static string FullName(Transaction t)
 {
     return FullName(t.First, t.Last, t.MiddleInitial, t.Suffix, t.Name);
 }
Ejemplo n.º 26
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.º 27
0
 public static decimal AmountDueTrans(CMSDataContext db, Transaction ti)
 {
     var org = db.LoadOrganizationById(ti.OrgId);
     var tt = (from t in db.ViewTransactionSummaries
               where t.RegId == ti.OriginalId
               select t).FirstOrDefault();
     if (tt == null)
         return 0;
     if (org.IsMissionTrip ?? false)
         return (tt.IndAmt ?? 0) - (db.TotalPaid(tt.OrganizationId, tt.PeopleId) ?? 0);
     return tt.TotDue ?? 0;
 }
Ejemplo n.º 28
0
        public static PaymentForm CreatePaymentFormForBalanceDue(Transaction ti)
        {
            PaymentInfo pi = null;
            if (ti.Person != null && string.Equals(OnlineRegModel.GetTransactionGateway(),
                        "Sage", StringComparison.InvariantCultureIgnoreCase))
                pi = ti.Person.PaymentInfos.FirstOrDefault();
            if (pi == null)
                pi = new PaymentInfo();
            var pf = new PaymentForm
                     {
                         PayBalance = true,
                         AmtToPay = ti.Amtdue ?? 0,
                         Amtdue = ti.Amtdue ?? 0,
                         AllowCoupon = true,
                         AskDonation = false,
                         Description = ti.Description,
                         OrgId = ti.OrgId,
                         OriginalId = ti.OriginalId,
                         Email = Util.FirstAddress(ti.Emails).Address,

                         First = ti.First,
                         MiddleInitial = ti.MiddleInitial.Truncate(1) ?? "",
                         Last = ti.Last,
                         Suffix = ti.Suffix,

                         Phone = ti.Phone,
                         Address = ti.Address,
                         City = ti.City,
                         State = ti.State,
                         Zip = ti.Zip,
                         timeout = 6000000,
                         testing = ti.Testing ?? false,
                         TranId = ti.Id,
            #if DEBUG2
                         CreditCard = "4111111111111111",
                         CCV = "123",
                         Expires = "1015",
                         Routing = "056008849",
                         Account = "12345678901234"
            #else
                         CreditCard = pi.MaskedCard,
                         MaskedCCV = Util.Mask(new StringBuilder(pi.Ccv), 0),
                         CCV = pi.Ccv,
                         Expires = pi.Expires,
                         Account = pi.MaskedAccount,
                         Routing = pi.Routing,
                         SavePayInfo =
                            (pi.MaskedAccount != null && pi.MaskedAccount.StartsWith("X"))
                            || (pi.MaskedCard != null && pi.MaskedCard.StartsWith("X")),
            #endif
                     };
            pf.Type = pf.NoEChecksAllowed ? "C" : "";
            return pf;
        }
Ejemplo n.º 29
0
		private void detach_Transactions(Transaction entity)
		{
			this.SendPropertyChanging();
			entity.Person = null;
		}
Ejemplo n.º 30
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 gw = DbUtil.Db.Gateway(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 = gw.VoidCreditCardTransaction(re);
                if (!resp.Approved)
                    resp = gw.VoidCheckTransaction(re);

                t.Voided = resp.Approved;
                amt = t.Amt;
            }
            else
            {
                if (t.PaymentType == PaymentType.Ach)
                    resp = gw.RefundCheck(re, amt ?? 0);
                else if (t.PaymentType == PaymentType.CreditCard)
                    resp = gw.RefundCreditCard(re, amt ?? 0);

                t.Credited = resp.Approved;
            }

            if (!resp.Approved)
                return Content("error: " + resp.Message);

            var transaction = 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,
                PaymentType = t.PaymentType,
                LastFourCC = t.LastFourCC,
                LastFourACH = t.LastFourACH
            };

            DbUtil.Db.Transactions.InsertOnSubmit(transaction);
            DbUtil.Db.SubmitChanges();
            Util.SendMsg(Util.SysFromEmail, Util.Host,
                Util.TryGetMailAddress(DbUtil.Db.StaffEmailForOrg(transaction.OrgId ?? 0)),
                "Void/Credit Transaction Type: " + type,
                $@"<table>
<tr><td>Name</td><td>{Transaction.FullName(t)}</td></tr>
<tr><td>Email</td><td>{t.Emails}</td></tr>
<tr><td>Address</td><td>{t.Address}</td></tr>
<tr><td>Phone</td><td>{t.Phone}</td></tr>
<tr><th colspan=""2"">Transaction Info</th></tr>
<tr><td>Description</td><td>{t.Description}</td></tr>
<tr><td>Amount</td><td>{-amt:N2}</td></tr>
<tr><td>Date</td><td>{t.TransactionDate.Value.FormatDateTm()}</td></tr>
<tr><td>TranIds</td><td>Org: {t.Id} {t.TransactionId}, Curr: {transaction.Id} {transaction.TransactionId}</td></tr>
<tr><td>User</td><td>{Util.UserFullName}</td></tr>
</table>", Util.EmailAddressListFromString(DbUtil.Db.StaffEmailForOrg(transaction.OrgId ?? 0)),
                0, 0);
            DbUtil.LogActivity("CreditVoid for " + t.TransactionId);

            return View("List", m);
        }