コード例 #1
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.");
        }
コード例 #2
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.");
        }
コード例 #3
0
        private bool verifyAccount(CCAccount myAccount, CCCustomer myCustomer)
        {
            bool verified = false;

            //get specific account row from db
            SqlCommand objCommand = new SqlCommand();

            objCommand.CommandType = CommandType.StoredProcedure;
            objCommand.CommandText = "CCGetSpecificAccount";
            objCommand.Parameters.AddWithValue("@ccNum", myAccount.CCNum);
            objDB.GetDataSetUsingCmdObj(objCommand);

            //gather required fields
            string lastName  = objDB.GetField("lastName", 0).ToString();
            string firstName = objDB.GetField("firstName", 0).ToString();
            string zip       = objDB.GetField("zip", 0).ToString();
            string ccNum     = objDB.GetField("ccNum", 0).ToString();
            string expDate   = objDB.GetField("expDate", 0).ToString();
            string cvc       = objDB.GetField("cvc", 0).ToString();
            string status    = objDB.GetField("status", 0).ToString();

            //compare each account field with db field
            if (status == "Active" && lastName == myCustomer.LastName && firstName == myCustomer.FirstName && zip == myCustomer.Zip && ccNum == myAccount.CCNum && expDate == myAccount.ExpDate && cvc == myAccount.Cvc)
            {
                verified = true;
            }

            return(verified);
        }
コード例 #4
0
        public string updateAccount(ref CCAccount myAccount, int apiKey)
        {
            string updateStatus = "failed to update account";

            if (apiKey == API_KEY)
            {
                SqlCommand objCommand = new SqlCommand();
                objCommand.CommandType = CommandType.StoredProcedure;
                objCommand.CommandText = "CCUpdateAccount";
                objCommand.Parameters.AddWithValue("@ccNum", myAccount.CCNum);
                objCommand.Parameters.AddWithValue("@expirDate", myAccount.ExpDate);
                objCommand.Parameters.AddWithValue("@status", myAccount.Status);

                decimal limit;
                Decimal.TryParse(myAccount.Limit, out limit);
                objCommand.Parameters.AddWithValue("@limit", limit);

                if (objDB.DoUpdateUsingCmdObj(objCommand) != -1)
                {
                    updateStatus = "successfully updated account";
                }
            }


            return(updateStatus);
        }
コード例 #5
0
        private string chargeAccount(CCAccount myAccount, CCTransaction myTransaction)
        {
            string transactionCode = "0";

            decimal amount = 0;

            if (Decimal.TryParse(myTransaction.Amount, out amount))
            {
                SqlCommand objCommand = new SqlCommand();
                objCommand.CommandType = CommandType.StoredProcedure;
                objCommand.CommandText = "CCGetSpecificAccount";
                objCommand.Parameters.AddWithValue("@ccNum", myAccount.CCNum);
                objDB.GetDataSetUsingCmdObj(objCommand);

                decimal balance = (decimal)objDB.GetField("balance", 0);
                decimal limit   = (decimal)objDB.GetField("creditLimit", 0);

                decimal newBalance = balance + amount;

                if (newBalance <= limit)
                {
                    SqlCommand objCommandTransaction = new SqlCommand();
                    objCommandTransaction.CommandType = CommandType.StoredProcedure;
                    objCommandTransaction.CommandText = "CCPerformTransaction";
                    objCommandTransaction.Parameters.AddWithValue("@newBalance", newBalance);
                    objCommandTransaction.Parameters.AddWithValue("@ccNum", myAccount.CCNum);

                    if (objDB.DoUpdateUsingCmdObj(objCommandTransaction) != -1)
                    {
                        transactionCode = "1"; //charge accepted

                        SqlCommand insertTransaction = new SqlCommand();
                        insertTransaction.CommandType = CommandType.StoredProcedure;
                        insertTransaction.CommandText = "CCInsertTransaction";
                        insertTransaction.Parameters.AddWithValue("@ccNum", myAccount.CCNum);
                        insertTransaction.Parameters.AddWithValue("@amount", amount);
                        insertTransaction.Parameters.AddWithValue("@type", myTransaction.Type);
                        insertTransaction.Parameters.AddWithValue("@date", myTransaction.Date);
                        insertTransaction.Parameters.AddWithValue("@time", myTransaction.Time);

                        objDB.DoUpdateUsingCmdObj(insertTransaction); //insert transaction
                    }
                }
                else
                {
                    transactionCode = "2"; //declined -- over credit limit
                }
            }
            else
            {
                transactionCode = "3"; //invalid amount
            }


            return(transactionCode);
        }
