Created
October 31, 2023 12:53
-
-
Save Velsimir/9c5fa416b00c6f0859e86f256f0ea80e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace IMJunior | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
PaymentBase paymentBase = new PaymentBase(); | |
OrderForm orderForm = new OrderForm(paymentBase); | |
PaymentHandler paymentHandler = new PaymentHandler(paymentBase); | |
string systemId; | |
orderForm.ShowForm(); | |
systemId = orderForm.GetUserInput(); | |
paymentHandler.SetConnection(systemId); | |
paymentHandler.ShowPaymentResult(systemId); | |
} | |
} | |
public class OrderForm | |
{ | |
private List<IPaymantSystem> _paymentSystemList; | |
public OrderForm(PaymentBase paymentBase) | |
{ | |
_paymentSystemList = new List<IPaymantSystem>(); | |
paymentBase.GetPaymentList(_paymentSystemList); | |
} | |
public void ShowForm() | |
{ | |
Console.WriteLine("Мы принимаем: "); | |
for (int i = 0; i < _paymentSystemList.Count; i++) | |
{ | |
Console.WriteLine($"{_paymentSystemList[i].GetPaymentName()}"); | |
} | |
} | |
public string GetUserInput() | |
{ | |
Console.WriteLine("Какой системой вы хотите совершить оплату?"); | |
return Console.ReadLine(); | |
} | |
} | |
public class PaymentHandler | |
{ | |
private List<IPaymantSystem> _paymentSystemList; | |
public PaymentHandler(PaymentBase paymentBase) | |
{ | |
_paymentSystemList = new List<IPaymantSystem>(); | |
paymentBase.GetPaymentList(_paymentSystemList); | |
} | |
public void SetConnection(string systemId) | |
{ | |
foreach (var item in _paymentSystemList) | |
{ | |
if (item.GetPaymentName() == systemId) | |
{ | |
item.SetConnection(); | |
break; | |
} | |
} | |
} | |
public void ShowPaymentResult(string systemId) | |
{ | |
Console.WriteLine($"Вы оплатили с помощью {systemId}"); | |
foreach (var item in _paymentSystemList) | |
{ | |
if (item.GetPaymentName() == systemId) | |
{ | |
ShowPaymentStatus(systemId); | |
break; | |
} | |
} | |
} | |
public void ShowPaymentStatus(string name) | |
{ | |
Console.WriteLine($"Проверка платежа через {name}..."); | |
Console.WriteLine("Оплата прошла успешно!"); | |
} | |
} | |
public class PaymentBase | |
{ | |
private List<IPaymantSystem> _paymentSystemList; | |
public PaymentBase() | |
{ | |
_paymentSystemList = new List<IPaymantSystem>(); | |
_paymentSystemList.Add(new Webmoney()); | |
_paymentSystemList.Add(new QIWI()); | |
_paymentSystemList.Add(new Card()); | |
} | |
public void GetPaymentList(List<IPaymantSystem> paymantSystems) | |
{ | |
foreach (var intem in _paymentSystemList) | |
{ | |
paymantSystems.Add(intem); | |
} | |
} | |
} | |
public interface IPaymantSystem | |
{ | |
public string GetPaymentName(); | |
public void SetConnection(); | |
} | |
public class Card : IPaymantSystem | |
{ | |
private string _name = "Card"; | |
public string GetPaymentName() | |
{ | |
return _name; | |
} | |
public void SetConnection() | |
{ | |
Console.WriteLine($"Вызов API банка эмитера карты {_name}..."); | |
} | |
} | |
public class QIWI : IPaymantSystem | |
{ | |
private string _name = "QIWI"; | |
public void SetConnection() | |
{ | |
Console.WriteLine($"Перевод на страницу {_name}..."); | |
} | |
public string GetPaymentName() | |
{ | |
return _name; | |
} | |
} | |
public class Webmoney : IPaymantSystem | |
{ | |
private string _name = "Webmoney"; | |
public string GetPaymentName() | |
{ | |
return _name; | |
} | |
public void SetConnection() | |
{ | |
Console.WriteLine($"Вызов API {_name}..."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment