예제 #1
0
 public OnlineOrder(Refactored.Cart cart, PaymentDetails paymentDetails) : base(cart)
 {
     _notificationService = new NotificationService();
     _paymentDeatils      = paymentDetails;
     _paymentProcessor    = new PaymentProcessor();
     _reservationService  = new ReservationService();
 }
예제 #2
0
        public void ChargeCard(PaymentDetails paymentDetails, Refactored.Cart cart)
        {
            using (var paymentGateway = new PaymentGateway())
            {
                try
                {
                    paymentGateway.Credentials    = "account credentials";
                    paymentGateway.CardNumber     = paymentDetails.CreditCardNumber;
                    paymentGateway.ExpiresMonth   = paymentDetails.ExpiresMonth;
                    paymentGateway.ExpiresYear    = paymentDetails.ExpiresYear;
                    paymentGateway.NameOnCard     = paymentDetails.CardholderName;
                    paymentGateway.AmountToCharge = cart.TotalAmount();

                    paymentGateway.Charge();
                }
                catch (AvsMismatchException ex)
                {
                    throw new OrderException("The card gateway rejected the card based on the address provided.", ex);
                }
                catch (Exception ex)
                {
                    throw new OrderException("There was a problem with your card.", ex);
                }
            }
        }
 public OnlineOrder(Refactored.Cart cart,
                    PaymentDetails paymentDetails,
                    IPaymentProcessor paymentProcessor,
                    IReservationService reservationService,
                    INotificationService notificationService)
     : base(cart)
 {
     _paymentDetails      = paymentDetails;
     _paymentProcessor    = paymentProcessor;
     _reservationService  = reservationService;
     _notificationService = notificationService;
 }
예제 #4
0
        //Tightly Coupled
        public void Checkout(Refactored.Cart cart, PaymentDetails paymentDetails, bool notifyCustomer)
        {
            if (paymentDetails.PaymentMethod == PaymentMethod.CreditCard)
            {
                ChargeCard(paymentDetails, cart);
            }

            ReserveInventory(cart);

            if (notifyCustomer)
            {
                _notifyCustomer.NotifyCustomerOrderCreated(cart);
            }
        }
예제 #5
0
 public void ReserveInventory(Refactored.Cart cart)
 {
     foreach (var item in cart.Items)
     {
         try
         {
             var inventorySystem = new InventorySystem();
             inventorySystem.Reserve(item.Sku, item.Quantity);
         }
         catch (InsufficientInventoryException ex)
         {
             throw new OrderException("Insufficient inventory for item " + item.Sku, ex);
         }
         catch (Exception ex)
         {
             throw new OrderException("Problem reserving inventory", ex);
         }
     }
 }
예제 #6
0
        public void NotFailWithNoItemsNotificationNoCreditCard()
        {
            var paymentProcessor    = new FakePaymentProcessor();
            var reservationService  = new FakeReservationService();
            var notificationService = new NotificationService();
            var cart = new Refactored.Cart()
            {
                CustomerEmail = "*****@*****.**"
            };
            var paymentDetails = new PaymentDetails()
            {
                PaymentMethod = PaymentMethod.CreditCard
            };
            var order = new LosselyCoupled.OnlineOrder(cart,
                                                       paymentDetails,
                                                       paymentProcessor,
                                                       reservationService,
                                                       notificationService);

            order.Checkout();

            // if I got here, I guess it worked...
        }
 public PosCreditOrder(Refactored.Cart cart, PaymentDetails paymentDetails) : base(cart)
 {
     _paymentDetails   = paymentDetails;
     _paymentProcessor = new PaymentProcessor();
 }
예제 #8
0
 public void SetUp()
 {
     _cart = new Refactored.Cart();
 }
예제 #9
0
 public PoSCashOrder(Refactored.Cart cart)
     : base(cart)
 {
 }
예제 #10
0
 protected OrderSRP(Refactored.Cart cart)
 {
     _cart = cart;
 }