Ejemplo n.º 1
0
        public static void PaymentChoice(List <Product> shoppingCart)
        {
            decimal subTotal = 0m, salesTax = 0m, grandTotal = 0m, change = 0m;

            bool valid = false;

            Console.WriteLine();
            //displays users totals
            foreach (Product item in shoppingCart)
            {
                subTotal = Math.Round((Payment.STotal(item.Quantity, item.PriceEach) + subTotal), 2, MidpointRounding.ToZero);
                salesTax = Math.Round((Payment.Tax(subTotal) + salesTax), 2, MidpointRounding.ToZero);
            }
            grandTotal = Math.Round((Payment.GrandTotal(subTotal, salesTax)), 2, MidpointRounding.ToZero);

            //displays users shopping cart
            Console.WriteLine("You have selected the following items:\n");
            foreach (var product in shoppingCart)
            {
                Console.WriteLine($"{product.Quantity} x {product.Name} @ {product.PriceEach.ToString("C2")}");
            }

            Console.WriteLine($"\nSubtotal: {subTotal.ToString("C2")}\nSales Tax: {salesTax.ToString("C2")}\n\nGrand Total: {grandTotal.ToString("C2")}\n");

            Console.WriteLine("Continuing to Checkout screen in 5 seconds");
            Thread.Sleep(5000);

            do
            {
                //clearing screen to make it neat
                Console.Clear();

                //displays grand total to be paid
                Console.WriteLine($"Grand Total: {grandTotal.ToString("C2")}\n");

                //allows user to select method of payment
                Console.WriteLine("\nPayment choice: Cash, Credit, Check..");
                string paymentType = Validation.ValidPaymentType(Console.ReadLine());

                if (paymentType == "cash")
                {
                    //sends grandtotal to PayCash method and allows user to enter exact amount or more than needed to return change. Will not allow partial payments
                    change = Payment.PayCash(grandTotal);
                    Thread.Sleep(5000);
                    Console.Clear();

                    //sends items and change to receipt list
                    Receipt.DisplayCashReceipt(shoppingCart, change);
                }
                else if (paymentType == "credit" || paymentType == "credit card" || paymentType == "card")
                {
                    //user enters cc number
                    Console.WriteLine("Please enter your credit card number");
                    string ccNumber = Validation.ValidCreditCard(Console.ReadLine());

                    //sends cc number to Payment class to gather remaining info to validate
                    Payment.CCPayment(ccNumber);
                    Console.WriteLine("Successful! Please wait for your receipt");
                    Thread.Sleep(5000);
                    Console.Clear();

                    //sends items and cc number to receipt
                    Receipt.DisplayCreditCardReceipt(shoppingCart, ccNumber);
                }
                else if (paymentType == "check")
                {
                    //validates check number
                    Console.WriteLine("Please enter your check number");
                    int checknum = Validation.ValidCheck(Console.ReadLine());
                    Console.WriteLine("Please wait");
                    Thread.Sleep(5000);
                    Console.Clear();

                    //sends items and check number to receipt
                    Receipt.DisplayCheckReceipt(shoppingCart, checknum);
                }
            } while (valid == true);
        }