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 void Checkout(Cart cart, PaymentDetails paymentDetails, bool notifyCustomer) { if (paymentDetails.PaymentMethod == PaymentMethod.CreditCard) { ChargeCard(paymentDetails, cart); } ReserveInventory(cart); if (notifyCustomer) { NotifyCustomer(cart); } }
public Order(Cart cart, PaymentDetails paymentDetails, INotificationService notifyCustomer) { _cart = cart; _paymentDetails = paymentDetails; _notifyCustomer = notifyCustomer; }