Пример #1
0
        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);
        }
Пример #2
0
        public void TestCancelRecurringGiftStripeError()
        {
            var       authUserToken   = _authType + " " + _authToken;
            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.CancelRecurringGift(authUserToken, recurringGiftId)).Throws(stripeException);

            var response = _fixture.CancelRecurringGift(recurringGiftId);

            _donorService.VerifyAll();
            Assert.IsNotNull(response);
            Assert.IsInstanceOf <RestHttpActionResult <PaymentProcessorErrorResponse> >(response);
            var err = (RestHttpActionResult <PaymentProcessorErrorResponse>)response;

            Assert.AreEqual(HttpStatusCode.Forbidden, err.StatusCode);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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();
        }
Пример #5
0
 private PaymentProcessorException AddGlobalErrorMessage(PaymentProcessorException e)
 {
     // This same logic exists on the Angular side in app/give/services/payment_service.js.
     // This is because of the Stripe "tokens" call, which goes directly to Stripe, not via our API.  We
     // are implementing the same here in the interest of keeping our application somewhat agnostic to
     // the underlying payment processor.
     if ("abort".Equals(e.Type) || "abort".Equals(e.Code))
     {
         e.GlobalMessage = _contentBlockService["paymentMethodProcessingError"];
     }
     else if ("card_error".Equals(e.Type))
     {
         if (e.Code != null && ("card_declined".Equals(e.Code) || e.Code.Matches("^incorrect") || e.Code.Matches("^invalid")))
         {
             e.GlobalMessage = _contentBlockService["paymentMethodDeclined"];
         }
         else if ("processing_error".Equals(e.Code))
         {
             e.GlobalMessage = _contentBlockService["paymentMethodProcessingError"];
         }
     }
     else if ("bank_account".Equals(e.Param))
     {
         if ("invalid_request_error".Equals(e.Type))
         {
             e.GlobalMessage = _contentBlockService["paymentMethodDeclined"];
         }
     }
     else
     {
         e.GlobalMessage = _contentBlockService["failedResponse"];
     }
     return(e);
 }
Пример #6
0
        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();
        }