Beispiel #1
0
        static PaymentType TakingCheckPayments(decimal itemPrice)
        {
            string usersName;

            while (true)
            {
                Console.WriteLine("Name on the check:");
                usersName = Console.ReadLine();
                if (ValidateUserInput.StringNotEmpty(usersName) != true)
                {
                    Console.WriteLine("Name field cannot be empty.");
                }
                else if (ValidateUserInput.StringIsNumeric(usersName) == true)
                {
                    Console.WriteLine("Numbers are not allowed in the name filed. Please enter your name");
                }
                else
                {
                    break;
                }
            }

            string checkNumber;

            while (true)
            {
                Console.WriteLine("Check Number:");
                checkNumber = Console.ReadLine();
                if (Regex.IsMatch(checkNumber, @"^[0-9]{3,4}"))
                {
                    break;
                }
                if (ValidateUserInput.StringNotEmpty(checkNumber) != true)
                {
                    Console.WriteLine("Check Number field cannot be empty.");
                }
                else if (ValidateUserInput.StringIsNumeric(checkNumber) == false)
                {
                    Console.WriteLine("Invalid entry. Please enter a check number");
                }
                else
                {
                    Console.WriteLine("That was an invalid check number");
                }
            }

            Check userChoseCheck = new Check(usersName, checkNumber, itemPrice);

            return(userChoseCheck);
        }
Beispiel #2
0
        static PaymentType TakingCCPayments(decimal itemPrice)
        {
            string usersName;

            Console.WriteLine("Name on the card:");
            usersName = ValidateUserInput.ValidateUserName();

            string creditCardNumber;

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("Credit Card Number:");

                Console.WriteLine("16 digits, no spaces");
                creditCardNumber = Console.ReadLine();
                if (Regex.IsMatch(creditCardNumber, @"^[0-9]{16}"))
                {
                    break;
                }
                else if (creditCardNumber == "")
                {
                    Console.WriteLine("Credit Card number field cannot be empty.");
                }
                else if (ValidateUserInput.StringIsNumeric(creditCardNumber) == false)
                {
                    Console.WriteLine("Invalid entry. Please enter your credit number");
                }
                else
                {
                    Console.WriteLine("That was not a 16 digit number");
                }
            }

            string expirationDate;

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("Expiration date:");
                Console.WriteLine("MM/YYYY");
                expirationDate = Console.ReadLine();
                if (expirationDate == "")
                {
                    Console.WriteLine("Expiration date field cannot be empty.");
                }
                else if (Regex.IsMatch(expirationDate, @"(0[1-9]|10|11|12)/20[0-9]{2}$"))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("That was an invalid expiration date");
                }
            }

            string securityCode;

            while (true)
            {
                Console.WriteLine();
                Console.WriteLine("Security Code:");
                Console.WriteLine("4 numbers");
                securityCode = Console.ReadLine();
                Console.WriteLine();
                if (securityCode == "")
                {
                    Console.WriteLine("Security code field cannot be empty.");
                }
                else if (Regex.IsMatch(securityCode, @"^[0-9]{4}"))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("That was an invalid security code");;
                }
            }
            CreditCard userChoseCC = new CreditCard(usersName, creditCardNumber, expirationDate, securityCode, itemPrice);

            return(userChoseCC);
        }
Beispiel #3
0
        static void PaymentSelection(decimal totalFromReceipt)
        {
            PaymentDetails pd = new PaymentDetails();

            Console.WriteLine("How would you like to pay for your drinks?:");
            Console.WriteLine();
            while (true)
            {
                Console.WriteLine("1. Cash\n2. Credit Card\n3. Checks");
                string paymentMethodChosen = Console.ReadLine(); // This validation is working
                if (paymentMethodChosen == "1")
                {
                    Console.WriteLine();
                    Console.WriteLine("How much cash are you paying with?");
                    Console.WriteLine($"Your total is ${ totalFromReceipt }");

                    while (true)
                    {
                        string cashFromUserStr = Console.ReadLine();

                        if (ValidateUserInput.StringIsNumeric(cashFromUserStr) && cashFromUserStr != "" && decimal.Parse(cashFromUserStr) >= totalFromReceipt)
                        {
                            decimal cashFromUserDec = decimal.Parse(cashFromUserStr);
                            Console.WriteLine();
                            // I will need the the total receipt again
                            Console.WriteLine("==========================");
                            Console.WriteLine();
                            Console.WriteLine($"Cash Tender: \t${ cashFromUserDec }");

                            decimal changesToGiveBack = totalFromReceipt - cashFromUserDec;
                            Console.WriteLine($"Change Due: \t${-changesToGiveBack}");
                            Console.WriteLine();
                            break;
                        }
                        else
                        {
                            Console.WriteLine($"Invalid entry! Enter cash greater than { totalFromReceipt }");
                        }
                    }
                    break;
                }
                else if (paymentMethodChosen == "2")
                {
                    PaymentType pt = TakingCCPayments(totalFromReceipt);// the value coming into itemprice needs to come from the total price of item already purchased
                    pd.TakingPayment(pt);
                    break;
                }
                else if (paymentMethodChosen == "3")
                {
                    PaymentType pt = TakingCheckPayments(totalFromReceipt);
                    pd.TakingPayment(pt);
                    break;
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Invalid entry. Choose a payment method:");
                }
            }

            Console.WriteLine("Thank you for your shopping at Coffee/Tea! \nHave a nice day!");
            Console.WriteLine();

            List <Drinks> menu = CreateMenu();

            DisplayMenu(menu);
        }