public void ChargeCard(PaymentDetails paymentDetails, 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(Cart cart, PaymentDetails paymentDetails) : base(cart) { _paymentDetails = paymentDetails; _paymentProcessor = new PaymentProcessor(); _reservationService = new ReservationService(); _notificationService = new NotificationService(); }
public void Checkout(Cart cart, PaymentDetails paymentDetails, bool notifyCustomer) { if (paymentDetails.PaymentMethod == PaymentMethod.CreditCard) { ChargeCard(paymentDetails, cart); } ReserveInventory(cart); if (notifyCustomer) { NotifyCustomer(cart); } }
// you will see that most of the work is done in the "CheckOut" Method. public void Checkout(Cart cart, PaymentDetails paymentDetails, bool notifyCustomer) { // Problem 1: "Cash" Transactions do not need "Credit Card" Processing if (paymentDetails.PaymentMethod == PaymentMethod.CreditCard) { ChargeCard(paymentDetails, cart); } // Problem 2: Point Of Sale Transactions Do not need Inventory Reservations ReserveInventory(cart); // Problem 3: Point Of Sale Transactions do not need email notifications // the customer does not provide an email // the customer knows immediately that the order was success if (notifyCustomer) { NotifyCustomer(cart); } // Problem 4: Any Change to notifications, Credit Card processing, Or Inventory // management will affect "Order" as well as the "Web" and "Point Of Sale" // implementations of "Order" }
public void ProcessCreditCard(PaymentDetails paymentDetails, decimal amount) { throw new NotImplementedException(); }
public PoSCreditOrder(Cart cart, PaymentDetails paymentDetails) : base(cart) { _paymentDetails = paymentDetails; _paymentProcessor = new PaymentProcessor(); }