Ejemplo n.º 1
0
        public void GetContactByParticipantId()
        {
            const int participantId = 99999;
            var expectedContact = new MyContact
            {
                Contact_ID = 11111,
                Email_Address = "*****@*****.**",
                Last_Name = "Dalton",
                First_Name = "Andy"
            };

            var mockContactDictionary = new List<Dictionary<string, object>>
            {
                new Dictionary<string, object>
                {
                    {"Contact_ID", expectedContact.Contact_ID},
                    {"Email_Address", expectedContact.Email_Address},
                    {"First_Name", expectedContact.First_Name},
                    {"Last_Name", expectedContact.Last_Name}
                }
            };
            var searchString = participantId+",";
            _ministryPlatformService.Setup(m => m.GetPageViewRecords("ContactByParticipantId", It.IsAny<string>(), searchString, "", 0)).Returns(mockContactDictionary);

            var returnedContact =_fixture.GetContactByParticipantId(participantId);

            _ministryPlatformService.VerifyAll();

            Assert.AreEqual(expectedContact.Contact_ID, returnedContact.Contact_ID);
            Assert.AreEqual(expectedContact.Email_Address, returnedContact.Email_Address);
            Assert.AreEqual(expectedContact.First_Name, returnedContact.First_Name);
            Assert.AreEqual(expectedContact.Last_Name, returnedContact.Last_Name);
        }
Ejemplo n.º 2
0
        public void SetUp()
        {
            _contactAttributeService = new Mock<IContactAttributeService>();
            var contactAllAttributesDto = new ContactAllAttributesDTO();
            _contactAttributeService.Setup(mocked => mocked.GetContactAttributes(It.IsAny<string>(), It.IsAny<int>())).Returns(contactAllAttributesDto);
            _contactService = new Mock<MPInterfaces.IContactService>();
            _authenticationService = new Mock<MPInterfaces.IAuthenticationService>();
            _participantService = new Mock<MPInterfaces.IParticipantService>();

            _apiUserService = new Mock<MPInterfaces.IApiUserService>();
            _apiUserService.Setup(m => m.GetToken()).Returns("something");

            _authenticationService.Setup(mocked => mocked.GetContactId(It.IsAny<string>())).Returns(123456);
            _myContact = new MyContact
            {
                Contact_ID = 123456,
                Email_Address = "*****@*****.**",
                Last_Name = "last-name",
                Nickname = "nickname",
                First_Name = "first-name",
                Middle_Name = "middle-name",
                Maiden_Name = "maiden-name",
                Mobile_Phone = "mobile-phone",
                Mobile_Carrier = 999,
                Date_Of_Birth = "date-of-birth",
                Marital_Status_ID = 5,
                Gender_ID = 2,
                Employer_Name = "employer-name",
                Address_Line_1 = "address-line-1",
                Address_Line_2 = "address-line-2",
                City = "city",
                State = "state",
                Postal_Code = "postal-code",
                Foreign_Country = "foreign-country",
                Home_Phone = "home-phone",
                Congregation_ID = 8,
                Household_ID = 7,
                Household_Name = "hh name",
                Address_ID = 6,
                Attendance_Start_Date = startDate
            };
            _householdMembers = new List<HouseholdMember>();

            _fixture = new PersonService(_contactService.Object, _contactAttributeService.Object, _apiUserService.Object, _participantService.Object);

            //force AutoMapper to register
            AutoMapperConfig.RegisterMappings();
        }
Ejemplo n.º 3
0
        public void TestCreateRecurringGiftWholeLottaFailures()
        {
            var recurringGiftDto = new RecurringGiftDto
            {
                StripeTokenId = "tok_123",
                PlanAmount = 123.45M,
                PlanInterval = PlanInterval.Weekly,
                Program = "987",
                StartDate = DateTime.Parse("1973-10-15")
            };

            var contactDonor = new ContactDonor
            {
                DonorId = 678,
                ProcessorId = "cus_123",
                ContactId = 909090
            };

            var defaultSource = new SourceData
            {
                id = "card_123",
                brand = "Visa",
                last4 = "5150"
            };

            var stripeCustomer = new StripeCustomer
            {
                brand = "visa",
                last4 = "9876",
                id = "cus_123",
                default_source = "card_123",
                sources = new Sources
                {
                    data = new List<SourceData>
                    {
                        new SourceData
                        {
                            id = "bank_123",
                            bank_last4 = "5678"
                        },
                        defaultSource
                    }
                }
            };

            var stripePlan = new StripePlan
            {
                Id = "plan_123"
            };

            const int donorAccountId = 999;

            var stripeSubscription = new StripeSubscription
            {
                Id = "sub_123"
            };

            var contact = new MyContact()
            {
                Congregation_ID = 1
            };

            _paymentService.Setup(mocked => mocked.CreateCustomer(recurringGiftDto.StripeTokenId, "678, Recurring Gift Subscription")).Returns(stripeCustomer);
            _paymentService.Setup(mocked => mocked.CreatePlan(recurringGiftDto, contactDonor)).Returns(stripePlan);
            _mpDonorService.Setup(
                mocked =>
                    mocked.CreateDonorAccount(defaultSource.brand,
                                              It.IsAny<string>(),
                                              defaultSource.last4,
                                              null,
                                              contactDonor.DonorId,
                                              defaultSource.id,
                                              stripeCustomer.id)).Returns(donorAccountId);
            _paymentService.Setup(mocked => mocked.CreateSubscription(stripePlan.Id, stripeCustomer.id, recurringGiftDto.StartDate)).Returns(stripeSubscription);
            _mpContactService.Setup(mocked => mocked.GetContactById(contactDonor.ContactId)).Returns(contact);
            var exception = new ApplicationException("Do it to it Lars");
            _mpDonorService.Setup(
                mocked =>
                    mocked.CreateRecurringGiftRecord("auth",
                                                     contactDonor.DonorId,
                                                     donorAccountId,
                                                     EnumMemberSerializationUtils.ToEnumString(recurringGiftDto.PlanInterval),
                                                     recurringGiftDto.PlanAmount,
                                                     recurringGiftDto.StartDate,
                                                     recurringGiftDto.Program,
                                                     stripeSubscription.Id,
                                                     contact.Congregation_ID.Value)).Throws(exception);

            _paymentService.Setup(mocked => mocked.CancelSubscription(stripeCustomer.id, stripeSubscription.Id)).Throws(new Exception());
            _paymentService.Setup(mocked => mocked.CancelPlan(stripePlan.Id)).Throws(new Exception());
            _paymentService.Setup(mocked => mocked.DeleteCustomer(stripeCustomer.id)).Throws(new Exception());
            _mpDonorService.Setup(mocked => mocked.DeleteDonorAccount("auth", donorAccountId)).Throws(new Exception());

            try
            {
                _fixture.CreateRecurringGift("auth", recurringGiftDto, contactDonor);
                Assert.Fail("Expected exception was not thrown");
            }
            catch (ApplicationException e)
            {
                Assert.AreSame(exception, e);
            }
            _paymentService.VerifyAll();
            _mpDonorService.VerifyAll();
            _mpContactService.VerifyAll();
        }
