Example #1
0
        public CheckoutState Apply(CheckoutState checkoutState)
        {
            if (checkoutState.DiscountableItemsTotal == 0)
            {
                return(ToNotAppliedState(checkoutState));
            }

            var discountToApply = Math.Min(checkoutState.DiscountableItemsTotal, _value);
            var newBasketTotal  = checkoutState.CurrentTotal - discountToApply;

            return(checkoutState.ToNewState(newBasketTotal, DiscountResult.CreateApplied(_id)));
        }
Example #2
0
        private CheckoutState ToNotAppliedState(CheckoutState checkoutState)
        {
            var notAppliedResult = DiscountResult.CreateNotApplied(_id, GetNotAppliedMessage());

            return(checkoutState.ToNewState(checkoutState.CurrentTotal, notAppliedResult));
        }