コード例 #6
0
        public string addAccount(int clientVerificationCode, int custID, ref CCAccount myAccount, int apiKey)
        {
            string addStatus = "failed to add account";

            //create customer to match client input
            CCCustomer myCustomer = new CCCustomer();

            //pull specified customer from database
            SqlCommand objCommand = new SqlCommand();

            objCommand.CommandType = CommandType.StoredProcedure;
            objCommand.CommandText = "CCGetSpecificCustomer";
            objCommand.Parameters.AddWithValue("@custID", custID);

            DataSet ds = objDB.GetDataSetUsingCmdObj(objCommand);

            //set property
            myCustomer.LastName = objDB.GetField("lastName", 0).ToString();

            //create server verification code
            int serverVerificationCode = ccProc.generateVerificationCode(myCustomer);

            //check against client verfication code -- if match add account
            if (clientVerificationCode == serverVerificationCode && apiKey == API_KEY)
            {
                SqlCommand objCommand1 = new SqlCommand();
                objCommand1.CommandType = CommandType.StoredProcedure;
                objCommand1.CommandText = "CCAddAccount";
                objCommand1.Parameters.AddWithValue("@ccNum", myAccount.CCNum);
                objCommand1.Parameters.AddWithValue("@ccType", myAccount.CCType);
                objCommand1.Parameters.AddWithValue("@custID", custID);
                objCommand1.Parameters.AddWithValue("@cvc", Int32.Parse(myAccount.Cvc));
                objCommand1.Parameters.AddWithValue("@expDate", myAccount.ExpDate);
                decimal limit;
                Decimal.TryParse(myAccount.Limit, out limit);
                objCommand1.Parameters.AddWithValue("@limit", limit);

                if (objDB.DoUpdateUsingCmdObj(objCommand1) != -1)
                {
                    addStatus = "successfully added account";
                }
            }

            return(addStatus);
        }
コード例 #7
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));
        }
コード例 #8
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");
        }
コード例 #9
0
        public string[] processTransaction(ref string[] transactionInfo, int apiKey)
        {
            //create customer, transaction, and account objects
            CCCustomer    myCustomer    = new CCCustomer();
            CCAccount     myAccount     = new CCAccount();
            CCTransaction myTransaction = new CCTransaction();

            //initialize return values
            myTransaction.Date = "";
            myTransaction.Time = "";
            string acceptOrDecline = "Decline";
            string transactionCode = "0";


            //retrieve and assign verification codes
            myCustomer.LastName = transactionInfo[LNAME_INDEX];
            string serverVerificationCode = ccProc.generateVerificationCode(myCustomer).ToString();
            string clientVerificationCode = transactionInfo[CODE_INDEX];

            //check if verification codes match, if so -- proceed with account verification
            if (serverVerificationCode == clientVerificationCode && apiKey == API_KEY)
            {
                //assign values to customer and account objects
                myCustomer.FirstName = transactionInfo[FNAME_INDEX];
                myCustomer.Zip       = transactionInfo[ZIP_INDEX];
                myAccount.CCNum      = transactionInfo[CCNUM_INDEX];
                myAccount.ExpDate    = transactionInfo[DATE_INDEX];
                myAccount.Cvc        = transactionInfo[CVC_INDEX];



                //verify account information, if so -- process transaction
                if (verifyAccount(myAccount, myCustomer))
                {
                    myTransaction.Amount = transactionInfo[AMT_INDEX];
                    myTransaction.Type   = transactionInfo[TYPE_INDEX];
                    myTransaction.Date   = DateTime.Today.ToString("MM/dd/yyyy");
                    myTransaction.Time   = DateTime.Now.ToString("HH:mm");

                    //check for transaction type -- perform desired transaction
                    if (myTransaction.Type == "Payment")
                    {
                        transactionCode = makePayment(myAccount, myTransaction);

                        if (transactionCode == "1") //successful transaction
                        {
                            acceptOrDecline = "Accept";
                        }
                    }
                    else if (myTransaction.Type == "Purchase")
                    {
                        transactionCode = chargeAccount(myAccount, myTransaction);

                        if (transactionCode == "1") //successful transaction
                        {
                            acceptOrDecline = "Accept";
                        }
                    }
                    else
                    {
                        transactionCode = "99"; //unknown transaction type
                    }
                }
                else
                {
                    transactionCode = "3"; //account information invalid (unverified)
                }
            }
            else
            {
                //verification string invalid
            }

            //assign values to return array
            string[] transactionReturnInfo = new string[4];
            transactionReturnInfo[ACCEPTORDECLINE_INDEX] = acceptOrDecline;
            transactionReturnInfo[TRANSACTIONCODE_INDEX] = transactionCode;
            transactionReturnInfo[TRANSACTIONDATE_INDEX] = myTransaction.Date;
            transactionReturnInfo[TRANSACTIONTIME_INDEX] = myTransaction.Time;



            //return transaction array
            return(transactionReturnInfo);
        }