public void BuyProduct(Product[] productsToBuy, Card creditCard)
        {
            _productToBuy = new List<Product>(productsToBuy);
            _creditCard = creditCard;

            CheckNextProductToBuy();
        }
 private void ProcessPayment(Card creditCard, double totalAmount)
 {
     // Check credit limit of the customer's card, and charge the payment
     for (int i = 0; i < _creditCards.Length; i++)
     {
         // If credit card found
         if (_creditCards[i].Name == creditCard.Name &&
                 _creditCards[i].Number == creditCard.Number)
         {
             if (_creditCards[i].CreditLimit > (_creditCards[i].CumulatedAmount + totalAmount))
             {
                 // Process payment using the provided credit card
                 _creditCards[i].CumulatedAmount += totalAmount;
             }
         }
     }
 }
        protected override void Run()
        {
            // Reset
            List<Product> productsToBuy;
            Product productForOneClickCheckout;
            Product tempProduct;
            Card creditCard;

            productsToBuy = new List<Product>();

            // Add books
            tempProduct = new Product();
            tempProduct.Name = "Software Engineering (10th Edition)";
            tempProduct.Price = 165.20;
            productsToBuy.Add(tempProduct);

            tempProduct = new Product();
            tempProduct.Name = "Introduction to Programming Using C#";
            tempProduct.Price = 24.95;
            productsToBuy.Add(tempProduct);

            // Book for one-click checkout
            productForOneClickCheckout = new Product();
            productForOneClickCheckout.Name = "Introduction to Programming Using C++";
            productForOneClickCheckout.Price = 30.99;

            _totalNumberOfBooks = 3;

            // Add credit card
            creditCard = new Card();
            creditCard.Number = "12345";
            creditCard.Name = "John Doe";
            //creditCard.CreditLimit = 200.00;

            // Begin simulation
            _customer.BuyProduct(productsToBuy.ToArray(), creditCard);
            _customer.OneClickOrder(productForOneClickCheckout, creditCard);
        }
        private void ProcessOneClickOrder(Product product, Card creditCard)
        {
            Package package;

            SendMessage(typeof(Customer), "ProcessingOneClickOrder");

            package = new Package();
            package.Add(product);

            SendMessage(typeof(Visa), "ChargeRequest", creditCard, product.Price, package);
        }
        private void MakePayment(Card creditCard, Package package)
        {
            double totalAmount;

            totalAmount = 0;

            // Sum up all prices
            foreach (Product p in _user_cart)
            {
                totalAmount += p.Price;
            }

            // Send payment info to the credit card company
            SendMessage(typeof(Visa), "ChargeRequest", creditCard, totalAmount, package);
        }
        public void OneClickOrder(Product productToBuy, Card creditCard)
        {
            _creditCard = creditCard;

            SendMessage(typeof(Amazon), "OneClickOrder", productToBuy, creditCard);
        }