Exemple #1
0
        public void Checkout(ShoppingCart shoppingCart, PaymentDetails paymentDetails, bool notifyCustomer)
        {
            if (paymentDetails.PaymentMethod == PaymentMethod.CreditCard)
            {
                ChargeCard(paymentDetails, shoppingCart);
            }

            ReserveInventory(shoppingCart);

            if (notifyCustomer)
            {
                NotifyCustomer(shoppingCart);
            }
        }
Exemple #2
0
        public void ChargeCard(PaymentDetails paymentDetails, ShoppingCart cart)
        {
            PaymentService paymentService = new PaymentService();

            try
            {
                paymentService.Credentials    = "Credentials";
                paymentService.CardNumber     = paymentDetails.CreditCardNumber;
                paymentService.ExpiryDate     = paymentDetails.ExpiryDate;
                paymentService.NameOnCard     = paymentDetails.CardholderName;
                paymentService.AmountToCharge = cart.TotalAmount;

                paymentService.Charge();
            }
            catch (AccountBalanceMismatchException 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);
            }
        }