Example #1
0
        public void TestSaveStripeCustomer_CreateStripeAccount()
        {
            //Arrange
            StripeCCAccount stripeAccount = new StripeCCAccount()
            {
                FirstName       = "FirstName",
                LastName        = "LastName",
                Email           = "*****@*****.**",
                StripeId        = "strp_asdf!@#$",
                CCNumber        = "4242424242424242",
                ExpirationMonth = "11",
                ExpirationYear  = "2020",
                CVV             = "123"
            };


            var customerService = new Moq.Mock <StripeCustomerService>("test");

            //customerService.Setup(m => m.Get(It.IsAny<string>(), It.IsAny<StripeRequestOptions>()))
            //    .Throws<StripeException>();



            customerService.Setup(m => m.Create(It.IsAny <StripeCustomerCreateOptions>(), It.IsAny <StripeRequestOptions>())).Returns(new StripeCustomer()
            {
                //Email = "*****@*****.**",
                Id = "StripeCreateId"
            });

            //Act
            StripeCCAccount responseStripeAccount = CCAccount.SaveStripeCustomer(customerService.Object, stripeAccount);

            //Assert
            Assert.AreEqual("StripeCreateId", responseStripeAccount.StripeId, "Account was not created correctly.");
        }
Example #2
0
        public void TestSaveStripeCustomer_UpdateStripeAccount_FailedToLocate()
        {
            //Arrange
            StripeCCAccount stripeAccount = new StripeCCAccount()
            {
                FirstName       = "FirstName",
                LastName        = "LastName",
                Email           = "*****@*****.**",
                StripeId        = "strp_asdf!@#$",
                CCNumber        = "4242424242424242",
                ExpirationMonth = "11",
                ExpirationYear  = "2020",
                CVV             = "123"
            };


            var customerService = new Moq.Mock <StripeCustomerService>("test");

            customerService.Setup(m => m.Get(It.IsAny <string>(), It.IsAny <StripeRequestOptions>()))
            .Throws <StripeException>();

            customerService.Setup(m => m.Update(It.IsAny <string>(), It.IsAny <StripeCustomerUpdateOptions>(), It.IsAny <StripeRequestOptions>())).Returns(new StripeCustomer()
            {
                //Email = "*****@*****.**",
                Id = "StripeUpdateId"
            });

            //Act
            StripeCCAccount responseStripeAccount = CCAccount.SaveStripeCustomer(customerService.Object, stripeAccount);


            //Assert
            Assert.AreEqual("Stripe failed to locate the account.", responseStripeAccount.ErrorMessage, "Error message does not match.");
        }
Example #3
0
        public ActionResult EditProfile(EditProfileViewModel editProfileViewModel)
        {
            var manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));

            //Get Users FullName and StripeId from UserManager
            var currentUser = manager.FindById(User.Identity.GetUserId());

            currentUser.FirstName = editProfileViewModel.FirstName;
            currentUser.LastName  = editProfileViewModel.LastName;


            StripeCCAccount stripeAccount = new StripeCCAccount()
            {
                FirstName       = editProfileViewModel.FirstName,
                LastName        = editProfileViewModel.LastName,
                Email           = currentUser.Email,
                StripeId        = currentUser.StripeId,
                CCNumber        = editProfileViewModel.CCNumber,
                ExpirationMonth = editProfileViewModel.ExpirationMonth,
                ExpirationYear  = editProfileViewModel.ExpirationYear,
                CVV             = editProfileViewModel.CVV
            };

            var customerService = new StripeCustomerService();

            StripeCCAccount responseStripeAccount = CCAccount.SaveStripeCustomer(customerService, stripeAccount);

            currentUser.StripeId = responseStripeAccount.StripeId;

            manager.Update(currentUser);

            //Clearing the ModelState to remove all the customer sencitive info ASAP.
            ModelState.Clear();

            editProfileViewModel.CCNumber        = null;
            editProfileViewModel.CVV             = null;
            editProfileViewModel.ExpirationMonth = null;
            editProfileViewModel.ExpirationYear  = null;

            return(View(editProfileViewModel));
        }
Example #4
0
        public void TestSaveStripeCustomer_CreateStripeAccount_InvalidNumber()
        {
            //Arrange
            StripeCCAccount stripeAccount = new StripeCCAccount()
            {
                FirstName       = "FirstName",
                LastName        = "LastName",
                Email           = "*****@*****.**",
                StripeId        = "strp_asdf!@#$",
                CCNumber        = "4242424242424242",
                ExpirationMonth = "11",
                ExpirationYear  = "2020",
                CVV             = "123"
            };


            var customerService = new Moq.Mock <StripeCustomerService>("test");

            customerService.Setup(m => m.Get(It.IsAny <string>(), It.IsAny <StripeRequestOptions>()))
            .Throws <StripeException>();

            customerService.Setup(
                m => m.Create(It.IsAny <StripeCustomerCreateOptions>(), It.IsAny <StripeRequestOptions>()))
            .Throws(new StripeException()
            {
                StripeError = new StripeError()
                {
                    Code = "invalid_number"
                }
            });

            //Act
            StripeCCAccount responseStripeAccount = CCAccount.SaveStripeCustomer(customerService.Object, stripeAccount);

            //Assert
            Assert.AreEqual(false, responseStripeAccount.Success, "Account creation did not fail as was expected.");
            Assert.AreEqual("The Credit Card Number is invalid.", responseStripeAccount.ErrorMessage, "Error message is wrong");
        }