Ejemplo n.º 4
0
        public void TestCreateRecurringGift()
        {
            var recurringGiftDto = new RecurringGiftDto
            {
                StripeTokenId = "tok_123",
                PlanAmount = 123.45M,
                PlanInterval = PlanInterval.Weekly,
                Program = "987",
                StartDate = DateTime.Parse("1973-10-15")
            };

            var contactDonor = new ContactDonor
            {
                DonorId = 678,
                ProcessorId = "cus_123",
                ContactId = 909090
            };

            var defaultSource = new SourceData
            {
                id = "card_123",
                brand = "Visa",
                last4 = "5150"
            };

            var stripeCustomer = new StripeCustomer
            {
                brand = "visa",
                last4 = "9876",
                id = "cus_123",
                default_source = "card_123",
                sources = new Sources
                {
                    data = new List<SourceData>
                    {
                        new SourceData
                        {
                            id = "bank_123",
                            bank_last4 = "5678"
                        },
                        defaultSource
                    }
                }
            };

            var stripePlan = new StripePlan
            {
                Id = "plan_123"
            };

            const int donorAccountId = 999;

            var stripeSubscription = new StripeSubscription
            {
                Id = "sub_123"
            };

            var contact = new MyContact()
            {
                Congregation_ID = 1
            };
            const int recurringGiftId = 888;

            var recurringGift = new CreateDonationDistDto
            {
                ProgramName = "Crossroads",
                Amount = 123.45M,
                Recurrence = "12th of the month",
                DonorAccountId = 90
            };

            _paymentService.Setup(mocked => mocked.CreateCustomer(recurringGiftDto.StripeTokenId, "678, Recurring Gift Subscription")).Returns(stripeCustomer);
            _paymentService.Setup(mocked => mocked.CreatePlan(recurringGiftDto, contactDonor)).Returns(stripePlan);
            _mpDonorService.Setup(
                mocked =>
                    mocked.CreateDonorAccount(defaultSource.brand,
                                              It.IsAny<string>(),
                                              defaultSource.last4,
                                              null,
                                              contactDonor.DonorId,
                                              defaultSource.id,
                                              stripeCustomer.id)).Returns(donorAccountId);
            _paymentService.Setup(mocked => mocked.CreateSubscription(stripePlan.Id, stripeCustomer.id, recurringGiftDto.StartDate)).Returns(stripeSubscription);
            _mpContactService.Setup(mocked => mocked.GetContactById(contactDonor.ContactId)).Returns(contact);
            _mpDonorService.Setup(
                mocked =>
                    mocked.CreateRecurringGiftRecord("auth", contactDonor.DonorId,
                                                     donorAccountId,
                                                     EnumMemberSerializationUtils.ToEnumString(recurringGiftDto.PlanInterval),
                                                     recurringGiftDto.PlanAmount,
                                                     recurringGiftDto.StartDate,
                                                     recurringGiftDto.Program,
                                                     stripeSubscription.Id, contact.Congregation_ID.Value)).Returns(recurringGiftId);

            _mpDonorService.Setup(mocked => mocked.GetRecurringGiftById("auth", recurringGiftId)).Returns(recurringGift);
            _mpDonorService.Setup(mocked => mocked.GetDonorAccountPymtType(recurringGift.DonorAccountId.Value)).Returns(1);
            _mpDonorService.Setup(
                mocked =>
                    mocked.SendEmail(RecurringGiftSetupEmailTemplateId, recurringGift.DonorId, (int)(123.45M/100), "Check", It.IsAny<DateTime>(), "Crossroads", string.Empty, "12th of the month"));

            var response = _fixture.CreateRecurringGift("auth", recurringGiftDto, contactDonor);
            _paymentService.VerifyAll();
            _mpDonorService.VerifyAll();
            Assert.AreEqual(recurringGiftId, response);
        }
Ejemplo n.º 5
0
        public void SendTwoRsvpEmails()
        {
            const int daysBefore = 999;
            const int emailTemplateId = 77;
            const int unassignedContact = 7386594;
            var participants = new List<EventParticipant>
            {
                new EventParticipant
                {
                    ParticipantId = 1,
                    EventId = 123,
                    ContactId = 987654
                },
                new EventParticipant
                {
                    ParticipantId = 2,
                    EventId = 456,
                    ContactId = 456123
                }
            };

            var mockPrimaryContact = new Contact
            {
                ContactId = 98765,
                EmailAddress = "*****@*****.**"
            };

            var defaultContact = new MyContact
            {
                Contact_ID = 123456,
                Email_Address = "*****@*****.**"
            };

            var mockEvent1 = new Event {EventType = "Childcare", PrimaryContact = mockPrimaryContact};
            var mockEvent2 = new Event {EventType = "DoggieDaycare", PrimaryContact = mockPrimaryContact};
            var mockEvents = new List<Event> {mockEvent1, mockEvent2};

            _configurationWrapper.Setup(m => m.GetConfigIntValue("NumberOfDaysBeforeEventToSend")).Returns(daysBefore);
            _configurationWrapper.Setup(m => m.GetConfigIntValue("ChildcareRequestTemplate")).Returns(emailTemplateId);
            _communicationService.Setup(m => m.GetTemplate(emailTemplateId)).Returns(new MessageTemplate());            
            _eventParticipantService.Setup(m => m.GetChildCareParticipants(daysBefore)).Returns(participants);
            _communicationService.Setup(m => m.SendMessage(It.IsAny<Communication>())).Verifiable();

            var kids = new List<Participant> { new Participant { ContactId = 456321987 } };
            _crdsEventService.Setup(m => m.EventParticpants(987654321, It.IsAny<string>())).Returns(kids);
            var mockChildcareEvent = new Event {EventId = 987654321};
            var mockContact = new Contact
            {
                ContactId = 8888888,
                EmailAddress = "*****@*****.**"
            };
            mockChildcareEvent.PrimaryContact = mockContact;
            _crdsEventService.Setup(m => m.GetChildcareEvent(participants[0].EventId)).Returns(mockChildcareEvent);
            _crdsEventService.Setup(m => m.GetChildcareEvent(participants[1].EventId)).Returns(mockChildcareEvent);
            _configurationWrapper.Setup(m => m.GetConfigIntValue("DefaultContactEmailId")).Returns(1234);
            _contactService.Setup(mocked => mocked.GetContactById(1234)).Returns(defaultContact); 
            var myKids = new List<Participant>();
            _crdsEventService.Setup(m => m.MyChildrenParticipants(987654, kids, It.IsAny<string>())).Returns(myKids);

            _fixture.SendRequestForRsvp();

            _configurationWrapper.VerifyAll();
            _communicationService.VerifyAll();
            _contactService.VerifyAll();
            _eventParticipantService.VerifyAll();
            _communicationService.VerifyAll();
            _communicationService.Verify(m => m.SendMessage(It.IsAny<Communication>()), Times.Exactly(2));
            _eventService.VerifyAll();
        }
Ejemplo n.º 6
0
        public void SetUp()
        {
            _contactRelationshipService = new Mock<IContactRelationshipService>();
            _contactService = new Mock<IContactService>();
            _opportunityService = new Mock<IOpportunityService>();
            _authenticationService = new Mock<IAuthenticationService>();
            _personService = new Mock<crds_angular.Services.Interfaces.IPersonService>();
            _eventService = new Mock<IEventService>();
            _serveService = new Mock<IServeService>();
            _participantService = new Mock<IParticipantService>();
            _groupParticipantService = new Mock<IGroupParticipantService>();
            _groupService = new Mock<IGroupService>();
            _communicationService = new Mock<ICommunicationService>();
            _configurationWrapper = new Mock<IConfigurationWrapper>();
            _apiUserService = new Mock<IApiUserService>();
            _responseService = new Mock<IResponseService>();

            fakeOpportunity.EventTypeId = 3;
            fakeOpportunity.GroupContactId = 23;
            fakeOpportunity.GroupContactName = "Harold";
            fakeOpportunity.GroupName = "Mighty Ducks";
            fakeOpportunity.OpportunityId = 12;
            fakeOpportunity.OpportunityName = "Goalie";

            fakeGroupContact.Contact_ID = 23;
            fakeGroupContact.Email_Address = "*****@*****.**";
            fakeGroupContact.Nickname = "fakeNick";
            fakeGroupContact.Last_Name = "Name";

            fakeMyContact.Contact_ID = 8;
            fakeMyContact.Email_Address = "*****@*****.**";

            _contactService.Setup(m => m.GetContactById(1)).Returns(fakeGroupContact);
            _contactService.Setup(m => m.GetContactById(fakeOpportunity.GroupContactId)).Returns(fakeGroupContact);
            _contactService.Setup(m => m.GetContactById(8)).Returns(fakeMyContact);

            _communicationService.Setup(m => m.GetTemplate(rsvpYesId)).Returns(mockRsvpYesTemplate);
            _communicationService.Setup(m => m.GetTemplate(rsvpNoId)).Returns(mockRsvpNoTemplate);
            _communicationService.Setup(m => m.GetTemplate(rsvpChangeId)).Returns(mockRsvpChangedTemplate);


            _authenticationService.Setup(mocked => mocked.GetContactId(It.IsAny<string>())).Returns(123456);
            var myContact = new MyContact
            {
                Contact_ID = 123456,
                Email_Address = "*****@*****.**",
                Last_Name = "last-name",
                Nickname = "nickname",
                First_Name = "first-name",
                Middle_Name = "middle-name",
                Maiden_Name = "maiden-name",
                Mobile_Phone = "mobile-phone",
                Mobile_Carrier = 999,
                Date_Of_Birth = "date-of-birth",
                Marital_Status_ID = 5,
                Gender_ID = 2,
                Employer_Name = "employer-name",
                Address_Line_1 = "address-line-1",
                Address_Line_2 = "address-line-2",
                City = "city",
                State = "state",
                Postal_Code = "postal-code",                
                Foreign_Country = "foreign-country",
                Home_Phone = "home-phone",
                Congregation_ID = 8,
                Household_ID = 7,
                Address_ID = 6
            };
            _contactService.Setup(mocked => mocked.GetMyProfile(It.IsAny<string>())).Returns(myContact);

            var person = new Person();
            person.ContactId = myContact.Contact_ID;
            person.EmailAddress = myContact.Email_Address;
            person.LastName = myContact.Last_Name;
            person.NickName = myContact.Nickname;

            _personService.Setup(m => m.GetLoggedInUserProfile(It.IsAny<string>())).Returns(person);

            _fixture = new ServeService(_contactService.Object, _contactRelationshipService.Object,
                _opportunityService.Object, _eventService.Object,
                _participantService.Object, _groupParticipantService.Object, _groupService.Object,
                _communicationService.Object, _authenticationService.Object, _configurationWrapper.Object, _apiUserService.Object, _responseService.Object);

            //force AutoMapper to register
            AutoMapperConfig.RegisterMappings();
        }
Ejemplo n.º 7
0
        private int CreateContact(MyContact contact)
        {
            var contactDictionary = new Dictionary<string, object>
            {
                {"Company", false},
                {"Last_Name", contact.Last_Name},
                {"First_Name", contact.First_Name},
                {"Display_Name", contact.Last_Name + ", " + contact.First_Name},
                {"Nickname", contact.First_Name},
                {"ID_Card", contact.ID_Number}
            };

            if (contact.Household_ID > 0)
            {
                contactDictionary.Add("HouseHold_ID", contact.Household_ID);
                contactDictionary.Add("Household_Position_ID", _householdPositionDefaultId);
            }

            try
            {
                return (_ministryPlatformService.CreateRecord(_contactsPageId, contactDictionary, ApiLogin()));
            }
            catch (Exception e)
            {
                var msg = string.Format("Error creating Sponsered Child Contact, firstName: {0} lastName: {1} idCard: {2}",
                                        contact.First_Name,
                                        contact.Last_Name,
                                        contact.ID_Number);
                _logger.Error(msg, e);
                throw (new ApplicationException(msg, e));
            }
        }
Ejemplo n.º 8
0
        private static MyContact ParseProfileRecord(Dictionary<string, object> recordsDict)
        {
            var contact = new MyContact
            {
                Address_ID = recordsDict.ToNullableInt("Address_ID"),
                Address_Line_1 = recordsDict.ToString("Address_Line_1"),
                Address_Line_2 = recordsDict.ToString("Address_Line_2"),
                Congregation_ID = recordsDict.ToNullableInt("Congregation_ID"),
                Household_ID = recordsDict.ToInt("Household_ID"),
                Household_Name = recordsDict.ToString("Household_Name"),
                City = recordsDict.ToString("City"),
                State = recordsDict.ToString("State"),
                County = recordsDict.ToString("County"),
                Postal_Code = recordsDict.ToString("Postal_Code"),                
                Contact_ID = recordsDict.ToInt("Contact_ID"),
                Date_Of_Birth = recordsDict.ToDateAsString("Date_of_Birth"),
                Email_Address = recordsDict.ToString("Email_Address"),
                Employer_Name = recordsDict.ToString("Employer_Name"),
                First_Name = recordsDict.ToString("First_Name"),
                Foreign_Country = recordsDict.ToString("Foreign_Country"),
                Gender_ID = recordsDict.ToNullableInt("Gender_ID"),
                Home_Phone = recordsDict.ToString("Home_Phone"),
                Last_Name = recordsDict.ToString("Last_Name"),
                Maiden_Name = recordsDict.ToString("Maiden_Name"),
                Marital_Status_ID = recordsDict.ToNullableInt("Marital_Status_ID"),
                Middle_Name = recordsDict.ToString("Middle_Name"),
                Mobile_Carrier = recordsDict.ToNullableInt("Mobile_Carrier_ID"),
                Mobile_Phone = recordsDict.ToString("Mobile_Phone"),
                Nickname = recordsDict.ToString("Nickname"),
                Age = recordsDict.ToInt("Age"),
                Passport_Number = recordsDict.ToString("Passport_Number"),
                Passport_Country = recordsDict.ToString("Passport_Country"),
                Passport_Expiration = ParseExpirationDate(recordsDict.ToNullableDate("Passport_Expiration")),
                Passport_Firstname = recordsDict.ToString("Passport_Firstname"),
                Passport_Lastname = recordsDict.ToString("Passport_Lastname"),
                Passport_Middlename = recordsDict.ToString("Passport_Middlename")                
            };
            if (recordsDict.ContainsKey("Participant_Start_Date"))
            {
                contact.Participant_Start_Date = recordsDict.ToDate("Participant_Start_Date");
            }
            if (recordsDict.ContainsKey("Attendance_Start_Date"))
            {
                contact.Attendance_Start_Date = recordsDict.ToNullableDate("Attendance_Start_Date");
            }

            if (recordsDict.ContainsKey("ID_Card"))
            {
                contact.ID_Number = recordsDict.ToString("ID_Card");
            }
            return contact;
        }
Ejemplo n.º 9
0
        private Dictionary<string, object> HandleNoRsvp(Participant participant,
                                                        Event e,
                                                        List<int> opportunityIds,
                                                        string token,
                                                        MyContact groupLeader)
        {
            int templateId;
            Opportunity previousOpportunity = null;

            try
            {
                templateId = AppSetting("RsvpNoTemplate");
                //opportunityId = opportunityIds.First();
                _eventService.UnregisterParticipantForEvent(participant.ParticipantId, e.EventId);
            }
            catch (ApplicationException ex)
            {
                logger.Debug(ex.Message + ": There is no need to remove the event participant because there is not one.");
                templateId = AppSetting("RsvpNoTemplate");
            }

            // Responding no means that we are saying no to all opportunities for this group for this event            
            foreach (var oid in opportunityIds)
            {
                var comments = string.Empty; //anything of value to put in comments?
                var updatedOpp = _opportunityService.RespondToOpportunity(participant.ParticipantId,
                                                                          oid,
                                                                          comments,
                                                                          e.EventId,
                                                                          false);
                if (updatedOpp > 0)
                {
                    previousOpportunity = _opportunityService.GetOpportunityById(oid, token);
                }
            }

            if (previousOpportunity != null)
            {
                var emailName = participant.DisplayName;
                var emailEmail = participant.EmailAddress;
                var emailTeamName = previousOpportunity.GroupName;
                var emailOpportunityName = previousOpportunity.OpportunityName;
                var emailEventDateTime = e.EventStartDate.ToString();

                SendCancellationMessage(groupLeader, emailName, emailEmail, emailTeamName, emailOpportunityName, emailEventDateTime);
            }

            return new Dictionary<string, object>()
            {
                {"templateId", templateId},
                {"previousOpportunity", previousOpportunity},
                {"rsvp", false}
            };
        }
Ejemplo n.º 10
0
 private Dictionary<string, object> CreateRsvp(string token,
                                               int opportunityId,
                                               List<int> opportunityIds,
                                               bool signUp,
                                               Participant participant,
                                               Event @event,
                                               MyContact groupLeader)
 {
     var response = signUp
         ? HandleYesRsvp(participant, @event, opportunityId, opportunityIds, token)
         : HandleNoRsvp(participant, @event, opportunityIds, token, groupLeader);
     return response;
 }
Ejemplo n.º 11
0
        public void TestGetContactDonorForCheckAccount()
        {
            const int contactId = 765567;
            const int donorId = 681806;
            const string displayName = "Victoria Secret";
            const string addr1 = "25 First St";
            const string addr2 = "Suite 101";
            const string city = "San Francisco";
            const string state = "CA";
            const string zip = "91010";
            const string encryptedKey = "pink$010101@knip";
            const string donorLookupByEncryptedAccount = "DonorLookupByEncryptedAccount";

            var donorContact = new List<Dictionary<string, object>>
            {
                new Dictionary<string, object>
                {
                    { "Contact_ID", contactId },
                    {"Display_Name", displayName},
                    {"Donor_ID", donorId}
                }
            };

            _ministryPlatformService.Setup(mocked => mocked.GetPageViewRecords("," + donorLookupByEncryptedAccount, It.IsAny<string>(), encryptedKey, "", 0)).Returns(donorContact);

            var myContact = new MyContact
            {
                Address_Line_1 = addr1,
                Address_Line_2 = addr2,
                City = city,
                State = state,
                Postal_Code = zip
            };

            var contactDonor = new ContactDonor
            {
                DonorId = donorId,
                Details = new ContactDetails
                {
                    DisplayName = displayName,
                    Address = new PostalAddress()
                    {
                        Line1 = addr1,
                        Line2 = addr2,
                        City = city,
                        State = state,
                        PostalCode = zip
                    }
                }
            };

            _ministryPlatformService.Setup(mocked => mocked.GetPageViewRecords(
              2179, It.IsAny<string>(), "," + encryptedKey, "", 0)).Returns(donorContact);

            _contactService.Setup(mocked => mocked.GetContactById(
              contactId)).Returns(myContact);

            var result = _fixture.GetContactDonorForCheckAccount(encryptedKey);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Details.DisplayName, contactDonor.Details.DisplayName);
            Assert.AreEqual(result.Details.Address.Line1, contactDonor.Details.Address.Line1);
            Assert.AreEqual(result.Details.Address.Line2, contactDonor.Details.Address.Line2);
            Assert.AreEqual(result.Details.Address.City, contactDonor.Details.Address.City);
            Assert.AreEqual(result.Details.Address.State, contactDonor.Details.Address.State);
            Assert.AreEqual(result.Details.Address.PostalCode, contactDonor.Details.Address.PostalCode);
        }
Ejemplo n.º 12
0
        public void TestSendEmailNoFrequency()
        {
            const string program = "Crossroads";
            const int declineEmailTemplate = 11940;
            var donationDate = DateTime.Now;
            const string emailReason = "rejected: lack of funds";
            const int donorId = 9876;
            const int donationAmt = 4343;
            const string paymentType = "Bank";

            var defaultContact = new MyContact()
            {
                Contact_ID = 1234556,
                Email_Address = "*****@*****.**"
            };

            var getTemplateResponse = new MessageTemplate()
            {
                Body = "Your payment was rejected.  Darn.",
                Subject = "Test Decline Email"
            };

            const string emailAddress = "*****@*****.**";
            const int contactId = 3;
            var contactList = new List<Dictionary<string, object>>
            {
                new Dictionary<string, object>
                {
                    {"Donor_ID", 1},
                    {"Processor_ID", 2},
                    {"Contact_ID", contactId},
                    {"Email", emailAddress},
                    {"Statement_Type", "Family"},
                    {"Statement_Type_ID", 2},
                    {"Statement_Frequency", "Quarterly"},
                    {"Statement_Method", "Online"},
                    {"Household_ID", 4},
                }
            };

            _ministryPlatformService.Setup(mocked => mocked.GetPageViewRecords("DonorByContactId", It.IsAny<string>(), It.IsAny<string>(), string.Empty, 0)).Returns(contactList);
            var expectedCommunication = new Communication
            {
                AuthorUserId = 5,
                DomainId = 1,
                EmailBody = getTemplateResponse.Body,
                EmailSubject = getTemplateResponse.Subject,
                FromContact = new Contact {ContactId = 5, EmailAddress = "*****@*****.**"},
                ReplyToContact = new Contact {ContactId = 5, EmailAddress = "*****@*****.**" },
                ToContacts = new List<Contact> {new Contact{ContactId = contactId, EmailAddress = emailAddress}},
                MergeData = new Dictionary<string, object>
                {
                    {"Program_Name", program},
                    {"Donation_Amount", donationAmt.ToString("N2")},
                    {"Donation_Date", donationDate.ToString("MM/dd/yyyy h:mmtt", new DateTimeFormatInfo
                    {
                        AMDesignator = "am",
                        PMDesignator = "pm"
                    })},
                    {"Payment_Method", paymentType},
                    {"Decline_Reason", emailReason},
                }
            };
            _contactService.Setup(mocked => mocked.GetContactById(Convert.ToInt32(ConfigurationManager.AppSettings["DefaultGivingContactEmailId"]))).Returns(defaultContact);
            _communicationService.Setup(mocked => mocked.GetTemplate(declineEmailTemplate)).Returns(getTemplateResponse);
            _communicationService.Setup(
                mocked =>
                    mocked.SendMessage(
                        It.Is<Communication>(
                            c =>
                                c.EmailBody.Equals(expectedCommunication.EmailBody) && c.EmailSubject.Equals(expectedCommunication.EmailSubject) &&
                                c.ToContacts[0].ContactId == expectedCommunication.ToContacts[0].ContactId && c.ToContacts[0].EmailAddress.Equals(expectedCommunication.ToContacts[0].EmailAddress) &&
                                c.MergeData["Program_Name"].Equals(expectedCommunication.MergeData["Program_Name"]) &&
                                c.MergeData["Donation_Amount"].Equals(expectedCommunication.MergeData["Donation_Amount"]) &&
                                c.MergeData["Donation_Date"].Equals(expectedCommunication.MergeData["Donation_Date"]) &&
                                c.MergeData["Payment_Method"].Equals(expectedCommunication.MergeData["Payment_Method"]) &&
                                c.MergeData["Decline_Reason"].Equals(expectedCommunication.MergeData["Decline_Reason"]) &&
                                !c.MergeData.ContainsKey("Frequency")
                            )));

            _fixture.SendEmail(declineEmailTemplate, donorId, donationAmt, paymentType, donationDate, program,
                emailReason, null);

            _ministryPlatformService.VerifyAll();
            _communicationService.VerifyAll();

        }
Ejemplo n.º 13
0
        public void CreateDonationAndDistributionRecordWithPledge()
        {
            const decimal donationAmt = 676767;
            var feeAmt = 5656;
            var donorId = 1234567;
            var programId = "3";
            var pledgeId = 123;
            var setupDate = DateTime.Now;
            var chargeId = "ch_crds1234567";
            var processorId = "cus_8675309";
            var pymtType = "cc";
            var expectedDonationId = 321321;
            var expectedDonationDistributionId = 231231;
            var checkScannerBatchName = "check scanner batch";
            const string viewKey = "DonorByContactId";
            const string sortString = "";
            var searchString = ",\"" + donorId + "\"";
            var donationPageId = Convert.ToInt32(ConfigurationManager.AppSettings["Donations"]);
            var donationDistPageId = Convert.ToInt32(ConfigurationManager.AppSettings["Distributions"]);
            
            var defaultContact = new MyContact()
            {
                Contact_ID = 1234556,
                Email_Address = "*****@*****.**"
            };

            _ministryPlatformService.Setup(mocked => mocked.CreateRecord(
              donationPageId, It.IsAny<Dictionary<string, object>>(),
              It.IsAny<string>(), true)).Returns(expectedDonationId);

            _ministryPlatformService.Setup(mocked => mocked.CreateRecord(
                donationDistPageId, It.IsAny<Dictionary<string, object>>(),
                It.IsAny<string>(), true)).Returns(expectedDonationDistributionId);
            _contactService.Setup(mocked => mocked.GetContactById(Convert.ToInt32(ConfigurationManager.AppSettings["DefaultGivingContactEmailId"]))).Returns(defaultContact);
            _communicationService.Setup(mocked => mocked.SendMessage(It.IsAny<Communication>()));

            var expectedDonationValues = new Dictionary<string, object>
            {
                {"Donor_ID", donorId},
                {"Donation_Amount", donationAmt},
                {"Processor_Fee_Amount", feeAmt /Constants.StripeDecimalConversionValue},
                {"Payment_Type_ID", 4}, //hardcoded as credit card until ACH stories are worked
                {"Donation_Date", setupDate},
                {"Transaction_code", chargeId},
                {"Registered_Donor", true},
                {"Anonymous", false},
                {"Processor_ID", processorId},
                {"Donation_Status_Date", setupDate},
                {"Donation_Status_ID", 1},
                {"Recurring_Gift_ID", null},
                {"Is_Recurring_Gift", false},
                {"Donor_Account_ID", null},
                {"Check_Scanner_Batch", checkScannerBatchName}
            };

            var expectedDistributionValues = new Dictionary<string, object>
            {
                {"Donation_ID", expectedDonationId},
                {"Amount", donationAmt},
                {"Program_ID", programId},
                {"Pledge_ID", pledgeId}
               
            };

            var programServiceResponse = new Program
            {
                CommunicationTemplateId = 1234,
                ProgramId = 3,
                Name = "Crossroads"
            };

            _programService.Setup(mocked => mocked.GetProgramById(It.IsAny<int>())).Returns(programServiceResponse);

            var dictList = new List<Dictionary<string, object>>();
            dictList.Add(new Dictionary<string, object>()
            {
                {"Donor_ID", donorId},
                {"Processor_ID", "tx_123"},
                {"Email","*****@*****.**"},
                {"Contact_ID","1234"},
                {"Statement_Type", "Individual"},
                {"Statement_Type_ID", 1},
                {"Statement_Frequency", "Quarterly"},
                {"Statement_Method", "None"},
                {"Household_ID", 1}
            });


            _ministryPlatformService.Setup(mocked => mocked.GetPageViewRecords(viewKey, It.IsAny<string>(), searchString, sortString, 0)).Returns(dictList);

            var getTemplateResponse = new MessageTemplate()
            {
                Body = "Test Body Content",
                Subject = "Test Email Subject Line"
            };
            _communicationService.Setup(mocked => mocked.GetTemplate(It.IsAny<int>())).Returns(getTemplateResponse);

            var donationAndDistribution = new DonationAndDistributionRecord
            {
                DonationAmt = donationAmt,
                FeeAmt = feeAmt,
                DonorId = donorId,
                ProgramId = programId,
                ChargeId = chargeId,
                PymtType = pymtType,
                ProcessorId = processorId,
                SetupDate = setupDate,
                RegisteredDonor = true,
                CheckScannerBatchName = checkScannerBatchName,
                PledgeId = pledgeId
            };

            var response = _fixture.CreateDonationAndDistributionRecord(donationAndDistribution);

            // Explicitly verify each expectation...
            _communicationService.Verify(mocked => mocked.SendMessage(It.IsAny<Communication>()));
            _programService.Verify(mocked => mocked.GetProgramById(3));
            _ministryPlatformService.Verify(mocked => mocked.CreateRecord(donationPageId, expectedDonationValues, It.IsAny<string>(), true));
            _ministryPlatformService.Verify(mocked => mocked.CreateRecord(donationDistPageId, expectedDistributionValues, It.IsAny<string>(), true));

            // _ministryPlatformService.VerifyAll();
            _programService.VerifyAll();
            _communicationService.VerifyAll();
            Assert.IsNotNull(response);
            Assert.AreEqual(response, expectedDonationId);
        }
Ejemplo n.º 14
0
 private static Communication FormatCommunication(int authorUserId,
                                                  int domainId,
                                                  MessageTemplate template,
                                                  MyContact fromContact,
                                                  MyContact replyToContact,
                                                  int participantContactId,
                                                  string participantEmail,
                                                  Dictionary<string, object> mergeData)
 {
     var communication = new Communication
     {
         AuthorUserId = authorUserId,
         DomainId = domainId,
         EmailBody = template.Body,
         EmailSubject = template.Subject,
         FromContact = new Contact {ContactId = fromContact.Contact_ID, EmailAddress = fromContact.Email_Address},
         ReplyToContact = new Contact {ContactId = replyToContact.Contact_ID, EmailAddress = replyToContact.Email_Address},
         ToContacts = new List<Contact> {new Contact {ContactId = participantContactId, EmailAddress = participantEmail}},
         MergeData = mergeData
     };
     return communication;
 }
