Exemple #1
0
        private ConfirmEnum DoOnlineGiving(string transactionReturn)
        {
            var p = List[0];
            if (p.IsNew)
            {
                p.AddPerson(null, p.org.EntryPointId ?? 0);
            }

            var desc = $"{p.person.Name}; {p.person.PrimaryAddress}; {p.person.PrimaryZip}";
            var staff = DbUtil.Db.StaffPeopleForOrg(org.OrganizationId)[0];
            var body = GivingConfirmation.PostAndBuild(DbUtil.Db, staff, p.person, p.setting.Body, p.org.OrganizationId, p.FundItemsChosen(), Transaction, desc,
                p.setting.DonationFundId);

            if (!Transaction.TransactionId.HasValue())
            {
                Transaction.TransactionId = transactionReturn;
                if (testing == true && !Transaction.TransactionId.Contains("(testing)"))
                {
                    Transaction.TransactionId += "(testing)";
                }
            }
            var contributionemail = (from ex in p.person.PeopleExtras
                                     where ex.Field == "ContributionEmail"
                                     select ex.Data).SingleOrDefault();
            if (contributionemail.HasValue())
            {
                contributionemail = (contributionemail ?? "").Trim();
            }

            if (Util.ValidEmail(contributionemail))
            {
                Log("UsingSpecialEmail");
            }
            else
            {
                contributionemail = p.person.FromEmail;
            }

            MailAddress from = null;
            if (!Util.TryGetMailAddress(DbUtil.Db.StaffEmailForOrg(p.org.OrganizationId), out from))
            {
                from = GetAdminMailAddress();
            }

            var m = new EmailReplacements(DbUtil.Db, body, from);
            body = m.DoReplacements(DbUtil.Db, p.person);

            DbUtil.Db.EmailFinanceInformation(from, p.person, p.setting.Subject, body);
            DbUtil.Db.EmailFinanceInformation(contributionemail, DbUtil.Db.StaffPeopleForOrg(p.org.OrganizationId),
                "online giving contribution received",
                $"see contribution records for {p.person.Name} ({p.PeopleId}) {Util.Host}");
            if (p.CreatingAccount)
            {
                p.CreateAccount();
            }

            return ConfirmEnum.Confirm;
        }
Exemple #2
0
        public int DoGiving(CMSDataContext db)
        {
            var q = (from a in db.RecurringAmounts
                     where a.PeopleId == PeopleId
                     where a.ContributionFund.FundStatusId == 1
                     where a.ContributionFund.OnlineSort != null
                     where a.Amt > 0
                     select new GivingConfirmation.FundItem()
            {
                Amt = a.Amt.Value,
                Desc = a.ContributionFund.FundName,
                Fundid = a.FundId
            }).ToList();
            var total = q.Sum(vv => vv.Amt);

            if (total == 0)
            {
                return(0);
            }

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

            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,
                LoginPeopleId      = Person.PeopleId,
            };

            var vaultid = gw.VaultId(PeopleId);

            if (!vaultid.HasValue())
            {
                t.Message  = "Missing VaultId";
                t.Approved = false;
            }
            db.Transactions.InsertOnSubmit(t);
            db.SubmitChanges();
            if (!vaultid.HasValue())
            {
                return(0);
            }

            var ret = gw.PayWithVault(PeopleId, total, "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 notify = db.RecurringGivingNotifyPersons();
            var staff  = notify[0];
            var from   = Util.TryGetMailAddress(staff.EmailAddress);

            if (ret.Approved)
            {
                NextDate = FindNextDate(Util.Now.Date.AddDays(1));
                db.SubmitChanges();
                var msg = db.Content("RecurringGiftNotice") ?? new Content
                {
                    Title = $"Recurring {gift} for {{church}}",
                    Body  = $"Your gift of {total:C} was processed this morning."
                };
                var body    = GivingConfirmation.PostAndBuild(db, staff, Person, msg.Body, orgid, q, t, "Recurring Giving");
                var subject = msg.Title.Replace("{church}", church);
                var m       = new EmailReplacements(db, body, from);
                body = m.DoReplacements(db, Person);
                db.EmailFinanceInformation(from, Person, null, subject, body);
            }
            else
            {
                t.TransactionPeople.Add(new TransactionPerson
                {
                    PeopleId = Person.PeopleId,
                    Amt      = t.Amt,
                    OrgId    = orgid,
                });
                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}", $"${total: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);
        }