Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace IMJunior
- {
- class Program
- {
- static void Main(string[] args)
- {
- var orderForm = new OrderForm();
- var paymentHandler = orderForm.ShowForm();
- paymentHandler.MakeCallback();
- }
- }
- public class OrderForm
- {
- private const string _qiwi = "QIWI";
- private const string _webMoney = "WebMoney";
- private const string _card = "Card";
- public ISystemCallback ShowForm()
- {
- Console.WriteLine("Мы принимаем: QIWI, WebMoney, Card");
- //симуляция веб интерфейса
- Console.WriteLine("Какое системой вы хотите совершить оплату?");
- string systemId = Console.ReadLine();
- ISystemCallback result = systemId switch
- {
- "QIWI" => new QiwiSystemCallback(new QiwiPaymentHandler(_qiwi)),
- "WebMoney" => new WebMoneySystemCallback(new WebMoneyPaymentHandler(_webMoney)),
- "Card" => new CardSystemCallback(new CardPaymentHandler(_card)),
- _ => default
- };
- return result;
- }
- }
- public abstract class SystemCallback : ISystemCallback
- {
- protected IPaymentHandler PaymentHandler;
- protected SystemCallback(IPaymentHandler paymentHandler)
- {
- PaymentHandler = paymentHandler;
- }
- public abstract void MakeCallback();
- }
- public class QiwiSystemCallback : SystemCallback
- {
- public QiwiSystemCallback(IPaymentHandler paymentHandler) : base(paymentHandler)
- {
- }
- public override void MakeCallback()
- {
- Console.WriteLine("Перевод на страницу QIWI...");
- PaymentHandler.ShowPaymentResult();
- }
- }
- public class WebMoneySystemCallback : SystemCallback
- {
- public WebMoneySystemCallback(IPaymentHandler paymentHandler) : base(paymentHandler)
- {
- }
- public override void MakeCallback()
- {
- Console.WriteLine("Вызов API WebMoney...");
- PaymentHandler.ShowPaymentResult();
- }
- }
- public class CardSystemCallback : SystemCallback
- {
- public CardSystemCallback(IPaymentHandler paymentHandler) : base(paymentHandler)
- {
- }
- public override void MakeCallback()
- {
- Console.WriteLine("Вызов API банка эмитера карты Card...");
- PaymentHandler.ShowPaymentResult();
- }
- }
- public abstract class PaymentHandler : IPaymentHandler
- {
- protected readonly string SystemId;
- protected PaymentHandler(string systemId)
- {
- SystemId = systemId;
- }
- public virtual void ShowPaymentResult()
- {
- Console.WriteLine($"Вы оплатили с помощью {SystemId}");
- }
- }
- public class QiwiPaymentHandler : PaymentHandler
- {
- public QiwiPaymentHandler(string systemId) : base(systemId)
- {
- }
- public override void ShowPaymentResult()
- {
- base.ShowPaymentResult();
- Console.WriteLine("Проверка платежа через QIWI...");
- Console.WriteLine("Оплата прошла успешно!");
- }
- }
- public class WebMoneyPaymentHandler : PaymentHandler
- {
- public WebMoneyPaymentHandler(string systemId) : base(systemId)
- {
- }
- public override void ShowPaymentResult()
- {
- base.ShowPaymentResult();
- Console.WriteLine("Проверка платежа через WebMoney...");
- Console.WriteLine("Оплата прошла успешно!");
- }
- }
- public class CardPaymentHandler : PaymentHandler
- {
- public CardPaymentHandler(string systemId) : base(systemId)
- {
- }
- public override void ShowPaymentResult()
- {
- base.ShowPaymentResult();
- Console.WriteLine("Проверка платежа через Card...");
- Console.WriteLine("Оплата прошла успешно!");
- }
- }
- public interface ISystemCallback
- {
- public abstract void MakeCallback();
- }
- public interface IPaymentHandler
- {
- public void ShowPaymentResult();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement