public void ShouldGetDonorForEmail()
        {
            var donor = new ContactDonor();
            _mpDonorService.Setup(mocked => mocked.GetPossibleGuestContactDonor("*****@*****.**")).Returns(donor);
            var response = _fixture.GetContactDonorForEmail("*****@*****.**");

            _mpDonorService.VerifyAll();
            Assert.AreSame(donor, response);
            Assert.IsFalse(response.RegisteredUser);
        }
        public void ShouldGetDonorForAuthenticatedUser()
        {
            var donor = new ContactDonor();
            _authenticationService.Setup(mocked => mocked.GetContactId("authToken")).Returns(123);
            _mpDonorService.Setup(mocked => mocked.GetContactDonor(123)).Returns(donor);
            var response = _fixture.GetContactDonorForAuthenticatedUser("authToken");

            _authenticationService.VerifyAll();
            _mpDonorService.VerifyAll();

            Assert.AreSame(donor, response);
        }
        private DonationsDTO GetDonationsForDonor(ContactDonor donor, string donationYear = null, bool softCredit = false)
        {
            var donorIds = GetDonorIdsForDonor(donor);

            var donations = softCredit ? _mpDonorService.GetSoftCreditDonations(donorIds, donationYear) : _mpDonorService.GetDonations(donorIds, donationYear);
            return (PostProcessDonations(donations));
        }
 public int CreateContactForGuestGiver(string emailAddress, string displayName)
 {
     var contactDonor = new ContactDonor
     {
         Details = new ContactDetails
         {
             DisplayName = displayName,
             EmailAddress = emailAddress
         }
     };
     return (CreateContact(contactDonor));
 }
