public Transaction createTransaction(MobilePostTransaction mpt) { var ti = new Transaction(); ti.First = mpt.first; ti.MiddleInitial = mpt.middle; ti.Last = mpt.last; ti.Suffix = mpt.suffix; ti.Amt = mpt.amount; ti.Emails = mpt.email; ti.Description = mpt.description; ti.OrgId = mpt.orgID; ti.Address = mpt.address; ti.City = mpt.city; ti.State = mpt.state; ti.Zip = mpt.zip; ti.Phone = mpt.phone; ti.TransactionDate = mpt.date; DbUtil.Db.Transactions.InsertOnSubmit(ti); DbUtil.Db.SubmitChanges(); ti.OriginalId = ti.Id; DbUtil.Db.SubmitChanges(); return(ti); }
public void sendConfirmation(MobilePostTransaction mpt) { var person = DbUtil.Db.LoadPersonById(mpt.peopleID); var staff = DbUtil.Db.StaffPeopleForOrg(mpt.orgID)[0]; var org = DbUtil.Db.LoadOrganizationById(mpt.orgID); var settings = new Settings(org.RegSetting, DbUtil.Db, mpt.orgID); var text = settings.Body.Replace("{church}", DbUtil.Db.Setting("NameOfChurch", "church"), ignoreCase: true); text = text.Replace("{amt}", (mpt.amount).ToString("N2")); text = text.Replace("{date}", DateTime.Today.ToShortDateString()); text = text.Replace("{tranid}", mpt.transactionID.ToString()); text = text.Replace("{name}", person.Name); text = text.Replace("{account}", ""); text = text.Replace("{email}", person.EmailAddress); text = text.Replace("{phone}", person.HomePhone.FmtFone()); text = text.Replace("{contact}", staff.Name); text = text.Replace("{contactemail}", staff.EmailAddress); text = text.Replace("{contactphone}", 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(person.Name, person.PrimaryAddress, person.PrimaryZip); foreach (var item in mpt.items) { sb.AppendFormat(row, item.name, item.amount); person.PostUnattendedContribution(DbUtil.Db, item.amount, item.id, desc); } 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; } Util.SendMsg(Util.SysFromEmail, Util.Host, Util.TryGetMailAddress(DbUtil.Db.StaffEmailForOrg(mpt.orgID)), settings.Subject, sb.ToString(), Util.EmailAddressListFromString(contributionemail), 0, person.PeopleId); DbUtil.Db.Email(contributionemail, DbUtil.Db.StaffPeopleForOrg(mpt.orgID), "Online giving contribution received", "See contribution records for {0} ({1})".Fmt(person.Name, person.PeopleId)); /* * 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)"; * } * p.CreateAccount(); */ }
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!")); } }