/// <summary> /// The vending controller constructor. /// </summary> /// <param name="displayPanel">The display panel</param> /// <param name="coinReceiver">The payment module</param> /// <param name="orderPurchasePanel">The order module.</param> /// <param name="productRepository">The product repository.</param> /// <param name="walletRepository">The wallet repository.</param> /// <param name="saleRecord">Sold product logs</param> /// <param name="vendingMessageRepository">The messages repository.</param> public VendingMachineController(IDisplayPanel displayPanel, IPaymentReceiver coinReceiver, IOrderPanel orderPurchasePanel, IProductRepository productRepository, IWalletRepository walletRepository, ISoldRecord saleRecord, IVendingMessageRepository vendingMessageRepository) { _vendingMessageRepository = vendingMessageRepository; _displayPanel = displayPanel; _coinReceiver = coinReceiver; _coinReceiver.CoinAction += PaymentAction; _coinReceiver.FailtException += FailtException; _productRepository = productRepository; _walletRepository = walletRepository; _orderPurchasePanel = orderPurchasePanel; _orderPurchasePanel.OrderAction += OrderAction; _orderPurchasePanel.FailtException += FailtException; _saleRecord = saleRecord; }
public void HandleFile(string filename, IPaymentReceiver receiver) { ICollection<PaymentBundle> bundles; using (var provider = new FileRawPaymentRecordProvider(filename)) { var reader = GetReader(provider); bundles = reader.ProcessAllRecords(); } foreach (var bundle in bundles) { receiver.StartPaymentBundle(bundle.AccountNumber, bundle.PaymentDate, bundle.Currency); foreach (var payment in bundle.Payments) { receiver.Payment(payment.Amount, payment.Reference); } receiver.EndPaymentBundle(); } }
/// <summary> /// Loads coins into wallet. /// </summary> /// <param name="walletRepository">The coin repository.</param> /// <param name="paymentReceiver">The payment receiver.</param> /// <param name="machineConfig">The configuration.</param> public static void LoadWallet(this VendingConfiguration machineConfig, IWalletRepository walletRepository, IPaymentReceiver paymentReceiver) { foreach (var ch in machineConfig.ChangeWalletConfig) { if (paymentReceiver.AcceptedCoins.Any(c => c.Nominal == ch.Nominal)) { walletRepository.AddToWallet(new Coin(ch.Nominal), (int)ch.Number); } else { throw new InvalidDataException($"Invalid coin type of nominal {ch.Nominal}"); } } }