/// <summary> /// Creates a payment item and transaction for the paid invoice, against the 'Website' payment batch for today /// </summary> private void ProcessPaymentItem(Guid invoiceId, Guid contactId, decimal amount) { Guid paymentBatchId = this.GetWebsitePaymentBatch(); // Create transaction Entity trans = new Entity("mag_paymenttransaction"); trans["mag_contactid"] = MappingController.MapToEntityReference("contact", contactId); trans["mag_batchid"] = MappingController.MapToEntityReference("mag_paymentbatch", paymentBatchId); trans["mag_isprocessed"] = true; trans["mag_transactiontypecode"] = new OptionSetValue(809730002); // Credit Card trans["mag_transactiondate"] = DateTime.Today; trans["mag_amount"] = new Money(amount); Guid transId = this._sdk.Create(trans); // Create payment item Entity item = new Entity("mag_paymentitem"); item["mag_transactionid"] = MappingController.MapToEntityReference("mag_paymenttransaction", transId); item["mag_invoiceid"] = MappingController.MapToEntityReference("invoice", invoiceId); item["mag_amount"] = new Money(amount); Guid paymentItemId = this._sdk.Create(item); _tracer.Trace("paymentItemId={0}", paymentItemId); }
public Guid CreateContact(Contact c, bool isDonation) { this._tracer.Trace("Method: DonationController.CreateContact"); Entity contact = new Entity("contact"); contact["mag_salutationcode"] = MappingController.MapToOptionSetValue(c.SalutationCode); contact["firstname"] = c.FirstName; contact["lastname"] = c.LastName; contact["mag_organisationid"] = MappingController.MapToEntityReference("account", this.GetAccountId(c.CompanyName)); if (isDonation) { contact["mag_donor"] = c.IsDonor; } else { contact["donotbulkemail"] = false; } // CNR allow bulk email by default contact["gendercode"] = MappingController.MapToOptionSetValue(c.Gender); contact["birthdate"] = c.DateOfBirth; if (c.DateOfBirth.HasValue) { contact["mag_yearofbirth"] = c.DateOfBirth.Value.Year; } contact["emailaddress1"] = c.EmailAddress; contact["telephone3"] = c.WorkPhone; contact["telephone2"] = c.HomePhone; contact["mobilephone"] = c.MobilePhone; contact["address1_line1"] = c.Street; contact["address1_line2"] = c.Street2; contact["address1_line3"] = c.Suburb; contact["address1_city"] = c.City; contact["address1_postalcode"] = c.PostalCode; //contact["mag_importsource"] = "Online Donation"; // todo: uncomment once the field has been created in crm //contact["mag_matchcode"] = c.MatchCode.ToString(); // todo: uncomment once the field has been created in crm // note: design doc says to pass in job title but api data dictionary doesn't include this field /* fields don't exist in crm yet * contact["mag_sourcefamilyfriend"] = d.SourcedByFamilyOrFriend; * contact["mag_sourceismember"] = d.IsMember; * contact["mag_sourcewebsite"] = d.SourcedByWebsite; * contact["mag_sourcetext"] = d.SourceText; */ return(this._sdk.Create(contact)); }
private Guid CreatePaymentItem(Guid transactionId, Guid donationId, decimal amount) { this._tracer.Trace("Method: DonationController.CreatePaymentItem"); this._tracer.Trace("Parameters: transactionId={0}, donationId={1}, amount={2}", transactionId, donationId, amount); Entity paymentItem = new Entity("mag_paymentitem"); paymentItem["mag_transactionid"] = MappingController.MapToEntityReference("mag_paymenttransaction", transactionId); paymentItem["mag_donationid"] = MappingController.MapToEntityReference("mag_donation", donationId); paymentItem["mag_amount"] = new Money(amount); return(this._sdk.Create(paymentItem)); }
private Guid CreatePaymentTransaction(Guid batchId, Guid contactId, Donation donation) { this._tracer.Trace("Method: DonationController.CreatePaymentTransaction"); this._tracer.Trace("Parameters: batchId={0}, contactId={1}, donation", batchId, contactId); Entity paymentTransaction = new Entity("mag_paymenttransaction"); paymentTransaction["mag_batchid"] = MappingController.MapToEntityReference("mag_paymentbatch", batchId); paymentTransaction["mag_contactid"] = MappingController.MapToEntityReference("contact", contactId); paymentTransaction["mag_amount"] = new Money(donation.Amount); paymentTransaction["mag_isprocessed"] = true; paymentTransaction["mag_transactiondate"] = donation.Date; paymentTransaction["mag_transactionid"] = donation.DpsTransactionReference; paymentTransaction["mag_transactiontypecode"] = new OptionSetValue((int)PaymentTransactionTypeCode.CreditCard); return(this._sdk.Create(paymentTransaction)); }
public Guid CreatePledge(Donation donation, Guid contactId, Guid regionTagId, Guid campaignTagId, PaymentRepeatOptionCode repeatOption) { this._tracer.Trace("Method: DonationController.CreatePledge"); this._tracer.Trace("Parameters: donation, contactId={0}, regionTagId={1}, campaignTagId={2}, repeatOption={3}", contactId, regionTagId, campaignTagId, repeatOption); Entity pledge = new Entity("mag_pledge"); pledge["mag_dpsbillingid"] = donation.Pledge.DpsBillingId; pledge["mag_pledgeforcode"] = new OptionSetValue((int)DonationForCode.Individual); pledge["mag_contactid"] = MappingController.MapToEntityReference("contact", contactId); pledge["mag_campaignid"] = MappingController.MapToEntityReference("campaign", donation.CampaignId); pledge["mag_campaigntagid"] = MappingController.MapToEntityReference("mag_tag", campaignTagId); pledge["mag_coastguardregionunittagid"] = MappingController.MapToEntityReference("mag_tag", regionTagId); pledge["mag_pledgetypecode"] = new OptionSetValue((int)DonationTypeCode.Cash); pledge["mag_isregulargift"] = donation.IsRegularGift; pledge["mag_paymentfrequencycode"] = MappingController.MapToOptionSetValue(donation.Pledge.PaymentFrequencyCode); pledge["mag_comments"] = donation.Comments; pledge["mag_reasonforhelpingid"] = MappingController.MapToEntityReference("mag_reasonforhelping", donation.ReasonForHelpingId); // set the start date to the pledge start date, or use today's date. This is for the naming plugin pledge["mag_startdate"] = donation.Pledge.StartDate.HasValue ? GetUtcDateTime(donation.Pledge.StartDate.Value) : DateTime.UtcNow; pledge["mag_paymentmethodcode"] = new OptionSetValue((int)PaymentMethodCode.CreditCard); pledge["mag_cashvalue"] = new Money(donation.Amount); pledge["mag_importsource"] = "Online Donation"; pledge["mag_transactionid"] = donation.DpsTransactionReference; // set the payment repeat option and end date for regular gifts if (donation.IsRegularGift) { pledge["mag_paymentrepeatoptioncode"] = new OptionSetValue((int)repeatOption); pledge["mag_enddate"] = donation.Pledge.EndDate; pledge["mag_creditcardexpirydate"] = base.GetCCExpiryDate(donation.CCExpiry); } // set the owner to the owner of the contact if (donation.Donor.OwnerId != default(Guid)) { this._tracer.Trace("Pledge ownerid={0}, ownerType={1}", donation.Donor.OwnerId, donation.Donor.OwnerLogicalName); pledge["ownerid"] = MappingController.MapToEntityReference(donation.Donor.OwnerLogicalName, donation.Donor.OwnerId); } return(this._sdk.Create(pledge)); }
public Guid CreateDonation(Donation d, Guid contactId, Guid pledgeId, Guid regionTagId, Guid campaignTagId) { this._tracer.Trace("Method: DonationController.CreateDonation"); this._tracer.Trace("Parameters: d, contactId={0}, pledgeId={1}, regionTagId={2}, campaignTagId={3}", contactId, pledgeId, regionTagId, campaignTagId); Entity donation = new Entity("mag_donation"); donation["mag_donationforcode"] = new OptionSetValue((int)DonationForCode.Individual); donation["mag_contactid"] = MappingController.MapToEntityReference("contact", contactId); donation["statuscode"] = new OptionSetValue((int)DonationStatusCode.Collected); donation["mag_pledgeid"] = MappingController.MapToEntityReference("mag_pledge", pledgeId); donation["mag_campaignid"] = MappingController.MapToEntityReference("campaign", d.CampaignId); donation["mag_campaigntagid"] = MappingController.MapToEntityReference("mag_tag", campaignTagId); donation["mag_coastguardregionunittagid"] = MappingController.MapToEntityReference("mag_tag", regionTagId); donation["mag_donationtypecode"] = new OptionSetValue((int)DonationTypeCode.Cash); donation["mag_donationdate"] = d.Date; donation["mag_donationcloseddate"] = d.Date; donation["mag_cashvalue"] = new Money(d.Amount); donation["mag_isregulargift"] = d.IsRegularGift; donation["mag_paymentmethodcode"] = new OptionSetValue((int)PaymentMethodCode.CreditCard); donation["mag_transactionid"] = d.DpsTransactionReference; donation["mag_transactionstatus"] = d.DpsResponseText; donation["mag_importsource"] = "Online Donation"; donation["mag_taxreceiptname"] = string.IsNullOrEmpty(d.Donor.NameOnTaxReceipt) ? string.Format("{0} {1}", d.Donor.FirstName, d.Donor.LastName) : d.Donor.NameOnTaxReceipt; donation["mag_comments"] = d.Comments; donation["mag_reasonforhelpingid"] = MappingController.MapToEntityReference("mag_reasonforhelping", d.ReasonForHelpingId); donation["mag_receipted"] = true; donation["mag_receiptdate"] = DateTime.Now; // set the owner to the owner of the contact if (d.Donor.OwnerId != default(Guid)) { this._tracer.Trace("Donation ownerid={0}, ownerType={1}", d.Donor.OwnerId, d.Donor.OwnerLogicalName); donation["ownerid"] = MappingController.MapToEntityReference(d.Donor.OwnerLogicalName, d.Donor.OwnerId); } return(this._sdk.Create(donation)); }
/// <summary> /// Find a matching Membership in CRM based on the contact id, membership number, and associated "unpaid" invoice /// NOTE: UNUSED METHOD /// </summary> //private Membership MatchMembership(Membership membership, MatchController mc) //{ // Guid contactId = membership.Member.ContactId; // string membershipNumber = membership.MembershipNumber; // List<Membership> memberships = this.GetMemberships(contactId, membershipNumber); // Membership match = mc.MatchToExistingMembership(memberships); // membership.MatchCode = match.MatchCode; // set the match code // // create a membership // if (membership.MembershipId == default(Guid)) // { // membership.MembershipId = this.CreateMembership(membership); // } // return membership; //} /// <summary> /// Creates a new Membership in CRM for the associated Contact. Note - an Invoice will automatically be created from a plugin /// </summary> private Guid CreateMembership(Membership membership, Guid unitId) { this._tracer.Trace("Method: MembershipController.CreateMembership"); this._tracer.Trace("Parameters: unitId={0}", unitId); Entity mShip = new Entity("mag_membership"); mShip["mag_idnumber"] = membership.MembershipNumber; mShip["mag_contactid"] = MappingController.MapToEntityReference("contact", membership.Member.ContactId); mShip["mag_membershiptypeid"] = MappingController.MapToEntityReference("product", membership.MembershipType.MembershipTypeId); mShip["mag_startdate"] = DateTime.Now; mShip["mag_regionid"] = MappingController.MapToEntityReference("businessunit", membership.RegionCodeId); mShip["mag_unitid"] = MappingController.MapToEntityReference("mag_coastguardunit", unitId); mShip["mag_transactionid"] = membership.DpsTransactionReference; mShip["mag_membershipsourcecode"] = new OptionSetValue((int)MembershipSourceCode.Online); // online mShip["mag_paymentmethodcode"] = new OptionSetValue((int)PaymentMethodCode.CreditCard); mShip["mag_creditcardexpirydate"] = base.GetCCExpiryDate(membership.CCExpiry); mShip["mag_membershipsupportsid"] = MappingController.MapToEntityReference("mag_tag", membership.UnitCodeId); Guid membershipId = this._sdk.Create(mShip); // Plugin triggers to generate and link the invoice with the new membership // Get the new membership with the invoice ID and pay the invoice Entity newMembership = this._sdk.Retrieve("mag_membership", membershipId, new ColumnSet("mag_invoiceid")); Guid invoiceId = newMembership.Get <Guid>("mag_invoiceid"); if (invoiceId != null && invoiceId != Guid.Empty) { this.UpdateInvoicePaid(invoiceId); // Create a payment item for the invoice this.ProcessPaymentItem(invoiceId, membership.Member.ContactId, membership.MembershipType.Price); } return(membershipId); }