static void Main(string[] args) { ProcessPayment paymentProcess = new ProcessPayment(); Console.WriteLine("Pick one of the following tests:"); Console.WriteLine("1. Test no. 1 - Validation failed because of the Credit Card Number and the Expiration Date."); Console.WriteLine("2. Test no. 2 - Validation approved for the expensive amount of money."); Console.WriteLine("3. Test no. 3 - Enter all details of the card: Credit Card Number, Card Holder, Expiration Code, Security Code(opional) and the amount of money."); string input = Console.ReadLine(); if (input.Equals("1")) { // Credit card number validation fails try { CreditCard creditCard = new CreditCard { CreditCardNumber = "123456789", ExpirationDate = Convert.ToDateTime("10/01/2010"), CardHolder = "Vasile", SecurityCode = "023", Amount = 15 }; Validator.ValidateObject(creditCard, new ValidationContext(creditCard, null, null), true); paymentProcess.ProcessPaymentMethod(creditCard); } catch (Exception e) { Console.WriteLine(e.Message); } // Expiration date custom validation fails try { CreditCard creditCard = new CreditCard { CreditCardNumber = "1234567890000000", ExpirationDate = Convert.ToDateTime("10/01/2010"), CardHolder = "Vasile", SecurityCode = "023", Amount = 15 }; Validator.ValidateObject(creditCard, new ValidationContext(creditCard, null, null), true); paymentProcess.ProcessPaymentMethod(creditCard); } catch (Exception e) { Console.WriteLine(e.Message); } } //The payment is processed for an Expensive amount else if (input.Equals("2")) { try { CreditCard creditCard = new CreditCard { CreditCardNumber = "1234567890000000", ExpirationDate = Convert.ToDateTime("10/01/2020"), CardHolder = "Vasile", SecurityCode = "023", Amount = 250 }; Validator.ValidateObject(creditCard, new ValidationContext(creditCard, null, null), true); paymentProcess.ProcessPaymentMethod(creditCard); } catch (Exception e) { Console.WriteLine(e.Message); } } else if (input.Equals("3")) { try { Console.WriteLine("Enter Credit Card Number:"); string cardNum = Console.ReadLine(); Console.WriteLine("Enter Credit Card Holder:"); string cardName = Console.ReadLine(); Console.WriteLine("Enter the Expiration Date of the card:"); DateTime cardExp = Convert.ToDateTime(Console.ReadLine()); Console.WriteLine("Enter the Security Code (optional):"); string cardSecurityCode = Console.ReadLine(); Console.WriteLine("Enter the amount of money:"); decimal amountOfMoney = Convert.ToDecimal(Console.ReadLine()); CreditCard creditCard = new CreditCard { CreditCardNumber = cardNum, ExpirationDate = cardExp, CardHolder = cardName, SecurityCode = cardSecurityCode, Amount = amountOfMoney }; Validator.ValidateObject(creditCard, new ValidationContext(creditCard, null, null), true); paymentProcess.ProcessPaymentMethod(creditCard); } catch (Exception e) { Console.WriteLine(e.Message); } } }
public static bool MakePayment(CreditCard creditCard) { Console.WriteLine("Cheap Payment has been processed successfully…"); return(true); }
/// <summary> /// Logging failure-of-payment event /// </summary> /// <param name="creditCard"> creditCard for which payment failed </param> /// <param name="failureReason"> reason of failure </param> public void SignalPaymentFailure(CreditCard creditCard, string failureReason) { Console.WriteLine(String.Format("Payment could not be executed for credit " + "card number: {0};\t ammount: {1}\nReason for failure: {2}", creditCard.CreditCardNumber, creditCard.Ammount, failureReason)); }
/// <summary> /// Logging succesfull-payment event /// </summary> /// <param name="creditCard"> creditCard for which payment was fulfilled </param> public void SignalPaymentSuccess(CreditCard creditCard) { Console.WriteLine(String.Format("Payment executed successfully.\n" + "\t{0}£ were transfered from card: {1}, using {2}", creditCard.Ammount, creditCard.CreditCardNumber, GetType().Name)); }
/// <summary> /// When fulfilling a payment, first check if the service is available, then attempt to wire the monney. /// /// Despite having almost identical implementation of this function for all the PaymentProviders, I chose to /// override it for each provider, as in a business scenario providers would have different implementations. /// </summary> /// <returns> TRUE if payment was fulfilled successfully </returns> public abstract bool FulfillPayment(CreditCard creditCard, int retryAttempts);