Ejemplo n.º 15
0
 private static MyContact ReplyToContact(Event childEvent)
 {
     var contact = childEvent.PrimaryContact;
     var replyToContact = new MyContact
     {
         Contact_ID = contact.ContactId,
         Email_Address = contact.EmailAddress
     };
     return replyToContact;
 }
Ejemplo n.º 16
0
        public void TestCreateRecurringGiftNoCongregation()
        {
            var recurringGiftDto = new RecurringGiftDto
            {
                StripeTokenId = "tok_123",
                PlanAmount = 123.45M,
                PlanInterval = PlanInterval.Weekly,
                Program = "987",
                StartDate = DateTime.Parse("1973-10-15")
            };

            var contactDonor = new ContactDonor
            {
                DonorId = 678,
                ProcessorId = "cus_123"
            };

            var stripeCustomer = new StripeCustomer
            {
                brand = "visa",
                last4 = "9876",
                id = "card_123"
            };

            var stripePlan = new StripePlan
            {
                Id = "plan_123"
            };

            const int donorAccountId = 999;

            var stripeSubscription = new StripeSubscription
            {
                Id = "sub_123"
            };

            var contact = new MyContact()
            {
                Congregation_ID = null
            };
            const int recurringGiftId = 888;

            _paymentService.Setup(mocked => mocked.AddSourceToCustomer(contactDonor.ProcessorId, recurringGiftDto.StripeTokenId)).Returns(stripeCustomer);
            _paymentService.Setup(mocked => mocked.CreatePlan(recurringGiftDto, contactDonor)).Returns(stripePlan);
            _mpDonorService.Setup(
                mocked =>
                    mocked.CreateDonorAccount(stripeCustomer.brand,
                                              It.IsAny<string>(),
                                              stripeCustomer.last4,
                                              null,
                                              contactDonor.DonorId,
                                              stripeCustomer.id,
                                              contactDonor.ProcessorId)).Returns(donorAccountId);
            _paymentService.Setup(mocked => mocked.CreateSubscription(stripePlan.Id, contactDonor.ProcessorId, recurringGiftDto.StartDate)).Returns(stripeSubscription);
            _mpContactService.Setup(mocked => mocked.GetContactById(contactDonor.DonorId)).Returns(contact);
            _mpDonorService.Setup(
                mocked =>
                    mocked.CreateRecurringGiftRecord("auth", contactDonor.DonorId,
                                                     donorAccountId,
                                                     EnumMemberSerializationUtils.ToEnumString(recurringGiftDto.PlanInterval),
                                                     recurringGiftDto.PlanAmount,
                                                     recurringGiftDto.StartDate,
                                                     recurringGiftDto.Program,
                                                     stripeSubscription.Id, NotSiteSpecificCongregation)).Returns(recurringGiftId);
            var response = _fixture.CreateRecurringGift("auth", recurringGiftDto, contactDonor);
            _paymentService.VerifyAll();
            _mpDonorService.VerifyAll();
            _mpContactService.VerifyAll();
            Assert.AreEqual(recurringGiftId, response);
        }
Ejemplo n.º 17
0
        public void TestEditRecurringGiftChangePaymentAndStartDate()
        {
            const string authUserToken = "auth";
            var today = DateTime.Today;
            const int congregationId = 1;

            var editGift = new RecurringGiftDto
            {
                RecurringGiftId = 345,
                StripeTokenId = "tok_123",
                PlanAmount = 800M,
                Program = "3",
                PlanInterval = PlanInterval.Weekly,
                StartDate = today
            };

            var donor = new ContactDonor
            {
                DonorId = 456,
                ProcessorId = "cus_123",
                Email = "*****@*****.**"
            };

            var existingGift = new CreateDonationDistDto
            {
                Amount = 50000,
                ProgramId = "3",
                Frequency = 1,
                StartDate = today.AddDays(-7),
                DonorAccountId = 234,
                SubscriptionId = "sub_123",
                DayOfWeek = (int)today.AddDays(-7).DayOfWeek,
                RecurringGiftId = 345,
                DonorId = 789,
                StripeCustomerId = "cus_456",
                StripeAccountId = "card_456"
            };

            var stripeSource = new SourceData
            {
                brand = "Visa",
                last4 = "1234",
                id = "card_123"
            };

            const int newDonorAccountId = 987;

            var oldSubscription = new StripeSubscription
            {
                Id = "sub_123",
                Plan = new StripePlan
                {
                    Id = "plan_123"
                }
            };

            var newPlan = new StripePlan
            {
                Id = "plan_456"
            };

            var newSubscription = new StripeSubscription
            {
                Id = "sub_456"
            };

            const int newRecurringGiftId = 765;

            var newRecurringGift = new CreateDonationDistDto
            {
                Amount = 80000,
                ProgramId = "3",
                Frequency = 1,
                StartDate = today,
                DonorAccountId = 234,
                SubscriptionId = "sub_456",
                DayOfWeek = (int)today.DayOfWeek,
                RecurringGiftId = newRecurringGiftId,
                DonorId = 789
            };

            var contact = new MyContact()
            {
                Congregation_ID = congregationId
            };

            _mpDonorService.Setup(mocked => mocked.GetRecurringGiftById(authUserToken, editGift.RecurringGiftId)).Returns(existingGift);
            _paymentService.Setup(mocked => mocked.UpdateCustomerSource(existingGift.StripeCustomerId, editGift.StripeTokenId)).Returns(stripeSource);
            _mpDonorService.Setup(mocked => mocked.CreateDonorAccount(stripeSource.brand, "0", stripeSource.last4, null, existingGift.DonorId, stripeSource.id, existingGift.StripeCustomerId)).Returns(newDonorAccountId);
            _paymentService.Setup(mocked => mocked.CancelSubscription(existingGift.StripeCustomerId, existingGift.SubscriptionId)).Returns(oldSubscription);
            _paymentService.Setup(mocked => mocked.CreateSubscription(newPlan.Id, existingGift.StripeCustomerId, newRecurringGift.StartDate.Value)).Returns(newSubscription);
            _paymentService.Setup(mocked => mocked.CancelPlan(oldSubscription.Plan.Id)).Returns(oldSubscription.Plan);
            _paymentService.Setup(mocked => mocked.CreatePlan(editGift, donor)).Returns(newPlan);
            _mpDonorService.Setup(mocked => mocked.CancelRecurringGift(authUserToken, existingGift.RecurringGiftId.Value));
            _mpContactService.Setup(mocked => mocked.GetContactById(donor.ContactId)).Returns(contact);
            _mpDonorService.Setup(
                mocked =>
                    mocked.CreateRecurringGiftRecord(authUserToken,
                                                     donor.DonorId,
                                                     newDonorAccountId,
                                                     EnumMemberSerializationUtils.ToEnumString(editGift.PlanInterval),
                                                     editGift.PlanAmount,
                                                     editGift.StartDate,
                                                     editGift.Program,
                                                     newSubscription.Id, contact.Congregation_ID.Value)).Returns(newRecurringGiftId);
            _mpDonorService.Setup(mocked => mocked.GetRecurringGiftById(authUserToken, newRecurringGiftId)).Returns(newRecurringGift);

            var result = _fixture.EditRecurringGift(authUserToken, editGift, donor);
            _mpDonorService.VerifyAll();
            _paymentService.VerifyAll();

            Assert.IsNotNull(result);
            Assert.AreEqual(newRecurringGift.RecurringGiftId, result.RecurringGiftId);
            Assert.AreEqual(newRecurringGift.StartDate, result.StartDate);
            Assert.AreEqual(newRecurringGift.Amount, result.PlanAmount);
            Assert.AreEqual(PlanInterval.Weekly, result.PlanInterval);
            Assert.AreEqual(newRecurringGift.ProgramId, result.Program);
            Assert.AreEqual(newRecurringGift.DonorId, result.DonorID);
            Assert.AreEqual(donor.Email, result.EmailAddress);
            Assert.AreEqual(newSubscription.Id, result.SubscriptionID);
        }
