public void TestGetSuccessGetDonorAuthenticated() { var contactDonor = new MpContactDonor { 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); }
public MpContactDonor 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 MpContactDonor { DonorId = (int)donorAccount[0]["Donor_ID"], Details = new MpContactDetails { DisplayName = donorAccount[0]["Display_Name"].ToString(), Address = new MpPostalAddress { Line1 = myContact.Address_Line_1, Line2 = myContact.Address_Line_2, City = myContact.City, State = myContact.State, PostalCode = myContact.Postal_Code } } }; return(details); }
private IEnumerable <int> GetDonorIdsForDonor(MpContactDonor donor) { var donorIds = new HashSet <int>(); if (donor.ExistingDonor) { donorIds.Add(donor.DonorId); } if (donor.StatementTypeId != _statementTypeFamily || !donor.HasDetails) { return(donorIds); } var household = _contactRepository.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); }
public void TestCreateDonorForAuthenticatedUserStripeUpdateThrowsStripeException() { var dto = new CreateDonorDTO { email_address = "*****@*****.**", stripe_token_id = "456" }; var contactDonor = new MpContactDonor { DonorId = 123, ContactId = 789, Email = "*****@*****.**", ProcessorId = "102030", RegisteredUser = true, }; var stripeException = new PaymentProcessorException(HttpStatusCode.PaymentRequired, "auxMessage", "type", "message", "code", "decline", "param"); _donorService.Setup(mocked => mocked.GetContactDonorForAuthenticatedUser(It.IsAny <string>())).Returns(contactDonor); _donorService.Setup( (mocked => mocked.CreateOrUpdateContactDonor(contactDonor, string.Empty, string.Empty, string.Empty, String.Empty, "456", It.IsAny <DateTime>()))) .Throws(stripeException); var response = _fixture.Post(dto); Assert.AreEqual(typeof(RestHttpActionResult <PaymentProcessorErrorResponse>), response.GetType()); _donorService.VerifyAll(); _paymentService.VerifyAll(); }
public void TestEditRecurringGiftStripeError() { var authorizedUserToken = _authType + " " + _authToken; var donor = new MpContactDonor(); var editGift = new RecurringGiftDto(); const int recurringGiftId = 123; var stripeException = new PaymentProcessorException(HttpStatusCode.Forbidden, "aux message", "error type", "message", "code", "decline code", "param", new ContentBlock()); _donorService.Setup(mocked => mocked.GetContactDonorForAuthenticatedUser(authorizedUserToken)).Returns(donor); _donorService.Setup(mocked => mocked.EditRecurringGift(authorizedUserToken, editGift, donor)).Throws(stripeException); var response = _fixture.EditRecurringGift(recurringGiftId, editGift); _donorService.VerifyAll(); Assert.AreEqual(recurringGiftId, editGift.RecurringGiftId); Assert.IsNotNull(response); Assert.IsInstanceOf <RestHttpActionResult <PaymentProcessorErrorResponse> >(response); var err = (RestHttpActionResult <PaymentProcessorErrorResponse>)response; Assert.AreEqual(HttpStatusCode.Forbidden, err.StatusCode); }
public void TestCreateRecurringGift() { const string stripeToken = "tok_123"; var contactDonor = new MpContactDonor { Email = "*****@*****.**" }; var contactDonorUpdated = new MpContactDonor { Email = "*****@*****.**" }; var recurringGiftDto = new RecurringGiftDto { StripeTokenId = stripeToken }; _donorService.Setup(mocked => mocked.GetContactDonorForAuthenticatedUser(_authType + " " + _authToken)).Returns(contactDonor); _donorService.Setup(mocked => mocked.CreateOrUpdateContactDonor(contactDonor, string.Empty, string.Empty, string.Empty, string.Empty, null, null)).Returns(contactDonorUpdated); _donorService.Setup(mocked => mocked.CreateRecurringGift(_authType + " " + _authToken, recurringGiftDto, contactDonorUpdated)).Returns(123); var response = _fixture.CreateRecurringGift(recurringGiftDto); _donorService.VerifyAll(); Assert.IsNotNull(response); Assert.IsInstanceOf <OkNegotiatedContentResult <RecurringGiftDto> >(response); var dtoResponse = ((OkNegotiatedContentResult <RecurringGiftDto>)response).Content; Assert.IsNotNull(dtoResponse); Assert.AreSame(recurringGiftDto, dtoResponse); Assert.AreEqual(contactDonorUpdated.Email, recurringGiftDto.EmailAddress); Assert.AreEqual(123, recurringGiftDto.RecurringGiftId); }
public void TestCreateRecurringGiftStripeError() { const string stripeToken = "tok_123"; var contactDonor = new MpContactDonor(); var contactDonorUpdated = new MpContactDonor(); var recurringGiftDto = new RecurringGiftDto { StripeTokenId = stripeToken }; var stripeException = new PaymentProcessorException(HttpStatusCode.Forbidden, "aux message", "error type", "message", "code", "decline code", "param", new ContentBlock()); _donorService.Setup(mocked => mocked.GetContactDonorForAuthenticatedUser(_authType + " " + _authToken)).Returns(contactDonor); _donorService.Setup(mocked => mocked.CreateOrUpdateContactDonor(contactDonor, string.Empty, string.Empty, string.Empty, string.Empty, null, null)).Returns(contactDonorUpdated); _donorService.Setup(mocked => mocked.CreateRecurringGift(_authType + " " + _authToken, recurringGiftDto, contactDonorUpdated)).Throws(stripeException); var response = _fixture.CreateRecurringGift(recurringGiftDto); _donorService.VerifyAll(); Assert.IsNotNull(response); Assert.IsInstanceOf <RestHttpActionResult <PaymentProcessorErrorResponse> >(response); var err = (RestHttpActionResult <PaymentProcessorErrorResponse>)response; Assert.AreEqual(HttpStatusCode.Forbidden, err.StatusCode); }
private DonationsDTO GetDonationsForDonor(MpContactDonor donor, string donationYear = null, bool softCredit = false) { var donorIds = GetDonorIdsForDonor(donor); var donations = softCredit ? _mpDonorRepository.GetSoftCreditDonations(donorIds, donationYear) : _mpDonorRepository.GetDonations(donorIds, donationYear); return(PostProcessDonations(donations)); }
private int CreateContact(MpContactDonor mpContactDonor) { var token = ApiLogin(); var emailAddress = mpContactDonor.Details.EmailAddress; var displayName = mpContactDonor.Details.DisplayName; var firstName = mpContactDonor.Details.FirstName; var lastName = mpContactDonor.Details.LastName; int?householdId = null; if (mpContactDonor.Details.HasAddress) { try { householdId = CreateHouseholdAndAddress(displayName, mpContactDonor.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 }, { "First_Name", firstName }, { "Last_Name", lastName }, { "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 mpContact, emailAddress: {0} displayName: {1}", emailAddress, displayName); _logger.Error(msg, e); throw (new ApplicationException(msg, e)); } }
public void TestUpdateDonorRegisteredDonor() { var dto = new UpdateDonorDTO { DonorId = "123", EmailAddress = "*****@*****.**", StripeTokenId = "456" }; var contactDonor = new MpContactDonor { DonorId = 123, ContactId = 789, Email = "*****@*****.**", ProcessorId = "102030", RegisteredUser = true, }; var sourceData = new SourceData { brand = "Visa", last4 = "5432", address_zip = "90210", exp_month = "12", exp_year = "19" }; _donorService.Setup(mocked => mocked.GetContactDonorForAuthenticatedUser(It.IsAny <string>())).Returns(contactDonor); _paymentService.Setup(mocked => mocked.UpdateCustomerSource(contactDonor.ProcessorId, dto.StripeTokenId)) .Returns(sourceData); var result = _fixture.UpdateDonor(dto); _donorService.VerifyAll(); _paymentService.VerifyAll(); Assert.NotNull(result); Assert.IsInstanceOf <OkNegotiatedContentResult <DonorDTO> >(result); var donorDto = ((OkNegotiatedContentResult <DonorDTO>)result).Content; Assert.AreEqual(contactDonor.DonorId, donorDto.Id); Assert.AreEqual(contactDonor.ProcessorId, donorDto.ProcessorId); Assert.AreEqual(contactDonor.RegisteredUser, donorDto.RegisteredUser); Assert.IsNotNull(donorDto.DefaultSource.bank_account); Assert.IsNotNull(donorDto.DefaultSource.credit_card); Assert.AreEqual(sourceData.brand, donorDto.DefaultSource.credit_card.brand); Assert.AreEqual(sourceData.last4, donorDto.DefaultSource.credit_card.last4); Assert.AreEqual(sourceData.address_zip, donorDto.DefaultSource.credit_card.address_zip); Assert.AreEqual(sourceData.exp_month + sourceData.exp_year, donorDto.DefaultSource.credit_card.exp_date); }
public void TestGetContactDonorForCheck() { const string encryptedKey = "disCv2kF/8HlRCWeTqolok1G4imf1cNZershgmCCFDI="; const string addr1 = "12 Scenic Dr"; const string addr2 = "Penthouse Suite"; const string city = "Honolulu"; const string state = "HI"; const string zip = "68168-1618"; const string displayName = "Vacationing Vera"; const int donorId = 123456789; const string decrypAcct = "6015268542"; const string decryptRout = "042000314"; const string accountNumber = "P/H+3ccB0ZssORkd+YyJzA=="; const string routingNumber = "TUbiKZ/Vw1l6uyGCYIIUMg=="; var check = new CheckAccount { AccountNumber = accountNumber, RoutingNumber = routingNumber }; var contactDonor = new MpContactDonor { DonorId = donorId, Details = new MpContactDetails { DisplayName = displayName, Address = new MpPostalAddress() { Line1 = addr1, Line2 = addr2, City = city, State = state, PostalCode = zip } } }; _donorService.Setup(mocked => mocked.GetContactDonorForCheckAccount(encryptedKey)).Returns(contactDonor); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(accountNumber)).Returns(decrypAcct); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(routingNumber)).Returns(decryptRout); _mpDonorService.Setup(mocked => mocked.CreateHashedAccountAndRoutingNumber(decrypAcct, decryptRout)).Returns(encryptedKey); var result = _fixture.GetContactDonorForCheck(accountNumber, routingNumber); _donorService.VerifyAll(); Assert.IsNotNull(contactDonor); Assert.AreEqual(result.DisplayName, contactDonor.Details.DisplayName); Assert.AreEqual(result.Address, contactDonor.Details.Address); }
public MpContactDonor GetContactDonor(int contactId) { MpContactDonor 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 MpContactDonor() { 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 MpContactDetails { EmailAddress = record.ToString("Email"), HouseholdId = record.ToInt("Household_ID") } }; } else { donor = new MpContactDonor { ContactId = contactId, RegisteredUser = true }; } } catch (Exception ex) { throw new ApplicationException( string.Format("GetDonorRecord failed. Contact Id: {0}", contactId), ex); } return(donor); }
public int CreateContactForGuestGiver(string emailAddress, string displayName, string firstName, string lastName) { var contactDonor = new MpContactDonor { Details = new MpContactDetails { DisplayName = displayName, EmailAddress = emailAddress, FirstName = firstName, LastName = lastName } }; return(CreateContact(contactDonor)); }
public void TestGetGetDonorAuthenticatedNoPaymentProcessor() { var contactDonor = new MpContactDonor { ContactId = 1, DonorId = 2, ProcessorId = null }; _donorService.Setup(mocked => mocked.GetContactDonorForAuthenticatedUser(It.IsAny <string>())).Returns(contactDonor); IHttpActionResult result = _fixture.Get(); Assert.IsNotNull(result); Assert.IsInstanceOf(typeof(NotFoundResult), result); }
public void TestGetGetDonorUnauthenticatedNoPaymentProcessor() { _fixture.Request.Headers.Authorization = null; var contactDonor = new MpContactDonor { ContactId = 1, DonorId = 2, ProcessorId = null }; _donorService.Setup(mocked => mocked.GetContactDonorForEmail(Email)).Returns(contactDonor); IHttpActionResult result = _fixture.Get(Email); Assert.IsNotNull(result); Assert.IsInstanceOf(typeof(NotFoundResult), result); }
public void TestUpdateDonorGuestDonor() { _fixture.Request.Headers.Authorization = null; var dto = new UpdateDonorDTO { DonorId = "123", EmailAddress = "*****@*****.**", StripeTokenId = "456" }; var contactDonor = new MpContactDonor { DonorId = 123, ContactId = 789, Email = "*****@*****.**", ProcessorId = "102030", RegisteredUser = false, }; var sourceData = new SourceData { bank_last4 = "5555", routing_number = "987654321" }; _donorService.Setup(mocked => mocked.GetContactDonorForEmail("*****@*****.**")).Returns(contactDonor); _paymentService.Setup(mocked => mocked.UpdateCustomerSource(contactDonor.ProcessorId, dto.StripeTokenId)) .Returns(sourceData); var result = _fixture.UpdateDonor(dto); _donorService.VerifyAll(); _paymentService.VerifyAll(); Assert.NotNull(result); Assert.IsInstanceOf <OkNegotiatedContentResult <DonorDTO> >(result); var donorDto = ((OkNegotiatedContentResult <DonorDTO>)result).Content; Assert.AreEqual(contactDonor.DonorId, donorDto.Id); Assert.AreEqual(contactDonor.ProcessorId, donorDto.ProcessorId); Assert.AreEqual(contactDonor.RegisteredUser, donorDto.RegisteredUser); Assert.IsNotNull(donorDto.DefaultSource.credit_card); Assert.IsNotNull(donorDto.DefaultSource.bank_account); Assert.AreEqual(sourceData.bank_last4, donorDto.DefaultSource.bank_account.last4); Assert.AreEqual(sourceData.routing_number, donorDto.DefaultSource.bank_account.routing); }
public void ShouldPostToSuccessfullyReturnExistingGuestDonor() { _fixture.Request.Headers.Authorization = null; var createDonorDto = new CreateDonorDTO { stripe_token_id = "tok_test", email_address = "*****@*****.**", first_name = "", last_name = "" }; var lookupDonor = new MpContactDonor { ContactId = 8675309, DonorId = 90210, ProcessorId = "jenny_ive_got_your_number" }; var createDonor = new MpContactDonor { ContactId = 8675309, DonorId = 90210, ProcessorId = "jenny_ive_got_your_number" }; _donorService.Setup(mocked => mocked.GetContactDonorForEmail(createDonorDto.email_address)).Returns(lookupDonor); _donorService.Setup(mocked => mocked.CreateOrUpdateContactDonor(It.Is <MpContactDonor>(d => d == lookupDonor), string.Empty, string.Empty, string.Empty, createDonorDto.email_address, createDonorDto.stripe_token_id, It.IsAny <DateTime>())).Returns(createDonor); IHttpActionResult result = _fixture.Post(createDonorDto); _donorService.VerifyAll(); Assert.IsNotNull(result); Assert.IsInstanceOf(typeof(ResponseMessageResult), result); Assert.NotNull(((ResponseMessageResult)result).Response); Assert.AreEqual(HttpStatusCode.OK, ((ResponseMessageResult)result).Response.StatusCode); var content = ((ResponseMessageResult)result).Response.Content; Assert.NotNull(content); Assert.IsInstanceOf(typeof(ObjectContent <DonorDTO>), content); var responseDto = (DonorDTO)((ObjectContent)content).Value; Assert.AreEqual(90210, responseDto.Id); Assert.AreEqual("jenny_ive_got_your_number", responseDto.ProcessorId); }
public void TestCreateDonorWithDonorId() { var check = new CheckScannerCheck { Id = 11111, DonorId = 222, AccountNumber = "111", Address = new crds_angular.Models.Crossroads.Stewardship.Address { Line1 = "1 line 1", Line2 = "1 line 2", City = "1 city", State = "1 state", PostalCode = "1 postal" }, Amount = 1111, CheckDate = DateTime.Now.AddHours(1), CheckNumber = "11111", Name1 = "1 name 1", Name2 = "1 name 2", RoutingNumber = "1010", ScanDate = DateTime.Now.AddHours(2) }; var contactDonorExisting = new MpContactDonor { ContactId = 123, ProcessorId = "111000111", DonorId = 111111, RegisteredUser = true, Account = new MpDonorAccount { ProcessorId = "111000111", ProcessorAccountId = "111111" } }; _donorService.Setup(mocked => mocked.GetContactDonorForDonorId(check.DonorId.Value)).Returns(contactDonorExisting); _donorService.Setup(mocked => mocked.GetContactDonorForDonorAccount(check.AccountNumber, check.RoutingNumber)).Returns(contactDonorExisting); var result = _fixture.CreateDonor(check); _donorService.VerifyAll(); Assert.NotNull(result); Assert.AreEqual(contactDonorExisting, result); }
public StripePlan CreatePlan(RecurringGiftDto recurringGiftDto, MpContactDonor mpContactDonor) { var request = new RestRequest("plans", Method.POST); var interval = EnumMemberSerializationUtils.ToEnumString(recurringGiftDto.PlanInterval); request.AddParameter("amount", (int)(recurringGiftDto.PlanAmount * Constants.StripeDecimalConversionValue)); request.AddParameter("interval", interval); request.AddParameter("name", string.Format("Donor ID #{0} {1}ly", mpContactDonor.DonorId, interval)); request.AddParameter("currency", "usd"); request.AddParameter("id", mpContactDonor.DonorId + " " + DateTime.Now); var response = _stripeRestClient.Execute <StripePlan>(request); CheckStripeResponse("Invalid plan creation request", response); return(response.Data); }
public MpContactDonor GetPossibleGuestContactDonor(string email) { MpContactDonor 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 MpContactDonor() { DonorId = record.ToInt(DonorRecordId), ProcessorId = record.ToString(DonorProcessorId), ContactId = record.ToInt("Contact_ID"), Email = record.ToString("Email_Address"), RegisteredUser = false, Details = new MpContactDetails { FirstName = record.ToString("First_Name"), LastName = record.ToString("Last_Name") } }; } else { return(null); } } catch (Exception ex) { throw new ApplicationException( string.Format("GetPossibleGuestDonorContact failed. Email: {0}", email), ex); } return(donor); }
public void TestUpdateDonorStripeUpdateThrowsStripeException() { _fixture.Request.Headers.Authorization = null; var dto = new UpdateDonorDTO { DonorId = "123", EmailAddress = "*****@*****.**", StripeTokenId = "456" }; var contactDonor = new MpContactDonor { DonorId = 123, ContactId = 789, Email = "*****@*****.**", ProcessorId = "102030", RegisteredUser = false, }; _donorService.Setup(mocked => mocked.GetContactDonorForEmail("*****@*****.**")).Returns(contactDonor); var stripeException = new PaymentProcessorException(HttpStatusCode.PaymentRequired, "auxMessage", "type", "message", "code", "decline", "param"); _paymentService.Setup(mocked => mocked.UpdateCustomerSource(contactDonor.ProcessorId, dto.StripeTokenId)) .Throws(stripeException); var response = _fixture.UpdateDonor(dto); Assert.AreEqual(typeof(RestHttpActionResult <PaymentProcessorErrorResponse>), response.GetType()); var stripeErrorResponse = (RestHttpActionResult <PaymentProcessorErrorResponse>)response; var content = stripeErrorResponse.Content; Assert.AreEqual("type", content.Error.Type); Assert.AreEqual("message", content.Error.Message); Assert.AreEqual("code", content.Error.Code); Assert.AreEqual("decline", content.Error.DeclineCode); Assert.AreEqual("param", content.Error.Param); _donorService.VerifyAll(); _paymentService.VerifyAll(); }
public MpContactDonor GetEmailViaDonorId(int donorId) { var donor = new MpContactDonor(); 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 MpContactDetails { 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); }
private DonationYearsDTO GetDonationYearsForDonor(MpContactDonor donor) { var donorIds = GetDonorIdsForDonor(donor); var donations = _mpDonorRepository.GetDonations(donorIds, null); var softCreditDonations = _mpDonorRepository.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 TestEditRecurringGiftMinistryPlatformException() { var authorizedUserToken = _authType + " " + _authToken; var donor = new MpContactDonor(); var editGift = new RecurringGiftDto(); const int recurringGiftId = 123; _donorService.Setup(mocked => mocked.GetContactDonorForAuthenticatedUser(authorizedUserToken)).Returns(donor); _donorService.Setup(mocked => mocked.EditRecurringGift(authorizedUserToken, editGift, donor)).Throws <ApplicationException>(); try { _fixture.EditRecurringGift(recurringGiftId, editGift); Assert.Fail("expected exception was not thrown"); } catch (HttpResponseException) { // expected } _donorService.VerifyAll(); Assert.AreEqual(recurringGiftId, editGift.RecurringGiftId); }
public void TestEditRecurringGift() { var authorizedUserToken = _authType + " " + _authToken; var donor = new MpContactDonor(); var editGift = new RecurringGiftDto(); var newGift = new RecurringGiftDto(); const int recurringGiftId = 123; _donorService.Setup(mocked => mocked.GetContactDonorForAuthenticatedUser(authorizedUserToken)).Returns(donor); _donorService.Setup(mocked => mocked.EditRecurringGift(authorizedUserToken, editGift, donor)).Returns(newGift); var response = _fixture.EditRecurringGift(recurringGiftId, editGift); _donorService.VerifyAll(); Assert.AreEqual(recurringGiftId, editGift.RecurringGiftId); Assert.IsNotNull(response); Assert.IsInstanceOf <OkNegotiatedContentResult <RecurringGiftDto> >(response); var dtoResponse = ((OkNegotiatedContentResult <RecurringGiftDto>)response).Content; Assert.IsNotNull(dtoResponse); Assert.AreSame(newGift, dtoResponse); }
public MpContactDonor GetContactDonor(int contactId) { MpContactDonor donor; try { var token = base.ApiLogin(); var parameters = new Dictionary <string, object> { { "@Contact_ID", contactId } }; var storedProcReturn = _ministryPlatformRestRepository.UsingAuthenticationToken(token).GetFromStoredProc <MpContactDonor>("api_crds_Get_Contact_Donor", parameters); if (storedProcReturn != null && storedProcReturn.Count > 0 && storedProcReturn[0].Count > 0) { donor = storedProcReturn[0].First(); } else { donor = new MpContactDonor { ContactId = contactId, RegisteredUser = true }; } } catch (Exception ex) { throw new ApplicationException( string.Format("GetDonorRecord failed. Contact Id: {0}", contactId), ex); } return(donor); }
public void ShouldThrowExceptionWhenDonorCreationFails() { _fixture.Request.Headers.Authorization = null; var createDonorDto = new CreateDonorDTO { stripe_token_id = "tok_test", email_address = "*****@*****.**", first_name = "", last_name = "" }; var lookupDonor = new MpContactDonor { ContactId = 8675309, DonorId = 90210, ProcessorId = "jenny_ive_got_your_number" }; var createException = new Exception("Danger, Will Robinson!"); _donorService.Setup(mocked => mocked.GetContactDonorForEmail(createDonorDto.email_address)).Returns(lookupDonor); _donorService.Setup(mocked => mocked.CreateOrUpdateContactDonor(It.Is <MpContactDonor>(d => d == lookupDonor), string.Empty, string.Empty, string.Empty, createDonorDto.email_address, createDonorDto.stripe_token_id, It.IsAny <DateTime>())).Throws(createException); try { _fixture.Post(createDonorDto); Assert.Fail("Expected exception was not thrown"); } catch (Exception e) { Assert.AreEqual(typeof(HttpResponseException), e.GetType()); } _donorService.VerifyAll(); }
public void TestCreateDonationsFromBatch() { const string encryptedKey = "PH/rty1234"; const string decrypAcct = "6015268542"; const string decryptRout = "042000314"; const string donorAcctId = "4321"; var checks = new List <CheckScannerCheck> { new CheckScannerCheck { Id = 11111, AccountNumber = "111", Address = new crds_angular.Models.Crossroads.Stewardship.Address { Line1 = "1 line 1", Line2 = "1 line 2", City = "1 city", State = "1 state", PostalCode = "1 postal" }, Amount = 111100, CheckDate = DateTime.Now.AddHours(1), CheckNumber = " 0 0 00000222111111111111111", Name1 = "1 name 1", Name2 = "1 name 2", RoutingNumber = "1010", ScanDate = DateTime.Now.AddHours(2) } }; var contactDonorExisting = new MpContactDonor { ProcessorId = "111000111", DonorId = 111111, RegisteredUser = true, Account = new MpDonorAccount { DonorAccountId = Int32.Parse(donorAcctId), ProcessorId = "cus_aeirhsjidhriuewiwq", ProcessorAccountId = "py_dgsttety6737hjjhweiu3" } }; _checkScannerDao.Setup(mocked => mocked.GetChecksForBatch("batch123")).Returns(checks); _checkScannerDao.Setup(mocked => mocked.UpdateBatchStatus("batch123", BatchStatus.Exported)).Returns(new CheckScannerBatch()); _checkScannerDao.Setup(mocked => mocked.UpdateCheckStatus(11111, true, null)); _donorService.Setup(mocked => mocked.GetContactDonorForDonorAccount(checks[0].AccountNumber, checks[0].RoutingNumber)).Returns(contactDonorExisting); _paymentService.Setup(mocked => mocked.ChargeCustomer(contactDonorExisting.Account.ProcessorId, contactDonorExisting.Account.ProcessorAccountId, checks[0].Amount, contactDonorExisting.DonorId, checks[0].CheckNumber)).Returns(new StripeCharge { Id = "1020304", Source = new StripeSource() { id = "py_dgsttety6737hjjhweiu3" }, BalanceTransaction = new StripeBalanceTransaction { Fee = 123 } }); _mpDonorService.Setup(mocked => mocked.CreateHashedAccountAndRoutingNumber(decrypAcct, decryptRout)).Returns(encryptedKey); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(checks[0].AccountNumber)).Returns(decrypAcct); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(checks[0].RoutingNumber)).Returns(decryptRout); _mpDonorService.Setup(mocked => mocked.CreateHashedAccountAndRoutingNumber(decrypAcct, decryptRout)).Returns(encryptedKey); _mpDonorService.Setup( mocked => mocked.CreateDonationAndDistributionRecord( It.Is <MpDonationAndDistributionRecord>(d => d.DonationAmt == checks[0].Amount && d.FeeAmt == 123 && d.DonorId == contactDonorExisting.DonorId && d.ProgramId.Equals("9090") && d.ChargeId.Equals("1020304") && d.PymtType.Equals("check") && d.ProcessorId.Equals(contactDonorExisting.Account.ProcessorId) && d.SetupDate.Equals(checks[0].CheckDate) && d.RegisteredDonor && d.DonorAcctId == donorAcctId && d.CheckScannerBatchName.Equals("batch123") && d.CheckNumber.Equals("111111111111111")), false)) .Returns(321); var result = _fixture.CreateDonationsForBatch(new CheckScannerBatch { Name = "batch123", ProgramId = 9090 }); _checkScannerDao.VerifyAll(); _donorService.VerifyAll(); _mpDonorService.VerifyAll(); _paymentService.VerifyAll(); Assert.NotNull(result); Assert.NotNull(result.Checks); Assert.AreEqual(1, result.Checks.Count); Assert.AreEqual(BatchStatus.Exported, result.Status); }
public void TestCreateDonationsForBatchNoDonorAccount() { var checks = new List <CheckScannerCheck> { new CheckScannerCheck { Id = 44444, DonorId = 444444, AccountNumber = "444", Address = new crds_angular.Models.Crossroads.Stewardship.Address { Line1 = "4 line 1", Line2 = "4 line 2", City = "4 city", State = "4 state", PostalCode = "4 postal" }, Amount = 444400, CheckDate = DateTime.Now.AddHours(3), CheckNumber = "44444", Name1 = "4 name 1", Name2 = "4 name 2", RoutingNumber = "4040", ScanDate = DateTime.Now.AddHours(4) } }; const string encryptedKey = "PH/rty1234"; const string decrypAcct = "6015268542"; const string decryptAccountLast4 = "4288"; const string decryptRout = "042000314"; const string donorAcctId = "440044"; string nonAccountProcessorAccountId = "src_789"; string nonAccountProcessorId = "856"; _checkScannerDao.Setup(mocked => mocked.GetChecksForBatch("batch123")).Returns(checks); _checkScannerDao.Setup(mocked => mocked.UpdateBatchStatus("batch123", BatchStatus.Exported)).Returns(new CheckScannerBatch()); _checkScannerDao.Setup(mocked => mocked.UpdateCheckStatus(44444, true, null)); // donor without account for ez scan check var contactDonorNonExistingStripeCustomer = new MpContactDonor { ProcessorId = "cus_444000444", DonorId = 444444, ContactId = 444444, RegisteredUser = true, Account = new MpDonorAccount { DonorAccountId = 440044, Token = "tok986" } }; var contactDonorNonExistingStripeCustomerWithoutAccount = new MpContactDonor { ProcessorId = "cus_444000444", DonorId = 444444, ContactId = 444444, RegisteredUser = true }; var stripeCustomer = new StripeCustomer { id = "856", default_source = "src_789" }; var nonAccountStripeCustomer = new StripeCustomer { id = "src_789" }; var mockChargeNonExistingStripeCustomer = new StripeCharge { Id = "9080706050", Source = new StripeSource() { id = "ba_dgsttety6737hjjhweiu398765" } }; _donorService.Setup(mocked => mocked.GetContactDonorForDonorAccount(checks[0].AccountNumber, checks[0].RoutingNumber)).Returns((MpContactDonor)null); _donorService.Setup(mocked => mocked.GetContactDonorForDonorId(444444)).Returns(contactDonorNonExistingStripeCustomerWithoutAccount); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(checks[0].AccountNumber)).Returns(decrypAcct + "88"); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(checks[0].RoutingNumber)).Returns(decryptRout + "88"); _paymentService.Setup(mocked => mocked.CreateToken(decrypAcct + "88", decryptRout + "88", checks[0].Name1)).Returns(new StripeToken { Id = "tok986" }); _paymentService.Setup(mocked => mocked.CreateCustomer(null, contactDonorNonExistingStripeCustomer.ContactId.ToString() + " Scanned Checks")).Returns(stripeCustomer); _paymentService.Setup(mocked => mocked.AddSourceToCustomer(stripeCustomer.id, "tok986")).Returns(nonAccountStripeCustomer); _mpDonorService.Setup( mocked => mocked.CreateDonorAccount(null, decryptRout + "88", decryptAccountLast4, encryptedKey + "88", 444444, nonAccountProcessorAccountId, nonAccountProcessorId)).Returns(int.Parse(donorAcctId)); _mpDonorService.Setup(mocked => mocked.CreateHashedAccountAndRoutingNumber(decrypAcct + "88", decryptRout + "88")).Returns(encryptedKey + "88"); _donorService.Setup( mocked => mocked.CreateOrUpdateContactDonor( It.IsAny <MpContactDonor>(), It.IsAny <string>(), string.Empty, string.Empty, string.Empty, It.IsAny <string>(), It.IsAny <DateTime>())) .Returns(contactDonorNonExistingStripeCustomerWithoutAccount); _paymentService.Setup( mocked => mocked.ChargeCustomer(stripeCustomer.id, stripeCustomer.default_source, checks[0].Amount, contactDonorNonExistingStripeCustomer.DonorId, checks[0].CheckNumber)).Returns(mockChargeNonExistingStripeCustomer); _mpDonorService.Setup(mocked => mocked.CreateHashedAccountAndRoutingNumber(decrypAcct + "88", decryptRout + "88")).Returns(encryptedKey + "88"); _mpDonorService.Setup( mocked => mocked.CreateDonationAndDistributionRecord( It.Is <MpDonationAndDistributionRecord>(d => d.DonationAmt == checks[0].Amount && d.FeeAmt == null && d.DonorId == contactDonorNonExistingStripeCustomerWithoutAccount.DonorId && d.ProgramId.Equals("9090") && d.ChargeId.Equals("9080706050") && d.PymtType.Equals("check") && d.ProcessorId.Equals(nonAccountProcessorId) && d.SetupDate.Equals(checks[0].CheckDate) && d.RegisteredDonor && d.DonorAcctId == donorAcctId && d.CheckScannerBatchName.Equals("batch123") && d.CheckNumber.Equals("44444")), false)) .Returns(654); var result = _fixture.CreateDonationsForBatch(new CheckScannerBatch { Name = "batch123", ProgramId = 9090 }); _checkScannerDao.VerifyAll(); _donorService.VerifyAll(); _mpDonorService.VerifyAll(); _paymentService.VerifyAll(); Assert.NotNull(result); Assert.NotNull(result.Checks); Assert.AreEqual(1, result.Checks.Count); Assert.AreEqual(BatchStatus.Exported, result.Status); }
public void TestCreateForCreateDonorAccount() { var check = new CheckScannerCheck { Id = 11111, DonorId = 222, AccountNumber = "P/H+3ccB0ZssORkd+YyJzA==", Address = new crds_angular.Models.Crossroads.Stewardship.Address { Line1 = "1 line 1", Line2 = "1 line 2", City = "1 city", State = "1 state", PostalCode = "1 postal" }, Amount = 1111, CheckDate = DateTime.Now.AddHours(1), CheckNumber = "11111", Name1 = "1 name 1", Name2 = "1 name 2", RoutingNumber = "TUbiKZ/Vw1l6uyGCYIIUMg==", ScanDate = DateTime.Now.AddHours(2) }; var contactDonorByDonorId = new MpContactDonor { ProcessorId = "333000333", DonorId = 333333, ContactId = 3333 }; var contactDonorNew = new MpContactDonor { ProcessorId = "222000222", DonorId = 222222, RegisteredUser = false, Account = new MpDonorAccount { ProcessorAccountId = "py_dgsttety6737hjjhweiu3" } }; var token = new StripeToken { Id = "12t4token" }; const string encryptedKey = "PH/rty1234"; const string decrypAcct = "6015268542"; const string decryptRout = "042000314"; _donorService.Setup(mocked => mocked.GetContactDonorForDonorId(check.DonorId.Value)).Returns(contactDonorByDonorId); _donorService.Setup(mocked => mocked.GetContactDonorForDonorAccount(check.AccountNumber, check.RoutingNumber)).Returns((MpContactDonor)null); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(check.AccountNumber)).Returns(decrypAcct); _mpDonorService.Setup(mocked => mocked.DecryptCheckValue(check.RoutingNumber)).Returns(decryptRout); _paymentService.Setup(mocked => mocked.CreateToken(decrypAcct, decryptRout, check.Name1)).Returns(token); _donorService.Setup( mocked => mocked.CreateOrUpdateContactDonor( It.Is <MpContactDonor>( o => o.Details.DisplayName.Equals(check.Name1) && o.Details.Address.Line1.Equals(check.Address.Line1) && o.Details.Address.Line2.Equals(check.Address.Line2) && o.Details.Address.City.Equals(check.Address.City) && o.Details.Address.State.Equals(check.Address.State) && o.Details.Address.PostalCode.Equals(check.Address.PostalCode) && o.Account == null), string.Empty, string.Empty, string.Empty, string.Empty, null, It.IsAny <DateTime>())) .Returns(contactDonorNew); _mpDonorService.Setup(mocked => mocked.CreateHashedAccountAndRoutingNumber(decrypAcct, decryptRout)).Returns(encryptedKey); _mpDonorService.Setup(mocked => mocked.UpdateDonorAccount(encryptedKey, contactDonorNew.Account.ProcessorAccountId, contactDonorNew.ProcessorId)); var result = _fixture.CreateDonor(check); _donorService.VerifyAll(); Assert.NotNull(result); Assert.AreEqual(contactDonorNew, result); Assert.AreEqual(decryptRout, result.Account.RoutingNumber); Assert.AreEqual(decrypAcct, result.Account.AccountNumber); Assert.AreEqual(AccountType.Checking, result.Account.Type); }