コード例 #1
0
        private static CheckoutResult ValidateMasterCard(int number)
        {
            if (number.ToString().EndsWith('9'))
            {
                return(CheckoutResult.StaticFailure);
            }

            return(CheckoutResult.Success("MasterCard"));
        }
コード例 #2
0
        private static CheckoutResult CheckoutWithCheck(decimal amount, Check check)
        {
            if (check.Number.ToString().EndsWith('7'))
            {
                return(CheckoutResult.StaticFailure);
            }

            return(CheckoutResult.Success("check for " + amount.ToString("#.00") + "$"));
        }
コード例 #3
0
        private static CheckoutResult ValidateVisa(int number)
        {
            if (number.ToString().EndsWith('3'))
            {
                return(CheckoutResult.StaticFailure);
            }

            return(CheckoutResult.Success("Visa"));
        }
コード例 #4
0
        private static CheckoutResult CheckoutWithCard(decimal amount, Card card)
        {
            var result = card.Type.Match(
                visa => ValidateVisa(card.Number),
                masterCard => ValidateMasterCard(card.Number));

            CheckoutResult checkoutWithValidCard(CheckoutSuccess success)
            => CheckoutResult.Success("with " + success.Message + " for " + amount.ToString("#.00") + "$");

            return(result.Match(() => CheckoutResult.StaticFailure, succ => checkoutWithValidCard(succ)));
        }
コード例 #5
0
 private static CheckoutResult CheckoutWithCash(decimal amount)
 => CheckoutResult.Success("cash for " + amount.ToString("#.00") + "$");