private static abstractCustomizableEntityEntry AddSourceCodeToConstintuent(Donor d) { //add source code to donor var fm = new abstractCustomizableEntityEntry() { key = "source", value = new customField() { name = "source", value = SourceCodePickList().First().itemName, entityType = "constituent", sequenceNumber = 0, dataType = 0, } }; return(fm); }
private static abstractCustomizableEntityEntry AddCommunicationPreferences(Donor d) { //add opt in preferences to donor var fm = new abstractCustomizableEntityEntry() { key = "communicationPreferences", value = new customField() { name = "communicationPreferences", value = d.NesletterOptIn ? "Opt In" : "Unknown", entityType = "constituent", sequenceNumber = 0, dataType = 0, } }; return(fm); }
private static constituent CreateConstituent(Donor d) { var constt = new constituent(); try { var fieldMap = new abstractCustomizableEntityEntry[2]; fieldMap[0] = AddSourceCodeToConstintuent(d); fieldMap[1] = AddCommunicationPreferences(d); constt.firstName = d.FName; constt.lastName = d.LName; constt.constituentType = "individual"; constt.customFieldMap = fieldMap; constt.inactive = false; constt.createDate = DateTime.Now; constt.updateDate = DateTime.Now; var request = new SaveOrUpdateConstituentRequest { constituent = constt }; var response = _client.SaveOrUpdateConstituent(request); return(response.constituent); } catch (FaultException exception) { Type exType = exception.GetType(); MessageFault mf = exception.CreateMessageFault(); Console.WriteLine("Error when creating constituent // " + exception.Message); if (mf.HasDetail) { var detailedMessage = mf.GetDetail <System.Xml.Linq.XElement>(); String message = detailedMessage.FirstNode.ToString(); Console.WriteLine("More details // " + message); } } catch (Exception exc) { var txt = exc; } return(null); }
private static abstractCustomizableEntityEntry createCustomFieldMap(string key, long datatype, long entityId, string entityType, string name, string value) { //read project codes, and use in setup on which one to use. var fm = new abstractCustomizableEntityEntry { key = key }; var cf = new customField { dataType = datatype, entityId = entityId, entityType = entityType, name = name, value = value }; fm.value = cf; return(fm); }
private static void AddGiftToConstituent(Donation donation, ref constituent constt) { /* 12/16/2014 * For now, send all of our donations over as "CASH" until OLOD's API can handle pre-processed donations. * * */ try { var g = new gift(); var ps = new paymentSource(); var fieldMap = new abstractCustomizableEntityEntry[1]; fieldMap[0] = createCustomFieldMap("source", 0, constt.id, "source", "source", donation.SourceCode); ps.paymentType = PaymentType.Cash; ps.constituentId = constt.id; g.paymentSource = ps; var billing = donation.Donor.DonorAddresses.FirstOrDefault(x => x.AddressType == Enum_AddressType.Billing); var nowDate = DateTime.Now; g.createDate = nowDate; g.updateDate = nowDate; g.currencyCode = "USD"; g.address = TranslateAddress(billing, false); g.amount = donation.Amount; g.comments = "Processed by RaiseDonors using card ending in x" + donation.Last4ofCC; if (!string.IsNullOrEmpty(donation.Comment)) { g.comments += "Donor provided comment: " + donation.Comment; } g.customFieldMap = fieldMap; g.constituentId = constt.id; g.deductible = false; g.deductibleAmount = 0.00m; g.donationDate = nowDate; g.email = constt.primaryEmail; g.giftStatus = "Paid"; //Paid, Pending, Not Paid g.paymentType = PaymentType.Cash; g.phone = constt.primaryPhone; g.transactionDate = nowDate; g.transactionDateSpecified = true; //conditionally hide these -- wait for paul's response on what is best. //g.paymentStatus = ""; g.paymentMessage = "Processed thru RaiseDonors"; g.authCode = donation.AuthorizationNumber; g.txRefNum = donation.TransactionId; var distLines = new List <distributionLine>(); foreach (var d in donation.DonationFundAllocations) { //read project codes, and use in setup on which one to use. var fieldMaps = new List <abstractCustomizableEntityEntry> { createCustomFieldMap("anonymous", 0, constt.id, "distributionline", "anonymous", "false"), createCustomFieldMap("recognitionName", 0, constt.id, "distributionline", "recognitionName", donation.Donor.FullName), createCustomFieldMap("totalAdjustedAmount", 0, constt.id, "distributionline", "totalAdjustedAmount", d.Amount.ToString("0.00")), createCustomFieldMap("taxDeductible", 0, constt.id, "distributionline", "taxDeductible", "true"), }; var dLine = new distributionLine { customFieldMap = fieldMaps.ToArray(), amount = d.Amount, amountSpecified = true, other_motivationCode = donation.MotivationCode, //percentage = Math.Round((d.Amount / donation.Amount) * 100, 2, MidpointRounding.AwayFromZero), //motivationCode = donation.MotivationCode, //what motivated to give - don't use this one projectCode = d.Fund.Name //gift designation? }; distLines.Add(dLine); } //source-code, use customfield on the gift. //project, and source will throw error if not pre-existing. //throws error //Value cannot be null. //Parameter name: source g.distributionLines = distLines.ToArray(); var request = new SaveOrUpdateGiftRequest { gift = g, constituentId = constt.id }; var response = _client.SaveOrUpdateGift(request); Console.WriteLine("Successfully sent gift to OLOD, gift ID: " + response.gift.id + "."); } catch (FaultException exception) { Type exType = exception.GetType(); MessageFault mf = exception.CreateMessageFault(); Console.WriteLine("Error when adding gift to constituent // " + exception.Message); if (mf.HasDetail) { var detailedMessage = mf.GetDetail <System.Xml.Linq.XElement>(); String message = detailedMessage.FirstNode.ToString(); Console.WriteLine("More details // " + message); } } catch (Exception exc) { var text = exc; } }