static void Main(string[] args) { Console.Write("Payment Method: "); var method = Console.ReadLine(); Computer computer; var order = new Order { AmountOfCores = 4, AmountOfRam = 32, CpuFrequency = 3.0m, DriveType = "ssd" }; var processingService = new OrderProcessingService(); if (method.ToLower() == "cash") { computer = processingService.MakeCashPurchase(order, 1500m); } else { computer = processingService.MakeCreditPurchase(order); } GiveComputerToCustomer(computer); Console.Read(); }
public void Pending_order_should_not_be_processed_when_product_included_has_no_stock_available() { // Arrange var orderId = 9987; int productId = 1234; int quantityOnHand = 4; int orderQuantity = 5; decimal costPerItem = 10.00m; int reorderThreshold = 5; int reorderAmount = 5; var orderItem = new OrderItem(productId, orderQuantity, costPerItem); var order = new Order(orderId, DateTime.Now, OrderStatus.Pending, new List <OrderItem>() { orderItem }); var product = new Product(productId, "test product", quantityOnHand, reorderThreshold, reorderAmount, 10); _productRepository = new Mock <IProductRepository>(); _productRepository.Setup(x => x.GetById(It.Is <int>(p => p == productId))).Returns(product); _purchaseOrderRepository = new Mock <IPurchaseOrderRepository>(); _purchaseOrderRepository.Setup(x => x.Add(It.IsAny <PurchaseOrder>())); _orderProcessingService = new OrderProcessingService(_productRepository.Object, _purchaseOrderRepository.Object, _domainEventDispatcher.Object); // Act _orderProcessingService.ProcessOrder(order); // Assert Assert.Equal(OrderStatus.Error_Unfulfillable, order.Status); }
public OrderProcessingServiceTests() { _mockInventory = new Mock <IManageInventory>(); _mockProcessPayment = new Mock <IProcessPaymentService>(); _mockEmailService = new Mock <IEmailService>(); _sut = new OrderProcessingService(_mockInventory.Object, _mockProcessPayment.Object, _mockEmailService.Object); }
public string ProcessPayment(int paymentType) { string result = string.Empty; switch (paymentType) { case 1: // For Physical Product case 2: // For a Book OrderProcessingService objOrderProcessingService = new OrderProcessingService(); result = objOrderProcessingService.CreatePackingSlip(paymentType); break; case 3: // For Membership MembershipService objMembershipService = new MembershipService(); result = objMembershipService.ActivateMemberShip(activateMemberId); break; case 4: // For Upgrade MemberShip MembershipService objMembershipService1 = new MembershipService(); result = objMembershipService1.UpgradeMemberShip(upgradeMemberId); break; case 5: // For Video OrderProcessingService objOrderProcessingService1 = new OrderProcessingService(); result = objOrderProcessingService1.VideoToPackingSlip(videoToPackingSlipMemberId); break; } return(result); }
private static void ProcessAllOrders(IDictionary <Guid, IOrder> orders) { OrderProcessingService orderProcessingService = new OrderProcessingService(); IOrderExecutionService orderExecutionService = new OrderExecutionService(); MembershipProcessingStrategy membershipProcessingStrategy = new MembershipProcessingStrategy(orderExecutionService); ProductOrderProcessingStrategy productOrderProcessingStrategy = new ProductOrderProcessingStrategy(orderExecutionService); VideoRequestProcessingStrategy videoRquestProcessingStrategy = new VideoRequestProcessingStrategy(orderExecutionService); Console.WriteLine("\n\t\t---------------------------------------------\n"); Console.WriteLine("\n\t\t*********************************************\n"); Console.WriteLine("\n\t\t* PROCESSING ALL THE PLACED ORDERS *\n"); try { foreach (KeyValuePair <Guid, IOrder> kvp in orders) { string name = kvp.Value.GetType().Name.ToUpper(); switch ((OrderType)Enum.Parse(typeof(OrderType), name)) { case OrderType.MEMBERSHIP: orderProcessingService.SetOrderProcessingStrategy(membershipProcessingStrategy); orderProcessingService.ProcessOrder(kvp.Value); break; case OrderType.PRODUCT: orderProcessingService.SetOrderProcessingStrategy(productOrderProcessingStrategy); orderProcessingService.ProcessOrder(kvp.Value); break; case OrderType.VIDEO: orderProcessingService.SetOrderProcessingStrategy(videoRquestProcessingStrategy); orderProcessingService.ProcessOrder(kvp.Value); break; default: break; } } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("\n\t\t*********************************************\n"); Console.WriteLine("\n\t\t---------------------------------------------\n"); Console.WriteLine("\n\t\t* ALL ORDERS HAS BEEN PROCESSED *\n"); }
static void Main(string[] args) { var order = new Order { Decription = "iPhone 4", Quantity = 1, Customer = new Customer { Name = "Andy Pike", Email = "*****@*****.**", Phone = "1234567890" } }; var repository = new NHibernateRepository<Order>(new FileLogger()); var notifier = new PlainTextEmailer(); var orderProcessingService = new OrderProcessingService(repository, notifier); orderProcessingService.PlaceOrder(order); }
static void Main() { Console.WriteLine("Enter your product type (Book/Membership/Video/Other):"); string productType = Console.ReadLine().Trim(); Console.WriteLine("\nEnter your product name:"); string productName = Console.ReadLine().Trim(); Product processedProduct = OrderProcessingService.ProcessOrder(ServiceHelper.GetProductType(productType), productName); Console.WriteLine($"\n\n\nProduct Name:\n{processedProduct.ItemName}"); Console.WriteLine("\nOperations Performed:"); foreach (string processedOperation in processedProduct.ProcessingOperations) { Console.WriteLine($"{processedOperation}"); } Console.WriteLine("\n\n\n\n"); }
static async Task Main(string[] args) { Console.Clear(); Console.WriteLine("Hi! This is a very awesome tic tac toe game status analyzer"); var url = GetUrlFromUserInput(); var importLines = await DownloadStatusFileAsync(url); var service = new OrderProcessingService(); var shipmentLines = service.Process(importLines); Console.WriteLine("CustomerId,Name,Shipper,Duration,ShippingCost"); foreach (var shipmentLine in shipmentLines) { Console.WriteLine($"{shipmentLine.CustomerId},{shipmentLine.Name},{shipmentLine.Shipper},{shipmentLine.Duration},{shipmentLine.ShippingCost}"); } Console.WriteLine(); Console.ReadKey(); }
static void Main(string[] args) { var order = new Order { Decription = "iPhone 4", Quantity = 1, Customer = new Customer { Name = "Andy Pike", Email = "*****@*****.**", Phone = "1234567890" } }; var repository = new NHibernateRepository <Order>(new FileLogger()); var notifier = new PlainTextEmailer(); var orderProcessingService = new OrderProcessingService(repository, notifier); orderProcessingService.PlaceOrder(order); }
static void Main(string[] args) { var order = new Order { Decription = "iPhone 4", Quantity = 1, Customer = new Customer { Name = "Andy Pike", Email = "*****@*****.**", Phone = "1234567890" } }; //Do the following with this order: // * Save the order // * Log the save somewhere // * Notify the customer var orderProcessingService = new OrderProcessingService(); orderProcessingService.PlaceOrder(order); }
public void WhenOrderIsProcessed_IsReturnsShipmentInformation() { var order = new OrderBuilder() .WithCountry("Netherlands") .WithWeight(6) .Build(); var orderProcessor = new OrderProcessingService(); var shipmentInfo = orderProcessor.Process(new List <string> { order.ToString() }); Assert.AreEqual(1, shipmentInfo.Count()); var shipment = shipmentInfo.FirstOrDefault(); Assert.AreEqual(order.CustomerId, shipment.CustomerId); Assert.AreEqual(order.Name, shipment.Name); Assert.AreEqual("PostNL", shipment.Shipper); Assert.AreEqual(1, shipment.Duration); Assert.AreEqual(6.95M, shipment.ShippingCost); }
public new void SetUp() { _productService = new Mock <IProductService>(); _storeContext = new Mock <IStoreContext>(); _discountService = new Mock <IDiscountService>(); _categoryService = new Mock <ICategoryService>(); _manufacturerService = new Mock <IManufacturerService>(); _productAttributeParser = new Mock <IProductAttributeParser>(); _eventPublisher = new Mock <IEventPublisher>(); _localizationService = new Mock <ILocalizationService>(); _shippingMethodRepository = new Mock <IRepository <ShippingMethod> >(); _warehouseRepository = new Mock <IRepository <Warehouse> >(); _shipmentService = new Mock <IShipmentService>(); _paymentService = new Mock <IPaymentService>(); _checkoutAttributeParser = new Mock <ICheckoutAttributeParser>(); _giftCardService = new Mock <IGiftCardService>(); _genericAttributeService = new Mock <IGenericAttributeService>(); _geoLookupService = new Mock <IGeoLookupService>(); _countryService = new Mock <ICountryService>(); _stateProvinceService = new Mock <IStateProvinceService>(); _eventPublisher = new Mock <IEventPublisher>(); _addressService = new Mock <IAddressService>(); _rewardPointService = new Mock <IRewardPointService>(); _orderService = new Mock <IOrderService>(); _webHelper = new Mock <IWebHelper>(); _languageService = new Mock <ILanguageService>(); _priceFormatter = new Mock <IPriceFormatter>(); _productAttributeFormatter = new Mock <IProductAttributeFormatter>(); _shoppingCartService = new Mock <IShoppingCartService>(); _checkoutAttributeFormatter = new Mock <ICheckoutAttributeFormatter>(); _customerService = new Mock <ICustomerService>(); _encryptionService = new Mock <IEncryptionService>(); _workflowMessageService = new Mock <IWorkflowMessageService>(); _customerActivityService = new Mock <ICustomerActivityService>(); _currencyService = new Mock <ICurrencyService>(); _affiliateService = new Mock <IAffiliateService>(); _vendorService = new Mock <IVendorService>(); _pdfService = new Mock <IPdfService>(); _customNumberFormatter = new Mock <ICustomNumberFormatter>(); _rewardPointService = new Mock <IRewardPointService>(); _workContext = null; _store = new Store { Id = 1 }; _storeContext.Setup(x => x.CurrentStore).Returns(_store); _shoppingCartSettings = new ShoppingCartSettings(); _catalogSettings = new CatalogSettings(); var cacheManager = new NopNullCache(); //price calculation service _priceCalcService = new PriceCalculationService(_workContext, _storeContext.Object, _discountService.Object, _categoryService.Object, _manufacturerService.Object, _productAttributeParser.Object, _productService.Object, cacheManager, _shoppingCartSettings, _catalogSettings); _eventPublisher.Setup(x => x.Publish(It.IsAny <object>())); var pluginFinder = new PluginFinder(_eventPublisher.Object); //shipping _shippingSettings = new ShippingSettings { ActiveShippingRateComputationMethodSystemNames = new List <string>() }; _shippingSettings.ActiveShippingRateComputationMethodSystemNames.Add("FixedRateTestShippingRateComputationMethod"); _logger = new NullLogger(); _customerSettings = new CustomerSettings(); _addressSettings = new AddressSettings(); _shippingService = new ShippingService(_shippingMethodRepository.Object, _warehouseRepository.Object, _logger, _productService.Object, _productAttributeParser.Object, _checkoutAttributeParser.Object, _genericAttributeService.Object, _localizationService.Object, _addressService.Object, _shippingSettings, pluginFinder, _storeContext.Object, _eventPublisher.Object, _shoppingCartSettings, cacheManager); //tax _taxSettings = new TaxSettings { ShippingIsTaxable = true, PaymentMethodAdditionalFeeIsTaxable = true, DefaultTaxAddressId = 10 }; _addressService.Setup(x => x.GetAddressById(_taxSettings.DefaultTaxAddressId)).Returns(new Address { Id = _taxSettings.DefaultTaxAddressId }); _taxService = new TaxService(_addressService.Object, _workContext, _storeContext.Object, _taxSettings, pluginFinder, _geoLookupService.Object, _countryService.Object, _stateProvinceService.Object, _logger, _webHelper.Object, _customerSettings, _shippingSettings, _addressSettings); _rewardPointsSettings = new RewardPointsSettings(); _orderTotalCalcService = new OrderTotalCalculationService(_workContext, _storeContext.Object, _priceCalcService, _productService.Object, _productAttributeParser.Object, _taxService, _shippingService, _paymentService.Object, _checkoutAttributeParser.Object, _discountService.Object, _giftCardService.Object, _genericAttributeService.Object, _rewardPointService.Object, _taxSettings, _rewardPointsSettings, _shippingSettings, _shoppingCartSettings, _catalogSettings); _paymentSettings = new PaymentSettings { ActivePaymentMethodSystemNames = new List <string> { "Payments.TestMethod" } }; _orderSettings = new OrderSettings(); _localizationSettings = new LocalizationSettings(); _eventPublisher.Setup(x => x.Publish(It.IsAny <object>())); _currencySettings = new CurrencySettings(); _orderProcessingService = new OrderProcessingService(_orderService.Object, _webHelper.Object, _localizationService.Object, _languageService.Object, _productService.Object, _paymentService.Object, _logger, _orderTotalCalcService, _priceCalcService, _priceFormatter.Object, _productAttributeParser.Object, _productAttributeFormatter.Object, _giftCardService.Object, _shoppingCartService.Object, _checkoutAttributeFormatter.Object, _shippingService, _shipmentService.Object, _taxService, _customerService.Object, _discountService.Object, _encryptionService.Object, _workContext, _workflowMessageService.Object, _vendorService.Object, _customerActivityService.Object, _currencyService.Object, _affiliateService.Object, _eventPublisher.Object, _pdfService.Object, _rewardPointService.Object, _genericAttributeService.Object, _countryService.Object, _stateProvinceService.Object, _shippingSettings, _paymentSettings, _rewardPointsSettings, _orderSettings, _taxSettings, _localizationSettings, _currencySettings, _customNumberFormatter.Object); }
public ActionResult PDTHandler(FormCollection form) { Dictionary <string, string> values; var tx = Services.WebHelper.QueryString <string>("tx"); var utcNow = DateTime.UtcNow; var orderNumberGuid = Guid.Empty; var orderNumber = string.Empty; var total = decimal.Zero; string response; var provider = PaymentService.LoadPaymentMethodBySystemName(PayPalStandardProvider.SystemName, true); var processor = provider != null ? provider.Value as PayPalStandardProvider : null; if (processor == null) { Logger.Warn(null, T("Plugins.Payments.PayPal.NoModuleLoading", "PDTHandler")); return(RedirectToAction("Completed", "Checkout", new { area = "" })); } var settings = Services.Settings.LoadSetting <PayPalStandardPaymentSettings>(); if (processor.GetPDTDetails(tx, settings, out values, out response)) { values.TryGetValue("custom", out orderNumber); try { orderNumberGuid = new Guid(orderNumber); } catch { } var order = OrderService.GetOrderByGuid(orderNumberGuid); if (order != null) { try { total = decimal.Parse(values["mc_gross"], new CultureInfo("en-US")); } catch (Exception ex) { Logger.Error(ex, T("Plugins.Payments.PayPalStandard.FailedGetGross")); } values.TryGetValue("payer_status", out string payer_status); values.TryGetValue("payment_status", out string payment_status); values.TryGetValue("pending_reason", out string pending_reason); values.TryGetValue("mc_currency", out string mc_currency); values.TryGetValue("txn_id", out string txn_id); values.TryGetValue("payment_type", out string payment_type); values.TryGetValue("payer_id", out string payer_id); values.TryGetValue("receiver_id", out string receiver_id); values.TryGetValue("invoice", out string invoice); values.TryGetValue("payment_fee", out string payment_fee); var paymentNote = T("Plugins.Payments.PayPalStandard.PaymentNote", total, mc_currency, payer_status, payment_status, pending_reason, txn_id, payment_type, payer_id, receiver_id, invoice, payment_fee); OrderService.AddOrderNote(order, paymentNote); // validate order total... you may get differences if settings.PassProductNamesAndTotals is true if (settings.PdtValidateOrderTotal) { var roundedTotal = Math.Round(total, 2); var roundedOrderTotal = Math.Round(order.OrderTotal, 2); var roundedDifference = Math.Abs(roundedTotal - roundedOrderTotal); if (!roundedTotal.Equals(roundedOrderTotal)) { var message = T("Plugins.Payments.PayPalStandard.UnequalTotalOrder", total, roundedOrderTotal.FormatInvariant(), order.OrderTotal, roundedDifference.FormatInvariant()); if (settings.PdtValidateOnlyWarn) { OrderService.AddOrderNote(order, message); } else { Logger.Error(message); return(RedirectToAction("Index", "Home", new { area = "" })); } } } // mark order as paid var newPaymentStatus = GetPaymentStatus(payment_status, pending_reason, total, order.OrderTotal); if (newPaymentStatus == PaymentStatus.Paid) { // note, order can be marked as paid through IPN if (order.AuthorizationTransactionId.IsEmpty()) { order.AuthorizationTransactionId = order.CaptureTransactionId = txn_id; order.AuthorizationTransactionResult = order.CaptureTransactionResult = "Success"; OrderService.UpdateOrder(order); } if (OrderProcessingService.CanMarkOrderAsPaid(order)) { OrderProcessingService.MarkOrderAsPaid(order); } } } return(RedirectToAction("Completed", "Checkout", new { area = "" })); } else { try { values.TryGetValue("custom", out orderNumber); orderNumberGuid = new Guid(orderNumber); var order = OrderService.GetOrderByGuid(orderNumberGuid); OrderService.AddOrderNote(order, "{0} {1}".FormatInvariant(T("Plugins.Payments.PayPalStandard.PdtFailed"), response)); } catch { } return(RedirectToAction("Index", "Home", new { area = "" })); } }
public void SetUp() { _orderService = GetService <IOrderService>(); _orderProcessingService = GetService <OrderProcessingService>(); }
public OrderController(IDiscoveryClient discoClient, ILoggerFactory logFactory) { _orders = new OrderProcessingService(discoClient, logFactory); }