Beispiel #5
0
        public ContactDonor GetEmailViaDonorId(int donorId)
        {
            var donor = new ContactDonor();
            try
            {
                var searchStr = string.Format(",\"{0}\"", donorId);
                var records =
                    WithApiLogin(
                        apiToken => (_ministryPlatformService.GetPageViewRecords("DonorByContactId", apiToken, searchStr)));
                if (records != null && records.Count > 0)
                {
                    var record = records.First();

                    donor.DonorId = record.ToInt("Donor_ID");
                    donor.ProcessorId = record.ToString(DonorProcessorId);
                    donor.ContactId = record.ToInt("Contact_ID");
                    donor.RegisteredUser = true;
                    donor.Email = record.ToString("Email");
                    donor.StatementType = record.ToString("Statement_Type");
                    donor.StatementTypeId = record.ToInt("Statement_Type_ID");
                    donor.StatementFreq = record.ToString("Statement_Frequency");
                    donor.StatementMethod = record.ToString("Statement_Method");
                    donor.Details = new ContactDetails
                    {
                        EmailAddress = record.ToString("Email"),
                        HouseholdId = record.ToInt("Household_ID")
                    };
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(
                    string.Format("GetEmailViaDonorId failed.  Donor Id: {0}", donorId), ex);
            }

            return donor;
        }
Beispiel #6
0
        public ContactDonor GetPossibleGuestContactDonor(string email)
        {
            ContactDonor donor;
            try
            {
                if (string.IsNullOrWhiteSpace(email))
                {
                    return null;
                }
                var searchStr =  "," + email;
                var records =
                    WithApiLogin(
                        apiToken => (_ministryPlatformService.GetPageViewRecords("PossibleGuestDonorContact", apiToken, searchStr)));
                if (records != null && records.Count > 0)
                {
                    var record = records.First();
                    donor = new ContactDonor()
                    {
                        
                        DonorId = record.ToInt(DonorRecordId),
                        ProcessorId = record.ToString(DonorProcessorId),
                        ContactId = record.ToInt("Contact_ID"),
                        Email = record.ToString("Email_Address"),
                        RegisteredUser = false
                    };
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(
                    string.Format("GetPossibleGuestDonorContact failed. Email: {0}", email), ex);
            }

            return donor;

        }
        public void ShouldReturnExistingDonorWithExistingStripeId()
        {
            var donor = new ContactDonor
            {
                ContactId = 12345,
                DonorId = 67890,
                ProcessorId = "Processor_ID",
                RegisteredUser = true
            };

            var response = _fixture.CreateOrUpdateContactDonor(donor, EncryptedKey, "*****@*****.**", "stripe_token", DateTime.Now);

            _mpDonorService.VerifyAll();
            _mpContactService.VerifyAll();
            _paymentService.VerifyAll();

            Assert.AreEqual(donor.ContactId, response.ContactId);
            Assert.AreEqual(donor.DonorId, response.DonorId);
            Assert.AreEqual(donor.ProcessorId, response.ProcessorId);
            Assert.AreEqual(donor.RegisteredUser, response.RegisteredUser);
        }
        public void TestEditRecurringGiftNoEdits()
        {
            const string authUserToken = "auth";
            var today = DateTime.Today;

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

            var donor = new ContactDonor
            {
                DonorId = 456
            };

            var existingGift = new CreateDonationDistDto
            {
                Amount = 50000,
                ProgramId = "3",
                Frequency = 1,
                StartDate = today,
                DonorAccountId = 234,
                SubscriptionId = "sub_123",
                DayOfWeek = (int)today.DayOfWeek,
                RecurringGiftId = 345
            };

            _mpDonorService.Setup(mocked => mocked.GetRecurringGiftById(authUserToken, editGift.RecurringGiftId)).Returns(existingGift);

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

            Assert.IsNotNull(result);
        }
        public void TestGetDonor()
        {
            var donorId = 1234567;
            var processorId = "cus_431234";
            var contactId = 565656;
            var email = "*****@*****.**";
            var guestDonorPageViewId = "DonorByContactId";
            var expectedDonorValues = new List<Dictionary<string, object>>();
            expectedDonorValues.Add(new Dictionary<string, object>
            {
                {"Donor_ID", donorId},
                {"Processor_ID", processorId},
                {"Contact_ID", contactId},
                {"Email", email},
                {"Statement_Type", "Individual"},
                {"Statement_Type_ID", 1},
                {"Statement_Frequency", "Quarterly"},
                {"Statement_Method", "None"},
                {"Household_ID", 1}
            });
            var donor = new ContactDonor()
            {
                DonorId = donorId,
                ProcessorId = processorId,
                ContactId = contactId,
                Email = email
            };

            _ministryPlatformService.Setup(mocked => mocked.GetPageViewRecords(
                guestDonorPageViewId, It.IsAny<string>(),
                It.IsAny<string>(), "", 0)).Returns(expectedDonorValues);

            var response = _fixture.GetContactDonor(contactId);

            _ministryPlatformService.Verify(
                mocked => mocked.GetPageViewRecords(guestDonorPageViewId, It.IsAny<string>(), "\"" + contactId + "\",", "", 0));

            _ministryPlatformService.VerifyAll();
            Assert.AreEqual(response.DonorId, donor.DonorId);
            Assert.AreEqual(response.ContactId, donor.ContactId);
            Assert.AreEqual(response.ProcessorId, donor.ProcessorId);
        }
        public void TestGetPossibleGuestDonorContact()
        {
            var donorId = 1234567;
            var processorId = "cus_431234";
            var contactId = 565656;
            var email = "*****@*****.**";
            var guestDonorPageViewId = "PossibleGuestDonorContact";
            var expectedDonorValues = new List<Dictionary<string, object>>();
            expectedDonorValues.Add(new Dictionary<string, object>
            {
                {"Donor_Record", donorId},
                {"Processor_ID", processorId},
                {"Contact_ID", contactId},
                {"Email_Address", email}
            });
            var donor = new ContactDonor()
            {
                DonorId = donorId,
                ProcessorId = processorId,
                ContactId = contactId,
                Email = email
            };

            _ministryPlatformService.Setup(mocked => mocked.GetPageViewRecords(
              guestDonorPageViewId, It.IsAny<string>(),
              It.IsAny<string>(), "", 0)).Returns(expectedDonorValues);

            var response = _fixture.GetPossibleGuestContactDonor(email);

            _ministryPlatformService.Verify(mocked => mocked.GetPageViewRecords(guestDonorPageViewId, It.IsAny<string>(), "," + email, "", 0));

            _ministryPlatformService.VerifyAll();
            Assert.AreEqual(response.DonorId, donor.DonorId);
            Assert.AreEqual(response.ContactId, donor.ContactId);
            Assert.AreEqual(response.Email, donor.Email);
            Assert.AreEqual(response.ProcessorId, donor.ProcessorId);
        }
        public void TestSoftCreditGetDonationsForDonor()
        {
            var donations = new List<Donation>
            {
                new Donation
                {
                    donationAmt = 123,
                    donationId = 45,
                    donationDate = DateTime.Parse("1999-12-31 23:59:59"),
                    paymentTypeId = 2, // Cash
                    softCreditDonorId = 123,
                    donorDisplayName = "Fidelity",
                },
                new Donation
                {
                    donationAmt = 567,
                    donationId = 67,
                    donationDate = DateTime.Parse("1999-11-30 23:59:59"),
                    paymentTypeId = 5, //bank
                    transactionCode = "tx_67",
                    softCreditDonorId = 123,
                    donorDisplayName = "US Bank",
                },
                new Donation
                {
                    donationAmt = 678,
                    donationId = 78,
                    donationDate = DateTime.Parse("1999-10-30 23:59:59"),
                    paymentTypeId = 4, //bank
                    transactionCode = "tx_78",
                    softCreditDonorId = 123,
                    donorDisplayName = "Citi",
                }
            };

            var donor = new ContactDonor
            {
                ContactId = 987,
                DonorId = 123,
                StatementTypeId = 456,
                Details = new ContactDetails
                {
                    HouseholdId = 901
                }
            };


            var householdMembers = new List<HouseholdMember>
            {
                new HouseholdMember
                {
                    DonorId = 678,
                    StatementTypeId = 456
                },
                new HouseholdMember
                {
                    DonorId = 123,
                    StatementTypeId = 456
                },
                new HouseholdMember
                {
                    DonorId = 444,
                    StatementTypeId = 455
                },
                new HouseholdMember
                {
                    DonorId = 345,
                    StatementTypeId = 456
                }
            };

            _contactService.Setup(mocked => mocked.GetHouseholdFamilyMembers(901)).Returns(householdMembers);
            _mpDonorService.Setup(mocked => mocked.GetEmailViaDonorId(123)).Returns(donor);
            _mpDonorService.Setup(mocked => mocked.GetSoftCreditDonations(new[] { 123, 678, 345 }, "1999")).Returns(donations);
            var response = _fixture.GetDonationsForDonor(123, "1999", true);
            _mpDonorService.VerifyAll();
            _paymentService.VerifyAll();

            Assert.NotNull(response);
            Assert.NotNull(response.Donations);
            Assert.AreEqual(3, response.Donations.Count);
            Assert.AreEqual(donations[0].donationAmt + donations[1].donationAmt + donations[2].donationAmt, response.DonationTotalAmount);

            Assert.AreEqual(donations[2].donationDate, response.Donations[0].DonationDate);
            Assert.AreEqual(null, response.Donations[0].Source.AccountNumberLast4);
            Assert.AreEqual(null, response.Donations[0].Source.CardType);
            Assert.AreEqual("Citi", response.Donations[0].Source.Name);
            Assert.AreEqual(PaymentType.SoftCredit, response.Donations[0].Source.SourceType);

            Assert.AreEqual(donations[1].donationDate, response.Donations[1].DonationDate);
            Assert.AreEqual(null, response.Donations[1].Source.AccountNumberLast4);
            Assert.AreEqual("US Bank", response.Donations[1].Source.Name);

            Assert.AreEqual(donations[0].donationDate, response.Donations[2].DonationDate);
            Assert.AreEqual("Fidelity", response.Donations[2].Source.Name);
        }
        public void TestGetDonationYearsForDonor()
        {
            var donations = new List<Donation>
            {
                new Donation
                {
                    donationDate = DateTime.Parse("1999-12-31 23:59:59"),
                },
                new Donation
                {
                    donationDate = DateTime.Parse("2000-01-01 00:00:01"),
                },
                new Donation
                {
                    donationDate = DateTime.Parse("1999-11-30 23:59:59"),
                },
                new Donation
                {
                    donationDate = DateTime.Parse("1998-10-30 23:59:59"),
                }
            };

            var softCreditDonations = new List<Donation>
            {
                new Donation
                {
                    donationDate = DateTime.Parse("1997-12-31 23:59:59"),
                },
                new Donation
                {
                    donationDate = DateTime.Parse("2001-01-01 00:00:01"),
                },
                new Donation
                {
                    donationDate = DateTime.Parse("1999-11-30 23:59:59"),
                },
                new Donation
                {
                    donationDate = DateTime.Parse("1997-11-30 23:59:59"),
                },
                new Donation
                {
                    donationDate = DateTime.Parse("1996-10-30 23:59:59"),
                }
            };

            var expectedYears = new List<string>
            {
                "2001",
                "2000",
                "1999",
                "1998",
                "1997",
                "1996"
            };

            var donor = new ContactDonor
            {
                ContactId = 987,
                DonorId = 123,
                StatementTypeId = 456
            };
            _mpDonorService.Setup(mocked => mocked.GetEmailViaDonorId(123)).Returns(donor);
            _mpDonorService.Setup(mocked => mocked.GetDonations(new [] {123}, null)).Returns(donations);
            _mpDonorService.Setup(mocked => mocked.GetSoftCreditDonations(new [] {123}, null)).Returns(softCreditDonations);

            var response = _fixture.GetDonationYearsForDonor(123);
            _mpDonorService.VerifyAll();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.AvailableDonationYears);
            Assert.AreEqual(expectedYears.Count, response.AvailableDonationYears.Count);
        }
        public void TestGetDonationsForDonor()
        {
            var donations = new List<Donation>
            {
                new Donation
                {
                    donationAmt = 123,
                    donationId = 45,
                    donationDate = DateTime.Parse("1999-12-31 23:59:59"),
                    paymentTypeId = 2, // Cash
                },
                new Donation
                {
                    donationAmt = 567,
                    donationId = 67,
                    donationDate = DateTime.Parse("1999-11-30 23:59:59"),
                    paymentTypeId = 5, //bank
                    transactionCode = "tx_67"
                },
                new Donation
                {
                    donationAmt = 678,
                    donationId = 78,
                    donationDate = DateTime.Parse("1999-10-30 23:59:59"),
                    paymentTypeId = 4, //bank
                    transactionCode = "tx_78"
                }
            };

            var donor = new ContactDonor
            {
                ContactId = 987,
                DonorId = 123,
                StatementTypeId = 456,
                Details = new ContactDetails
                {
                    HouseholdId = 901
                }
            };

            var household = new List<HouseholdMember>
            {
                new HouseholdMember
                {
                    DonorId = 678,
                    StatementTypeId = 456
                },
                new HouseholdMember
                {
                    DonorId = 123,
                    StatementTypeId = 456
                },
                new HouseholdMember
                {
                    DonorId = 444,
                    StatementTypeId = 455
                },
                new HouseholdMember
                {
                    DonorId = 345,
                    StatementTypeId = 456
                }
            };
            _contactService.Setup(mocked => mocked.GetHouseholdFamilyMembers(901)).Returns(household);
            _mpDonorService.Setup(mocked => mocked.GetEmailViaDonorId(123)).Returns(donor);
            _mpDonorService.Setup(mocked => mocked.GetDonations(new [] {123, 678, 345}, "1999")).Returns(donations);
            _paymentService.Setup(mocked => mocked.GetCharge("tx_67")).Returns(new StripeCharge
            {
                Source = new StripeSource
                {
                    AccountNumberLast4 = "9876"
                }
            });
            _paymentService.Setup(mocked => mocked.GetCharge("tx_78")).Returns(new StripeCharge
            {
                Source = new StripeSource
                {
                    AccountNumberLast4 = "8765",
                    Brand = CardBrand.AmericanExpress
                }
            });
            var response = _fixture.GetDonationsForDonor(123, "1999");
            _mpDonorService.VerifyAll();
            _paymentService.VerifyAll();

            Assert.NotNull(response);
            Assert.NotNull(response.Donations);
            Assert.AreEqual(3, response.Donations.Count);
            Assert.AreEqual(donations[0].donationAmt + donations[1].donationAmt + donations[2].donationAmt, response.DonationTotalAmount);

            Assert.AreEqual(donations[2].donationDate, response.Donations[0].DonationDate);
            Assert.AreEqual("8765", response.Donations[0].Source.AccountNumberLast4);
            Assert.AreEqual(CreditCardType.AmericanExpress, response.Donations[0].Source.CardType);

            Assert.AreEqual(donations[1].donationDate, response.Donations[1].DonationDate);
            Assert.AreEqual("9876", response.Donations[1].Source.AccountNumberLast4);

            Assert.AreEqual(donations[0].donationDate, response.Donations[2].DonationDate);
            Assert.AreEqual("cash", response.Donations[2].Source.Name);
        }
        private IEnumerable<int> GetDonorIdsForDonor(ContactDonor donor)
        {
            var donorIds = new HashSet<int>();
            if (donor.ExistingDonor)
            {
                donorIds.Add(donor.DonorId);
            }

            if (donor.StatementTypeId != _statementTypeFamily || !donor.HasDetails)
            {
                return (donorIds);
            }

            var household = _contactService.GetHouseholdFamilyMembers(donor.Details.HouseholdId);
            if (household == null || !household.Any())
            {
                return (donorIds);
            }

            foreach (var member in household)
            {
                if(member.StatementTypeId.HasValue && member.StatementTypeId == _statementTypeFamily && member.DonorId.HasValue)
                {
                    donorIds.Add(member.DonorId.Value);
                }
            }

            return (donorIds);
        }
        private DonationYearsDTO GetDonationYearsForDonor(ContactDonor donor)
        {
            var donorIds = GetDonorIdsForDonor(donor);
            var donations = _mpDonorService.GetDonations(donorIds, null);
            var softCreditDonations = _mpDonorService.GetSoftCreditDonations(donorIds);

            var years = new HashSet<string>();
            if (softCreditDonations != null && softCreditDonations.Any())
            {
                years.UnionWith(softCreditDonations.Select(d => d.donationDate.Year.ToString()));
            }
            if (donations != null && donations.Any())
            {
                years.UnionWith(donations.Select(d => d.donationDate.Year.ToString()));
            }

            var donationYears = new DonationYearsDTO();
            donationYears.AvailableDonationYears.AddRange(years.ToList());

            return (donationYears);
        }
        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);
        }
        public void TestGetContactDonorForDonorAccount()
        {
            const int donorId = 1234567;
            const string processorId = "cus_431234";
            const int contactId = 565656;
            const string email = "*****@*****.**";
            const string guestDonorPageViewId = "DonorByContactId";
            const string accountNumber = "1234567";
            const string routingNumber = "042000314";
          
            var expectedEncAcct = _fixture.CreateHashedAccountAndRoutingNumber(accountNumber, routingNumber);
            var queryResults = new List<Dictionary<string, object>>
            {
                new Dictionary<string, object>
                {
                    { "Contact_ID", contactId }
                }
            };

            _ministryPlatformService.Setup(mocked => mocked.GetPageViewRecords(2015, It.IsAny<string>(), ",\"" + expectedEncAcct + "\"", "", 0)).Returns(queryResults);

            var expectedDonorValues = new List<Dictionary<string, object>>
            {
                new Dictionary<string, object>
                {
                    {"Donor_ID", donorId},
                    {"Processor_ID", processorId},
                    {"Contact_ID", contactId},
                    {"Email", email},
                    {"Statement_Type", "Individual"},
                    {"Statement_Type_ID", 1},
                    {"Statement_Frequency", "Quarterly"},
                    {"Statement_Method", "None"},
                    {"Household_ID", 1}
                }
            };
            var donor = new ContactDonor()
            {
                DonorId = donorId,
                ProcessorId = processorId,
                ContactId = contactId,
                Email = email
            };

            _ministryPlatformService.Setup(mocked => mocked.GetPageViewRecords(
                guestDonorPageViewId, It.IsAny<string>(),
                 "\"" + contactId + "\",", "", 0)).Returns(expectedDonorValues);
           
            var result = _fixture.GetContactDonorForDonorAccount(accountNumber, routingNumber);
            _ministryPlatformService.VerifyAll();
            _crypto.VerifyAll();

            Assert.IsNotNull(result);
            Assert.AreEqual(result.DonorId, donor.DonorId);
            Assert.AreEqual(result.ContactId, donor.ContactId);
            Assert.AreEqual(result.ProcessorId, donor.ProcessorId);
        }
        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);
        }
        public void TestEditRecurringGiftOnlyChangePayment()
        {
            const string authUserToken = "auth";
            var today = DateTime.Today;

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

            var donor = new ContactDonor
            {
                DonorId = 456,
                ProcessorId = "cus_123"
            };

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

            var stripeSource = new SourceData
            {
                id = "bank_1234",
                bank_last4 = "5678"
            };


            const int newDonorAccountId = 987;

            _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(null, "0", stripeSource.bank_last4, null, existingGift.DonorId, stripeSource.id, existingGift.StripeCustomerId)).Returns(newDonorAccountId);
            _mpDonorService.Setup(mocked => mocked.UpdateRecurringGiftDonorAccount(authUserToken, existingGift.RecurringGiftId.Value, newDonorAccountId));

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

            Assert.IsNotNull(result);
        }
        public void ShouldCreateNewDonorForExistingContact()
        {
            var donor = new ContactDonor
            {
                ContactId = 12345,
                DonorId = 0,
            };

            var stripeCust = new StripeCustomer
            {
                id = "856",
                default_source = "123",
            };

            _paymentService.Setup(mocked => mocked.CreateCustomer("stripe_token", null)).Returns(stripeCust);
            _mpDonorService.Setup(mocked => mocked.CreateDonorRecord(12345, stripeCust.id, It.IsAny<DateTime>(), StatementFrequencyNever, StatementTypeIndividual, StatementMethodNone, null)).Returns(456);
            _paymentService.Setup(mocked => mocked.UpdateCustomerDescription(stripeCust.id, 456)).Returns("456");

            var response = _fixture.CreateOrUpdateContactDonor(donor, EncryptedKey, "*****@*****.**", "stripe_token", DateTime.Now);

            _mpDonorService.VerifyAll();
            _mpContactService.VerifyAll();
            _paymentService.VerifyAll();

            Assert.AreEqual(12345, response.ContactId);
            Assert.AreEqual(456, response.DonorId);
            Assert.AreEqual(stripeCust.id, response.ProcessorId);
        }
        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);
        }
        public void ShouldCreateNewDonorForExistingRegisteredContact()
        {
            var donor = new ContactDonor
            {
                ContactId = 12345,
                DonorId = 0,
                RegisteredUser = true,
                Email = "*****@*****.**"
            };

            var stripeCust = new StripeCustomer
            {
                id = "856",
                default_source = "123",
            };

            _paymentService.Setup(mocked => mocked.CreateCustomer("stripe_token", null)).Returns(stripeCust);
            _mpDonorService.Setup(mocked => mocked.CreateDonorRecord(12345, stripeCust.id, It.IsAny<DateTime>(), 1, 1, 2, null)).Returns(456);
            _mpDonorService.Setup(mocked => mocked.GetEmailViaDonorId(456)).Returns(donor);
            _paymentService.Setup(mocked => mocked.UpdateCustomerDescription(stripeCust.id, 456)).Returns("456");

            var response = _fixture.CreateOrUpdateContactDonor(donor, EncryptedKey, "*****@*****.**", "stripe_token", DateTime.Now);

            _mpDonorService.VerifyAll();
            _mpContactService.VerifyAll();
            _paymentService.VerifyAll();

            Assert.AreEqual(12345, response.ContactId);
            Assert.AreEqual(456, response.DonorId);
            Assert.AreEqual(stripeCust.id, response.ProcessorId);
            Assert.AreEqual(donor.RegisteredUser, response.RegisteredUser);
        }
