예제 #1
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);
        }
예제 #2
0
        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));
        }
예제 #3
0
        private Guid CreateOrRetrievePledge(Pledge pledgeMatch, Donation donation, Guid contactId, Guid regionTagId, Guid campaignTagId, PaymentRepeatOptionCode repeatOption)
        {
            this._tracer.Trace("Method: DonationController.CreateOrRetrievePledge");
            this._tracer.Trace("Parameters: pledgeMatch, donation, contactId={0}, regionTagId={1}, campaignTagId={2}, repeatOption={3}", contactId, regionTagId, campaignTagId, repeatOption);

            Guid            pledgeId = pledgeMatch.PledgeId;
            PledgeMatchCode code     = pledgeMatch.MatchCode;

            if (code == PledgeMatchCode.None)
            {
                this._tracer.Trace("MatchCode=None. Creating a new Pledge");

                // create a new pledge
                pledgeId = this.CreatePledge(donation, contactId, regionTagId, campaignTagId, repeatOption);
            }

            return(pledgeId);
        }