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; }
private string ConfirmTransaction(OnlineRegModel m, string TransactionID, ExtraDatum ed = null) { m.ParseSettings(); if (m.List.Count == 0) return "error: unexpected, no registrants found in confirmation"; string confirm = "Confirm"; var managingsubs = m.ManagingSubscriptions(); var choosingslots = m.ChoosingSlots(); var t = m.Transaction; if (t == null && !managingsubs && !choosingslots) { var pf = PaymentForm.CreatePaymentForm(m); if (ed != null) pf.DatumId = ed.Id; t = pf.CreateTransaction(DbUtil.Db); m.TranId = t.Id; if (ed != null) { m.History.Add("ConfirmTransaction"); ed.Completed = true; ed.Data = Util.Serialize<OnlineRegModel>(m); DbUtil.Db.SubmitChanges(); } } if (t != null) ViewData["message"] = t.Message; if (m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.CreateAccount) { m.List[0].CreateAccount(); ViewData["CreatedAccount"] = true; confirm = "ConfirmAccount"; } else if (m.OnlineGiving()) { var p = m.List[0]; if (p.IsNew) p.AddPerson(null, p.org.EntryPointId ?? 0); var staff = DbUtil.Db.StaffPeopleForOrg(p.org.OrganizationId)[0]; var text = p.setting.Body.Replace("{church}", DbUtil.Db.Setting("NameOfChurch", "church"), ignoreCase:true); text = text.Replace("{amt}", (t.Amt ?? 0).ToString("N2")); text = text.Replace("{date}", DateTime.Today.ToShortDateString()); text = text.Replace("{tranid}", t.Id.ToString()); text = text.Replace("{name}", p.person.Name); text = text.Replace("{account}", ""); text = text.Replace("{email}", p.person.EmailAddress); text = text.Replace("{phone}", p.person.HomePhone.FmtFone()); text = text.Replace("{contact}", staff.Name); text = text.Replace("{contactemail}", staff.EmailAddress); text = text.Replace("{contactphone}", p.org.PhoneNumber.FmtFone()); var re = new Regex(@"(?<b>.*?)<!--ITEM\sROW\sSTART-->(?<row>.*?)\s*<!--ITEM\sROW\sEND-->(?<e>.*)", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace); var match = re.Match(text); var b = match.Groups["b"].Value; var row = match.Groups["row"].Value.Replace("{funditem}", "{0}").Replace("{itemamt}", "{1:N2}"); var e = match.Groups["e"].Value; var sb = new StringBuilder(b); var desc = "{0}; {1}; {2}".Fmt( p.person.Name, p.person.PrimaryAddress, p.person.PrimaryZip); foreach (var g in p.FundItemsChosen()) { if (g.amt > 0) { sb.AppendFormat(row, g.desc, g.amt); p.person.PostUnattendedContribution(DbUtil.Db, g.amt, g.fundid, desc); } } t.Financeonly = true; if (t.Donate > 0) { var fundname = DbUtil.Db.ContributionFunds.Single(ff => ff.FundId == p.setting.DonationFundId).FundName; sb.AppendFormat(row, fundname, t.Donate); t.Fund = p.setting.DonationFund(); p.person.PostUnattendedContribution(DbUtil.Db, t.Donate.Value, p.setting.DonationFundId, desc); } sb.Append(e); if (!t.TransactionId.HasValue()) { t.TransactionId = TransactionID; if (m.testing == true && !t.TransactionId.Contains("(testing)")) t.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)) contributionemail = p.person.FromEmail; Util.SendMsg(Util.SysFromEmail, Util.Host, Util.TryGetMailAddress(DbUtil.Db.StaffEmailForOrg(p.org.OrganizationId)), p.setting.Subject, sb.ToString(), Util.EmailAddressListFromString(contributionemail), 0, p.PeopleId); DbUtil.Db.Email(contributionemail, DbUtil.Db.StaffPeopleForOrg(p.org.OrganizationId), "online giving contribution received", "see contribution records for {0} ({1})".Fmt(p.person.Name, p.PeopleId)); if (p.CreatingAccount == true) p.CreateAccount(); } else if (managingsubs) { m.ConfirmManageSubscriptions(); m.URL = null; ViewData["ManagingSubscriptions"] = true; ViewData["CreatedAccount"] = m.List[0].CreatingAccount; confirm = "ConfirmAccount"; } else if (choosingslots) { m.ConfirmPickSlots(); m.URL = null; ViewData["ManagingVolunteer"] = true; ViewData["CreatedAccount"] = m.List[0].CreatingAccount; confirm = "ConfirmAccount"; } else if (m.OnlinePledge()) { m.ConfirmManagePledge(); ViewData["ManagingPledge"] = true; ViewData["CreatedAccount"] = m.List[0].CreatingAccount; confirm = "ConfirmAccount"; } else if (m.ManageGiving()) { m.ConfirmManageGiving(); ViewData["ManagingGiving"] = true; ViewData["CreatedAccount"] = m.List[0].CreatingAccount; confirm = "ConfirmAccount"; } else if (t.TransactionGateway.ToLower() == "serviceu") { t.TransactionId = TransactionID; if (m.testing == true && !t.TransactionId.Contains("(testing)")) t.TransactionId += "(testing)"; t.Message = "Transaction Completed"; t.Approved = true; m.EnrollAndConfirm(); if (m.List.Any(pp => pp.PeopleId == null)) { LogOutOfOnlineReg(); return "error: no person"; } m.UseCoupon(t.TransactionId, t.Amt ?? 0); } else { if (!t.TransactionId.HasValue()) { t.TransactionId = TransactionID; if (m.testing == true && !t.TransactionId.Contains("(testing)")) t.TransactionId += "(testing)"; } m.EnrollAndConfirm(); if (m.List.Any(pp => pp.PeopleId == null)) { LogOutOfOnlineReg(); return "error: no person"; } m.UseCoupon(t.TransactionId, t.Amt ?? 0); } if (m.IsCreateAccount() || m.ManagingSubscriptions()) ViewData["email"] = m.List[0].person.EmailAddress; else ViewData["email"] = m.List[0].email; if(m.masterorgid.HasValue && m.orgid.HasValue && !m.settings[m.orgid.Value].Subject.HasValue()) ViewData["orgname"] = m.masterorg.OrganizationName; else ViewData["orgname"] = m.org != null ? m.org.OrganizationName : m.masterorg.OrganizationName; LogOutOfOnlineReg(); return confirm; }
public static PaymentForm CreatePaymentForm(OnlineRegModel m) { var r = m.GetTransactionInfo(); if (r == null) return null; var pf = new PaymentForm { AmtToPay = m.PayAmount() + (m.donation ?? 0), AskDonation = m.AskDonation(), AllowCoupon = !m.OnlineGiving(), PayBalance = false, Amtdue = m.TotalAmount() + (m.donation ?? 0), Donate = m.donation, Description = m.DescriptionForPayment, Email = r.Email, First = r.First, MiddleInitial = r.Middle, Last = r.Last, Suffix = r.Suffix, IsLoggedIn = m.UserPeopleId.HasValue, OrgId = m.List[0].orgid, Url = m.URL, testing = m.testing ?? false, Terms = m.Terms, Address = r.Address, City = r.City, State = r.State, Zip = r.Zip, Phone = r.Phone, #if DEBUG2 CreditCard = "4111111111111111", CCV = "123", Expires = "1015", Routing = "056008849", Account = "12345678901234" #else CreditCard = r.payinfo.MaskedCard, Account = r.payinfo.MaskedAccount, Routing = r.payinfo.Routing, Expires = r.payinfo.Expires, MaskedCCV = Util.Mask(new StringBuilder(r.payinfo.Ccv), 0), CCV = r.payinfo.Ccv, SavePayInfo = (r.payinfo.MaskedAccount != null && r.payinfo.MaskedAccount.StartsWith("X")) || (r.payinfo.MaskedCard != null && r.payinfo.MaskedCard.StartsWith("X")), Type = r.payinfo.PreferredPaymentType, #endif }; if (m.OnlineGiving()) { pf.NoCreditCardsAllowed = DbUtil.Db.Setting("NoCreditCardGiving", "false").ToBool(); pf.IsGiving = true; pf.Type = r.payinfo.PreferredGivingType; if (pf.NoCreditCardsAllowed) pf.Type = "B"; // bank account only else if (pf.NoEChecksAllowed) pf.Type = "C"; // credit card only } pf.Type = pf.NoEChecksAllowed ? "C" : pf.Type; return pf; }
public static PaymentForm CreatePaymentForm(OnlineRegModel m) { var r = m.GetTransactionInfo(); if (r == null) { return(null); } var pf = new PaymentForm { AmtToPay = m.PayAmount() + (m.donation ?? 0), AskDonation = m.AskDonation(), AllowCoupon = !m.OnlineGiving(), PayBalance = false, Amtdue = m.TotalAmount() + (m.donation ?? 0), Donate = m.donation, Description = m.Header, Email = r.Email, First = r.First, MiddleInitial = r.Middle, Last = r.Last, Suffix = r.Suffix, IsLoggedIn = m.UserPeopleId.HasValue, OrgId = m.List[0].orgid, Url = m.URL, testing = m.testing ?? false, Terms = m.Terms, Address = r.Address, City = r.City, State = r.State, Zip = r.Zip, Phone = r.Phone, #if DEBUG2 CreditCard = "4111111111111111", CCV = "123", Expires = "1015", Routing = "056008849", Account = "12345678901234" #else CreditCard = r.payinfo.MaskedCard, Account = r.payinfo.MaskedAccount, Routing = r.payinfo.Routing, Expires = r.payinfo.Expires, MaskedCCV = Util.Mask(new StringBuilder(r.payinfo.Ccv), 0), CCV = r.payinfo.Ccv, SavePayInfo = (r.payinfo.MaskedAccount != null && r.payinfo.MaskedAccount.StartsWith("X")) || (r.payinfo.MaskedCard != null && r.payinfo.MaskedCard.StartsWith("X")), Type = r.payinfo.PreferredPaymentType, #endif }; if (m.OnlineGiving()) { pf.NoCreditCardsAllowed = DbUtil.Db.Setting("NoCreditCardGiving", "false").ToBool(); pf.IsGiving = true; pf.Type = r.payinfo.PreferredGivingType; if (pf.NoCreditCardsAllowed) { pf.Type = "B"; // bank account only } else if (pf.NoEChecksAllowed) { pf.Type = "C"; // credit card only } } pf.Type = pf.NoEChecksAllowed ? "C" : pf.Type; return(pf); }
// Set suggested giving fee for an indidividual person private static void CheckSetFee(OnlineRegModel m, OnlineRegPersonModel p) { if (m.OnlineGiving() && p.setting.ExtraValueFeeName.HasValue()) { var f = CmsWeb.Models.OnlineRegPersonModel.Funds().SingleOrDefault(ff => ff.Text == p.setting.ExtraValueFeeName); var evamt = p.person.GetExtra(p.setting.ExtraValueFeeName).ToDecimal(); if (f != null && evamt > 0) p.FundItem[f.Value.ToInt()] = evamt; } }
public static PaymentForm CreatePaymentForm(OnlineRegModel m) { var r = m.GetTransactionInfo(); if (r == null) { return(null); } var pf = new PaymentForm { FormId = Guid.NewGuid(), AmtToPay = m.PayAmount() + (m.donation ?? 0), AskDonation = m.AskDonation(), AllowCoupon = !m.OnlineGiving(), PayBalance = false, Amtdue = m.TotalAmount() + (m.donation ?? 0), Donate = m.donation, Description = m.DescriptionForPayment, Email = r.Email, First = r.First, MiddleInitial = r.Middle, Last = r.Last, Suffix = r.Suffix, IsLoggedIn = m.UserPeopleId.HasValue, OrgId = m.List[0].orgid, URL = m.URL, testing = m.testing ?? false, Terms = m.Terms, Address = r.Address, Address2 = r.Address2, City = r.City, State = r.State, Country = r.Country, Zip = r.Zip, Phone = r.Phone, #if DEBUG2 CreditCard = "4111111111111111", CVV = "123", Expires = "1015", Routing = "056008849", Account = "12345678901234" #else CreditCard = r.payinfo.MaskedCard, Account = r.payinfo.MaskedAccount, Routing = r.payinfo.Routing, Expires = r.payinfo.Expires, SavePayInfo = (r.payinfo.MaskedAccount != null && r.payinfo.MaskedAccount.StartsWith("X")) || (r.payinfo.MaskedCard != null && r.payinfo.MaskedCard.StartsWith("X")), Type = r.payinfo.PreferredPaymentType, #endif }; ClearMaskedNumbers(pf, r.payinfo); pf.AllowSaveProgress = m.AllowSaveProgress(); pf.NoCreditCardsAllowed = m.NoCreditCardsAllowed(); if (m.OnlineGiving()) { pf.NoCreditCardsAllowed = DbUtil.Db.Setting("NoCreditCardGiving", "false").ToBool(); pf.IsGiving = true; pf.FinanceOnly = true; pf.Type = r.payinfo.PreferredGivingType; } else if (m.ManageGiving() || m.OnlinePledge()) { pf.FinanceOnly = true; } if (pf.NoCreditCardsAllowed) { pf.Type = PaymentType.Ach; // bank account only } else if (pf.NoEChecksAllowed) { pf.Type = PaymentType.CreditCard; // credit card only } pf.Type = pf.NoEChecksAllowed ? PaymentType.CreditCard : pf.Type; pf.DatumId = m.DatumId ?? 0; return(pf); }