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))); }
private CheckoutState ToNotAppliedState(CheckoutState checkoutState) { var notAppliedResult = DiscountResult.CreateNotApplied(_id, GetNotAppliedMessage()); return(checkoutState.ToNewState(checkoutState.CurrentTotal, notAppliedResult)); }