Beispiel #1
0
        private IHttpActionResult UpdateDonor(string token, UpdateDonorDTO dto)
        {
            MpContactDonor mpContactDonor;
            SourceData     sourceData;

            try
            {
                mpContactDonor =
                    token == null?
                    _donorService.GetContactDonorForEmail(dto.EmailAddress)
                        :
                        _donorService.GetContactDonorForAuthenticatedUser(token);

                sourceData = _stripePaymentService.UpdateCustomerSource(mpContactDonor.ProcessorId, dto.StripeTokenId);
            }
            catch (PaymentProcessorException stripeException)
            {
                return(stripeException.GetStripeResult());
            }
            catch (ApplicationException applicationException)
            {
                var apiError = new ApiErrorDto("Error calling Ministry Platform" + applicationException.Message, applicationException);
                throw new HttpResponseException(apiError.HttpResponseMessage);
            }

            //return donor
            var donor = new DonorDTO
            {
                Id            = mpContactDonor.DonorId,
                ProcessorId   = mpContactDonor.ProcessorId,
                DefaultSource = new DefaultSourceDTO
                {
                    credit_card = new CreditCardDTO
                    {
                        brand       = sourceData.brand,
                        last4       = sourceData.last4,
                        address_zip = sourceData.address_zip,
                        exp_date    = sourceData.exp_month + sourceData.exp_year
                    },
                    bank_account = new BankAccountDTO
                    {
                        last4             = sourceData.bank_last4,
                        routing           = sourceData.routing_number,
                        accountHolderName = sourceData.account_holder_name,
                        accountHolderType = sourceData.account_holder_type
                    }
                },
                RegisteredUser = mpContactDonor.RegisteredUser,
                Email          = mpContactDonor.Email
            };

            return(Ok(donor));
        }
Beispiel #2
0
 public IHttpActionResult UpdateDonor([FromBody] UpdateDonorDTO dto)
 {
     return(Authorized(token => UpdateDonor(token, dto), () => UpdateDonor(null, dto)));
 }
        public void TestUpdateDonorStripeUpdateThrowsStripeException()
        {
            _fixture.Request.Headers.Authorization = null;
            var dto = new UpdateDonorDTO
            {
                DonorId = "123",
                EmailAddress = "*****@*****.**",
                StripeTokenId = "456"
            };

            var contactDonor = new ContactDonor
            {
                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 void TestUpdateDonorLookupThrowsApplicationException()
        {
            _fixture.Request.Headers.Authorization = null;
            var dto = new UpdateDonorDTO
            {
                DonorId = "123",
                EmailAddress = "*****@*****.**",
                StripeTokenId = "456"
            };

            var applicationException = new ApplicationException("whoa nelly");
            _donorService.Setup(mocked => mocked.GetContactDonorForEmail("*****@*****.**")).Throws(applicationException);

            try
            {
                _fixture.UpdateDonor(dto);
                Assert.Fail("Expected exception was not thrown");
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(HttpResponseException), e.GetType());
            }

            _donorService.VerifyAll();
            _paymentService.VerifyAll();
        }
        public void TestUpdateDonorRegisteredDonor()
        {
            var dto = new UpdateDonorDTO
            {
                DonorId = "123",
                EmailAddress = "*****@*****.**",
                StripeTokenId = "456"
            };

            var contactDonor = new ContactDonor
            {
                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 TestUpdateDonorGuestDonor()
        {
            _fixture.Request.Headers.Authorization = null;
            var dto = new UpdateDonorDTO
            {
                DonorId = "123",
                EmailAddress = "*****@*****.**",
                StripeTokenId = "456"
            };

            var contactDonor = new ContactDonor
            {
                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);
        }
        private IHttpActionResult UpdateDonor(string token, UpdateDonorDTO dto)
        {
            ContactDonor contactDonor;
            SourceData sourceData;

            try
            {
                contactDonor = 
                    token == null ? 
                    _donorService.GetContactDonorForEmail(dto.EmailAddress) 
                    : 
                    _donorService.GetContactDonorForAuthenticatedUser(token);
              
                sourceData = _stripePaymentService.UpdateCustomerSource(contactDonor.ProcessorId, dto.StripeTokenId);
            }
            catch (PaymentProcessorException stripeException)
            {
                return (stripeException.GetStripeResult());
            }
            catch (ApplicationException applicationException)
            {
                var apiError = new ApiErrorDto("Error calling Ministry Platform" + applicationException.Message, applicationException);
                throw new HttpResponseException(apiError.HttpResponseMessage);
            }

            //return donor
            var donor = new DonorDTO
            {
                Id = contactDonor.DonorId,
                ProcessorId = contactDonor.ProcessorId,
                DefaultSource = new DefaultSourceDTO
                {
                    credit_card = new CreditCardDTO
                    {
                        brand = sourceData.brand,
                        last4 = sourceData.last4,
                        address_zip = sourceData.address_zip,
                        exp_date = sourceData.exp_month + sourceData.exp_year
                    },
                    bank_account = new BankAccountDTO
                    {
                        last4 = sourceData.bank_last4,
                        routing = sourceData.routing_number
                    }
                },
                RegisteredUser = contactDonor.RegisteredUser,
                Email = contactDonor.Email
            };

            return Ok(donor);
        }