Inheritance: System.Exception
Example #1
0
        public void CancelSubscription_InvalidParameters_ThrowsStripeException()
        {
            //Arrange
            StripeException exception = new StripeException();
            exception.StripeError = new StripeError();
            exception.StripeError.ErrorType = "invalid_request";

            Mock<StripeSubscriptionService> custSubService = new Mock<StripeSubscriptionService>(null);
            custSubService.Setup(sub => sub.Cancel(It.IsAny<string>(), It.IsAny<string>(), false, null)).Throws(exception);
            stripeAccessor = new StripeAccessorService(custSubService.Object, charService.Object, cusService.Object);

            //Act
            string returnMessage = stripeAccessor.CancelSubscription(customerId, subscriptionId);

            //Assert
            Assert.That(returnMessage, Is.EqualTo("invalid_request"));
        }
Example #2
0
 public static ChargeResultDto MapChargeErrorToChargeResultDto(Stripe.StripeException ex)
 {
     return(new ChargeResultDto
     {
         IsSuccess = false,
         Error = new ChargeErrorDto()
         {
             ChargeId = ex.StripeError.ChargeId,
             Code = ex.StripeError.Code,
             DeclineCode = ex.StripeError.DeclineCode,
             Error = ex.StripeError.Error,
             ErrorDescription = ex.StripeError.ErrorDescription,
             ErrorType = ex.StripeError.ErrorType,
             Message = ex.StripeError.Message,
             Parameter = ex.StripeError.Parameter
         }
     });
 }
Example #3
0
        /// <summary>
        ///     Converts the <see cref="StripeException"/> into a non-Stripe.net exception
        /// </summary>
        /// <param name="ex">
        ///     The <see cref="StripeException"/> to convert
        /// </param>
        /// <returns>
        ///     A <see cref="StripeServiceException"/> representing the original 
        ///     <see cref="StripeException"/>
        /// </returns>
        protected virtual StripeServiceException HandleStripeException(StripeException ex)
        {
            string message;
            StripeExceptionType type;

            // Note: Stripe says their card_error messages are safe to display to the user
            if (ex.StripeError.ErrorType == "card_error")
            {
                message = ex.Message;
                type = StripeExceptionType.CardError;
            }
            else if (ex.HttpStatusCode == HttpStatusCode.Unauthorized)
            {
                // Note: We want to log this as it means we don't have a valid API key
                Debug.WriteLine("Stripe API Key is Invalid");
                Debug.WriteLine(ex.Message);

                type = StripeExceptionType.ApiKeyError;
                message = "An error occured while talking to one of our backends. Sorry!";
            }
            else
            {
                type = StripeExceptionType.UnknownError;
                message =
                    "An error occured while talking to one of our backends. Sorry!";
            }

            return new StripeServiceException(message, type, ex);
        }
Example #4
0
        void IEmailHelper.SendStripeError(StripeException error)
        {
            Guard.ArgumentNotNull(error.StripeError, "stripeError");
            Guard.ArgumentNotNull(error.StripeError.ErrorType, "errorType");
            Guard.ArgumentNotNull(error.StripeError.Message, "message");

            AlternateView plainView = null;
            if (emailErrors == "On")
            {
                try
                {
                    string body = String.Empty;
                    //first we create the Plain Text part
                    plainView = AlternateView.CreateAlternateViewFromString(error.StripeError.Code + error.StripeError.ErrorType + error.StripeError.Message, null, "text/plain");

                    List<AlternateView> views = new List<AlternateView>();
                    views.Add(plainView);
                    SendMail(adminEmail, "Stripe Error", views);
                }
                catch
                {
                }
            }
        }
Example #5
0
        public void UpdateCustomer_InvalidParameters_ThrowsStripeException()
        {
            //Arrange
            StripeException exception = new StripeException();
            exception.StripeError = new StripeError();
            exception.StripeError.ErrorType = "invalid_request";

            Mock<StripeCustomerService> custCustService = new Mock<StripeCustomerService>(null);
            custCustService.Setup(cust => cust.Update(It.IsAny<string>(), It.IsAny<StripeCustomerUpdateOptions>(), null))
                .Throws(exception);
            stripeAccessor = new StripeAccessorService(subService.Object, charService.Object, custCustService.Object);

            //Act
            string returnedException = stripeAccessor.UpdateCustomer(customerId, "email", "Hal", "Wilkerson");

            //Assert
            Assert.That(returnedException, Is.EqualTo("invalid_request"));
        }
Example #6
0
        public void SubscribeCustomer_InvalidParameters_ThrowsStripeException()
        {
            //Arrange
            StripeException exception = new StripeException();
            exception.StripeError = new StripeError();
            exception.StripeError.ErrorType = "invalid_request";

            Mock<StripeSubscriptionService> custSubService = new Mock<StripeSubscriptionService>(null);
            custSubService.Setup(sub => sub.Create(It.IsAny<string>(), It.IsAny<string>(), null, null)).Throws(exception);
            stripeAccessor = new StripeAccessorService(custSubService.Object, charService.Object, cusService.Object);

            //Act
            string returnedException = stripeAccessor.SubscribeCustomer(customerId, planId);

            //Arrange
            Assert.That(returnedException, Is.EqualTo("invalid_request"));
        }
Example #7
0
        public void GetCustomer_InvalidParameters_ThrowsStripeException()
        {
            //Arrange
            StripeException exception = new StripeException();
            exception.StripeError = new StripeError();
            CreateCustomerError error;
            exception.StripeError.ErrorType = "invalid_request";

            Mock<StripeCustomerService> custCustService = new Mock<StripeCustomerService>(null);
            custCustService.Setup(cust => cust.Get(It.IsAny<string>(), null))
                .Throws(exception);
            stripeAccessor = new StripeAccessorService(subService.Object, charService.Object, custCustService.Object);

            //Act
            StripeObject returnedException = stripeAccessor.GetCustomer(customerId);
            error = (CreateCustomerError)returnedException;

            //Assert
            Assert.That(returnedException, Is.InstanceOf<CreateCustomerError>());
            Assert.That(error.Error_Type, Is.EqualTo("invalid_request"));
        }
Example #8
0
        public void ChargeCustomer_InvalidParameters_ThrowsStripeException()
        {
            //Arrange
            StripeException exception = new StripeException();
            exception.StripeError = new StripeError();
            exception.StripeError.ErrorType = "invalid_request";

            Mock<StripeChargeService> custChargeService = new Mock<StripeChargeService>(null);
            custChargeService.Setup(charg => charg.Create(It.IsAny<StripeChargeCreateOptions>(), null))
                .Throws(exception);
            stripeAccessor = new StripeAccessorService(subService.Object, custChargeService.Object, cusService.Object);

            //Act
            String returnedException = stripeAccessor.ChargeCustomer(customerId, 2, 15, 2016, 1, 25);

            //Assert
            Assert.That(returnedException, Is.EqualTo("invalid_request"));
        }