Exemplo n.º 1
0
        public CashPaymentTest()
        {
            _cashPaymentService = new CashPaymentService();

            //_cashPaymentService.OnGivedChange += CashPaymentService_OnGivedChange;
            //_cashPaymentService.OnReceived += CashPaymentService_OnReceived;
            _cashPaymentService.OnStop += CashPaymentService_OnStop;
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            handler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(handler, true);

            IHost host = CreateHostBuilder(args).Build();

            IEventBroker broker = host.Services.GetRequiredService <IEventBroker>(); // initialize evenk broker

            // instantiate mediators
            OrderingMediator mediator        = host.Services.GetRequiredService <OrderingMediator>();
            PaymentMediator  paymentMediator = host.Services.GetRequiredService <PaymentMediator>();

            // POC
            Task.Run(() =>
            {
                Thread.Sleep(1500);

                IAttendant att = host.Services.GetRequiredService <IAttendant>();

                att.StartOrder(b => b.WithHeader("TST123456", "9262147116", "IVG", Locale.Latvia, Lang.Lv)
                               .WithObtainingMethod(GoodsObtainingMethod.Warehouse)
                               .WithItems(OrderLine.Create("0141", Money.Create(10.0m, CurrencyCode.Euro)))
                               .WithTotalValues(Money.Create(10.0m, CurrencyCode.Euro), 15.95m)
                               .WithExtraData("Kiosk", "LRK0123456")
                               .WithExtraData("SelectedMonth", "february 2021"));

                IPaymentProvider paymentProvider       = host.Services.GetRequiredService <IPaymentProvider>();
                ICashPaymentService cashPaymentService = host.Services.GetRequiredService <ICashPaymentService>(); // пользователь выбрал оплату кешем (не payment provider так решил, а пользователь)

                paymentProvider.Collect(PaymentSource.UVS, att.Order, (p) => { });


                Task.Factory.StartNew(() =>
                {
                    Thread.Sleep(10000);
                    att.CompleteOrder();
                });

                /*IStorageService s2 = host.Services.GetRequiredService<IStorageService>();
                 *
                 * ICompositeDispenser dispenser = host.Services.GetRequiredService<ICompositeDispenser>();
                 *
                 * ILayout layout = host.Services.GetRequiredService<ILayout>();
                 * if (layout == null)
                 * {
                 *  var t = s2.Get(x => true);
                 * }
                 *
                 * dispenser.OnDispensing += S1_OnDispensing;
                 *
                 * dispenser.Dispense(CompositDispenseAddress.Create(vendingMachineId: layout.Machines.First().Number.ToString(), layout.Machines.First().Trays.First().Belts.First().Address));
                 *
                 * dispenser.OnDispensing -= S1_OnDispensing;*/
            });

            host.Run();
        }
Exemplo n.º 3
0
        public PaymentMediator(IPaymentProvider paymentProvider, ICashPaymentService cashService, IEcommerceServices ecommerceServices)
        {
            _paymentProvider   = paymentProvider;
            _cashService       = cashService;
            _ecommerceServices = ecommerceServices;

            _paymentProvider.OnFetchMoneyCommand += (sender, e) =>
            {
                IEcommerceService ecomService = ecommerceServices[e.Source];

                if (ecomService != null)
                {
                    ecomService.FetchMoney(e.Order);
                }
                else
                {
                    switch (e.Source)
                    {
                    case PaymentSource.Cash:
                        foreach (ICashDeviceAdapter cashDevide in _cashService.CashDevices)
                        {
                            cashDevide.Start();
                        }
                        break;

                    default:
                        throw new NotImplementedException($"Unknown payment source {e.Source.GetCode()}");
                    }
                }
            };

            _paymentProvider.OnTotalAmountSpecified += (sender, e) => {
                // Notify all cash devices about duty (a remaining part of payment) was changed
                foreach (var cashDevice in _cashService.CashDevices)
                {
                    cashDevice.ReduceOrSetDutyTo(e.Value);
                }
            };

            _paymentProvider.OnGiveChangeSpecified += (sender, e) => {
                _cashService.IssueChange(e.ChangeAmount);
            };

            foreach (var cashDevice in _cashService.CashDevices)
            {
                cashDevice.OnMoneyReceived += (sender, e) => {
                    _paymentProvider.SomeMoneyIncome(PaymentSource.Cash, e.Money);

                    // Notify all cash devices about duty (a remaining part of payment) was changed
                    foreach (var device in _cashService.CashDevices)
                    {
                        device.ReduceOrSetDutyTo(_paymentProvider.Duty);
                    }
                }
            }
            ;

            foreach (var cashDevice in _cashService.CashDevices)
            {
                cashDevice.OnSomeChangeIssued += (sender, e) => {
                    _paymentProvider.SomeChangeExtracted(e.Money);
                }
            }
            ;

            foreach (var ecomService in _ecommerceServices.Services)
            {
                ecomService.OnReceived += (sender, e) => {
                    _paymentProvider.SomeMoneyIncome(ecomService.Source, e.Income);
                };
            }
        }