예제 #1
0
        /// <summary>
        /// Find a matching Contact in CRM based on the first name, last name, home phone, mobile phone, email address
        /// </summary>
        private Contact MatchContact(Membership membership, MatchController mc)
        {
            this._tracer.Trace("Method: MembershipController.MatchContact");

            string firstName    = membership.Member.FirstName;
            string lastName     = membership.Member.LastName;
            string homePhone    = membership.Member.HomePhone;
            string mobilePhone  = membership.Member.MobilePhone;
            string emailAddress = membership.Member.EmailAddress;

            this._tracer.Trace("firstName={0}, lastName={1}, homePhone={2}, mobilePhone={3}, emailAddress={4}",
                               firstName, lastName, homePhone, mobilePhone, emailAddress);

            List <Contact> contacts = base.GetContactsByName(firstName, lastName);
            Contact        match    = mc.MatchToExistingContact(contacts, mobilePhone, homePhone, emailAddress);

            membership.Member.ContactId = match.ContactId; // need this, otherwise the update fails!
            membership.Member.MatchCode = match.MatchCode; // set the match code

            this._tracer.Trace("MatchCode={0}", membership.Member.MatchCode);

            // create or update contact
            membership.Member.ContactId = base.CreateOrUpdateContact(membership.Member, false);
            return(membership.Member);
        }
예제 #2
0
        public void ProcessDonation(Donation donation)
        {
            this._tracer.Trace("Method: DonationController.ProcessDonation");

            Guid            contactId     = default(Guid);
            Guid            pledgeId      = default(Guid);
            Guid            campaignTagId = default(Guid);
            Guid            regionTagId   = default(Guid);
            Guid            transactionId = default(Guid);
            Guid            donationId    = default(Guid);
            Guid            paymentItemId = default(Guid);
            MatchController matcher       = new MatchController(this._tracer);

            // step 1: find a matching contact. create or update the contact based on the match
            contactId = MatchContact(donation, contactId, matcher);

            // get the campaign tag id of the related campaign (if any). we need to link this to both the pledge and donation
            campaignTagId = FindCampaign(donation, campaignTagId);

            // a region code will be passed from the website so we can set the coastguard unit
            regionTagId = FindRegion(donation, regionTagId);

            // step 2: match to a pledge. for one-off, match by contact, amount, is regular gift = no. for recurring, match by payment method, dps billing id, is regular gift = yes
            pledgeId = MatchPledge(donation, contactId, pledgeId, campaignTagId, regionTagId, matcher);

            // step 4: match to a payment batch. If we can't find one, we need to create a new batch
            Guid batchId = MatchPaymentBatch(donation, matcher);

            // handle rollbacks from this point forward. E.g. if a Donation fails to create, delete the related Payment Transaction
            Dictionary <Guid, string> recordsToDelete = new Dictionary <Guid, string>();

            try
            {
                // step 5: create a payment transaction - this is only for one-off payments
                if (!donation.IsRegularGift)
                {
                    transactionId = this.CreatePaymentTransaction(batchId, contactId, donation);
                    recordsToDelete.Add(transactionId, "mag_paymenttransaction");

                    // step 6: create a donation and link to the contact and pledge
                    donationId = this.CreateDonation(donation, contactId, pledgeId, regionTagId, campaignTagId);
                    recordsToDelete.Add(donationId, "mag_donation");

                    // step 7: create a payment item and link it to the donation and payment transaction
                    paymentItemId = this.CreatePaymentItem(transactionId, donationId, donation.Amount);
                    recordsToDelete.Add(paymentItemId, "mag_paymentitem");

                    // change the status reason of the Pledge to "Fulfilled"
                    this.SetPledgeStatus(pledgeId, 0, (int)PledgeStatusCode.Fulfilled);
                }
            }
            catch (Exception ex)
            {
                this._tracer.Trace(ex.ToString());
                Rollback(recordsToDelete);
                recordsToDelete.Clear();
                throw ex;
            }
        }
예제 #3
0
        private Guid MatchPaymentBatch(Donation donation, MatchController matcher)
        {
            List <Batch> paymentBatches = this.GetPaymentBatches(donation);
            Batch        batch          = matcher.MatchToExistingBatch(paymentBatches);

            Guid batchId = this.CreateOrRetrieveBatch(batch, donation);

            return(batchId);
        }
예제 #4
0
        private Guid MatchContact(Donation donation, Guid contactId, MatchController matcher)
        {
            List <Contact> contacts     = base.GetContactsByName(donation.Donor.FirstName, donation.Donor.LastName);
            Contact        contactMatch = matcher.MatchToExistingContact(contacts, donation.Donor.MobilePhone, donation.Donor.HomePhone, donation.Donor.EmailAddress);

            // copy the values from the matched contact
            donation.Donor.ContactId = contactMatch.ContactId;
            donation.Donor.MatchCode = contactMatch.MatchCode;
            donation.Donor.IsDonor   = true;

            contactId = base.CreateOrUpdateContact(donation.Donor, true);
            return(contactId);
        }
예제 #5
0
        /// <summary>
        /// Creates a new Membership in CRM. Matches against existing Contacts in CRM. If no Contact is found, a new one is created and is linked to the new Membership
        /// </summary>
        public void ProcessCreate(Membership membership)
        {
            this._tracer.Trace("Method: MembershipController.ProcessCreate");

            MatchController mc = new MatchController(this._tracer);

            // step 1: find a matching contact in CRM
            membership.Member = MatchContact(membership, mc);

            // step 2: coastguard code will be passed in representing the unit. We need to get the actual Coastguard Unit GUID from CRM
            Guid coastguardUnitCodeId = membership.UnitCodeId;
            Guid unitId = this.GetUnitId(coastguardUnitCodeId);

            // step 2: create a new membership in CRM
            this.CreateMembership(membership, unitId);
        }
예제 #6
0
        private Guid MatchPledge(Donation donation, Guid contactId, Guid pledgeId, Guid campaignTagId, Guid regionTagId, MatchController matcher)
        {
            if (contactId != default(Guid))
            {
                Pledge   pledge  = null;
                DateTime endDate = DateTime.Now;    // by default, set the end date to today. We'll use this for one-off billing
                PaymentRepeatOptionCode repeatOption = PaymentRepeatOptionCode.SetExpiryDate;

                this._tracer.Trace("donation.IsRegularGift={0}", donation.IsRegularGift);

                if (donation.IsRegularGift)
                {
                    List <Pledge> pledges = this.GetPledgesByBillingId(donation.Pledge.PledgeId);
                    pledge = matcher.MatchToExistingPledge(pledges, donation.Pledge.PledgeId);
                    if (donation.Pledge.EndDate.HasValue)
                    {
                        endDate = donation.Pledge.EndDate.Value;
                        this._tracer.Trace("donation.Pledge.EndDate={0}", donation.Pledge.EndDate.Value);
                    }
                    else
                    {
                        this._tracer.Trace("No end date. Payment Repeat Option=Until Further Notice");
                        repeatOption = PaymentRepeatOptionCode.UntilFurtherNotice;  // no end date
                    }
                }
                else
                {
                    List <Pledge> pledges = this.GetPledgesByContactAmount(contactId, donation.Amount);
                    pledge = matcher.MatchToExistingPledge(pledges, contactId, donation.Amount);
                }

                // step 3: create or link to an existing pledge
                pledgeId = this.CreateOrRetrievePledge(pledge, donation, contactId, regionTagId, campaignTagId, repeatOption);
            }
            return(pledgeId);
        }