Ejemplo n.º 18
0
        private void SendCancellationMessage(MyContact groupLeader, string volunteerName, string volunteerEmail, string teamName, string opportunityName, string eventDateTime)
        {
            var templateId = AppSetting("RsvpYesToNo");

            var mergeData = new Dictionary<string, object>
            {
                {"VolunteerName", volunteerName},
                {"VolunteerEmail", volunteerEmail},
                {"TeamName", teamName},
                {"OpportunityName", opportunityName},
                {"EventDateTime", eventDateTime}
            };

            var communication = SetupCommunication(templateId, groupLeader, groupLeader, mergeData);

            _communicationService.SendMessage(communication);
        }
Ejemplo n.º 19
0
        public int CreateContactForSponsoredChild(string firstName, string lastName, string town, string idCard)
        {
            var householdId = CreateAddressHouseholdForSponsoredChild(town, lastName);

            var contact = new MyContact
            {
                First_Name = firstName,
                Last_Name = lastName,
                ID_Number = idCard,
                Household_ID = householdId
            };
            
            return CreateContact(contact);
        }
Ejemplo n.º 20
0
 private Communication SetupCommunication(int templateId, MyContact groupContact, MyContact toContact, Dictionary<string, object> mergeData)
 {
     var template = _communicationService.GetTemplate(templateId);
     var defaultContact = _contactService.GetContactById(_configurationWrapper.GetConfigIntValue("DefaultContactEmailId"));
     return new Communication
     {
         AuthorUserId = 5,
         DomainId = 1,
         EmailBody = template.Body,
         EmailSubject = template.Subject,
         FromContact = new Contact {ContactId = defaultContact.Contact_ID, EmailAddress = defaultContact.Email_Address},
         ReplyToContact = new Contact {ContactId = groupContact.Contact_ID, EmailAddress = groupContact.Email_Address},
         ToContacts = new List<Contact> {new Contact {ContactId = toContact.Contact_ID, EmailAddress = toContact.Email_Address}},
         MergeData = mergeData
     };
 }
Ejemplo n.º 21
0
 public MyContact GetContactByParticipantId(int participantId)
 {
     var token = ApiLogin();
     var searchString = string.Format("{0},",participantId);
     var contacts = _ministryPlatformService.GetPageViewRecords("ContactByParticipantId", token, searchString);
     var c = contacts.SingleOrDefault();
     if (c == null)
     {
         return null;
     }
     var contact = new MyContact
     {
         Contact_ID = c.ToInt("Contact_ID"),
         Email_Address = c.ToString("Email_Address"),
         Last_Name = c.ToString("Last_Name"),
         First_Name = c.ToString("First_Name")
     };
     return contact;
 }
Ejemplo n.º 22
0
 private Dictionary<string, object> SetupMergeData(int contactId,
                                                   int opportunityId,
                                                   Opportunity previousOpportunity,
                                                   Opportunity currentOpportunity,
                                                   DateTime startDate,
                                                   DateTime endDate,
                                                   MyContact groupContact,
                                                   String htmlTable)
 {
     MyContact volunteer = _contactService.GetContactById(contactId);
     return new Dictionary<string, object>
     {
         {"Opportunity_Name", opportunityId == 0 ? "Not Available" : currentOpportunity.OpportunityName},
         {"Start_Date", startDate.ToShortDateString()},
         {"End_Date", endDate.ToShortDateString()},
         {"Shift_Start", currentOpportunity.ShiftStart.FormatAsString() ?? string.Empty},
         {"Shift_End", currentOpportunity.ShiftEnd.FormatAsString() ?? string.Empty},
         {"Room", currentOpportunity.Room ?? string.Empty},
         {"Group_Contact", groupContact.Nickname + " " + groupContact.Last_Name},
         {"Group_Name", currentOpportunity.GroupName},
         {
             "Previous_Opportunity_Name",
             previousOpportunity != null ? previousOpportunity.OpportunityName : @"Not Available"
         },
         {"Volunteer_Name", volunteer.Nickname + " " + volunteer.Last_Name},
         {"Html_Table", htmlTable}
     };
 }