Example #1
0
        public bool PurchaseProduct(IProduct product, IEnumerable <ICashDenomination> deposits,
                                    out IEnumerable <ICashDenomination> change, out string failureReason)
        {
            change = cashStore.DepositToStore(product.Cost, deposits, out string depositRejctReason);
            if (!string.IsNullOrEmpty(depositRejctReason))
            {
                failureReason = $"Unable to deposit cash: {depositRejctReason}";
                return(false);
            }

            //try to withdraw the product
            if (!productCatalogue.WithdrawProduct(product, out string withdrawFailReason))
            {
                failureReason = $"Unable to withdraw item: {withdrawFailReason}";
                change        = deposits;
                return(false);
            }

            failureReason = string.Empty;
            return(true);
        }