Beispiel #23
0
        public ContactDonor GetContactDonor(int contactId)
        {
            ContactDonor donor;
            try
            {
                var searchStr = string.Format("\"{0}\",", contactId);
                var records =
                    WithApiLogin(
                        apiToken => (_ministryPlatformService.GetPageViewRecords("DonorByContactId", apiToken, searchStr)));
                if (records != null && records.Count > 0)
                {
                    var record = records.First();
                    donor = new ContactDonor()
                    {
                        DonorId = record.ToInt("Donor_ID"),
                        //we only want processorID from the donor if we are not processing a check
                        ProcessorId = record.ToString(DonorProcessorId),
                        ContactId = record.ToInt("Contact_ID"),
                        RegisteredUser = true,
                        Email = record.ToString("Email"),
                        StatementType = record.ToString("Statement_Type"),
                        StatementTypeId = record.ToInt("Statement_Type_ID"),
                        StatementFreq = record.ToString("Statement_Frequency"),
                        StatementMethod = record.ToString("Statement_Method"),
                        Details = new ContactDetails
                        {
                            EmailAddress = record.ToString("Email"),
                            HouseholdId = record.ToInt("Household_ID")
                        }
                    };
                }
                else
                {
                    donor = new ContactDonor
                    {
                        ContactId = contactId,
                        RegisteredUser = true
                    };
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(
                    string.Format("GetDonorRecord failed.  Contact Id: {0}", contactId), ex);
            }

            return donor;

        }
        public void ShouldUpdateExistingDonorForExistingContact()
        {
            var donor = new ContactDonor
            {
                ContactId = 12345,
                DonorId = 456,
            };

            var stripeCust = new StripeCustomer
            {
                id = "856",
                default_source = "123",
            };

            _paymentService.Setup(mocked => mocked.CreateCustomer("stripe_token", null)).Returns(stripeCust);
            _mpDonorService.Setup(mocked => mocked.UpdatePaymentProcessorCustomerId(456, stripeCust.id)).Returns(456);
            _paymentService.Setup(mocked => mocked.UpdateCustomerDescription(stripeCust.id, 456)).Returns("456");

            var response = _fixture.CreateOrUpdateContactDonor(donor, EncryptedKey, "*****@*****.**", "stripe_token", DateTime.Now);

            _mpDonorService.VerifyAll();
            _mpContactService.VerifyAll();
            _paymentService.VerifyAll();

            Assert.AreEqual(12345, response.ContactId);
            Assert.AreEqual(456, response.DonorId);
            Assert.AreEqual(stripeCust.id, response.ProcessorId);
        }
Beispiel #25
0
        public ContactDonor GetContactDonorForCheckAccount(string encrptedKey)
        {
            var donorAccount = WithApiLogin(apiToken => _ministryPlatformService.GetPageViewRecords(_donorLookupByEncryptedAccount, apiToken, "," + encrptedKey));
            if (donorAccount == null || donorAccount.Count == 0)
            {
                return null;
            }
            var contactId = Convert.ToInt32(donorAccount[0]["Contact_ID"]);
            var myContact = _contactService.GetContactById(contactId);

            var details = new ContactDonor
            {
               DonorId = (int) donorAccount[0]["Donor_ID"],
               Details = new ContactDetails
               {
                   DisplayName = donorAccount[0]["Display_Name"].ToString(),
                   Address = new PostalAddress
                   {
                       Line1 = myContact.Address_Line_1,
                       Line2 = myContact.Address_Line_2,
                       City = myContact.City,
                       State = myContact.State,
                       PostalCode = myContact.Postal_Code
                   } 
               }
               
            };

            return details;
        }
        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);
        }
 public int CreateContactForNewDonor(ContactDonor contactDonor)
 {
     return (CreateContact(contactDonor));
 }
        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();
        }
        private int CreateContact(ContactDonor contactDonor)
        {
            var token = ApiLogin();

            var emailAddress = contactDonor.Details.EmailAddress;
            var displayName = contactDonor.Details.DisplayName;
            int? householdId = null;
            if (contactDonor.Details.HasAddress)
            {
                try
                {
                    householdId = CreateHouseholdAndAddress(displayName, contactDonor.Details.Address, token);
                }
                catch (Exception e)
                {
                    var msg = string.Format("Error creating household and address for emailAddress: {0} displayName: {1}",
                                            emailAddress,
                                            displayName);
                    _logger.Error(msg, e);
                    throw (new ApplicationException(msg, e));
                }
            }

            var contactDictionary = new Dictionary<string, object>
            {
                {"Email_Address", emailAddress},
                {"Company", false},
                {"Display_Name", displayName},
                {"Nickname", displayName},
                {"Household_ID", householdId},
                {"Household_Position_ID", _householdPositionDefaultId}
            };

            try
            {
                return (_ministryPlatformService.CreateRecord(_contactsPageId, contactDictionary, token));
            }
            catch (Exception e)
            {
                var msg = string.Format("Error creating contact, emailAddress: {0} displayName: {1}",
                                        emailAddress,
                                        displayName);
                _logger.Error(msg, e);
                throw (new ApplicationException(msg, e));
            }
        }
        public void TestGetSuccessGetDonorAuthenticated()
        {
            var contactDonor = new ContactDonor
            {
                ContactId = 1,
                DonorId = 394256,
                ProcessorId = ProcessorId
            };

            var defaultSource = new SourceData
            {
                last4 = "1234",
                brand = "Visa",
                address_zip = "45454"
            };
            
            _donorService.Setup(mocked => mocked.GetContactDonorForAuthenticatedUser(It.IsAny<string>())).Returns(contactDonor);
            _paymentService.Setup(mocked => mocked.GetDefaultSource(It.IsAny<string>())).Returns(defaultSource);
            IHttpActionResult result = _fixture.Get();
            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(OkNegotiatedContentResult<DonorDTO>), result);
            var okResult = (OkNegotiatedContentResult<DonorDTO>)result;
            Assert.AreEqual(DonorId, okResult.Content.Id);
            Assert.AreEqual(ProcessorId, okResult.Content.ProcessorId);
            Assert.AreEqual(Brand, okResult.Content.DefaultSource.credit_card.brand);
            Assert.AreEqual(Last4, okResult.Content.DefaultSource.credit_card.last4);
            Assert.AreEqual(AddressZip, okResult.Content.DefaultSource.credit_card.address_zip);
        }