private static CheckoutResult ValidateMasterCard(int number) { if (number.ToString().EndsWith('9')) { return(CheckoutResult.StaticFailure); } return(CheckoutResult.Success("MasterCard")); }
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") + "$")); }
private static CheckoutResult ValidateVisa(int number) { if (number.ToString().EndsWith('3')) { return(CheckoutResult.StaticFailure); } return(CheckoutResult.Success("Visa")); }
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))); }
private static CheckoutResult CheckoutWithCash(decimal amount) => CheckoutResult.Success("cash for " + amount.ToString("#.00") + "$");