public ConfigurationFactory(IStoreRepository storeRepository)
        {
            var config = ConfigurationManager.GetSection("commerceEngine") as CommerceEngineConfigurationSection;

            if (config == null)
            {
                return;
            }

            this._paymentProvider = Activator.CreateInstance(Type.GetType(config.PaymentProvider.Type)) as IPaymentProvider;
            if (this._paymentProvider != null)
            {
                this._paymentProvider.Login    = config.PaymentProvider.Login;
                this._paymentProvider.Password = config.PaymentProvider.Password;
            }

            this._mailingProvider = Activator.CreateInstance(Type.GetType(config.MailingProvider.Type)) as IMailingProvider;
            if (this._mailingProvider != null)
            {
                this._mailingProvider.FromAddress = config.MailingProvider.FromAddress;
                this._mailingProvider.SmtpServer  = config.MailingProvider.SmtpServer;
            }

            this._shippingProvider = Activator.CreateInstance(Type.GetType(config.ShippingProvider.Type)) as IShippingProvider;

            this._commerceEvents = new CommerceEvents();
            foreach (ProviderSettings element in config.Modules)
            {
                var module = Activator.CreateInstance(Type.GetType(element.Type)) as ICommerceModule;
                module?.Initialize(this._commerceEvents, element.Parameters);
            }
        }
 public CommerceManager(IStoreRepository storeRepository, IConfigurationFactory configurationFactory)
 {
     _StoreRepository  = storeRepository;
     _PaymentProcessor = configurationFactory.GetPaymentProcessor();
     _Mailer           = configurationFactory.GetMailer();
     _CommerceEvents   = configurationFactory.GetEvents();
 }
        public void Initialize(CommerceEvents events, NameValueCollection config)
        {
            var promotionStartDate = config["startPromotionDate"];

            if (string.IsNullOrWhiteSpace(promotionStartDate))
            {
                throw new ArgumentNullException("start date is missing");
            }

            var promotionEndDate = config["endPromotionDate"];

            if (string.IsNullOrWhiteSpace(promotionEndDate))
            {
                throw new ArgumentNullException("end date is missing");
            }

            this._startDate = Convert.ToDateTime(promotionStartDate);
            this._endDate   = Convert.ToDateTime(promotionEndDate);

            events.OrderItemProcessed += args =>
            {
                var today = DateTime.Today;
                if (today < this._startDate || today > this._endDate)
                {
                    return;
                }

                if (args.OrderLineItemData.Sku == 102)
                {
                    args.OrderLineItemData.PurchasePrice -= 30;
                }
            };
        }
示例#4
0
        public void Initialize(CommerceEvents events, NameValueCollection config)
        {
            events.OrderItemProcessed += OnOrderItemProcessed;

            string promotionStartDate = config["startDate"];

            if (string.IsNullOrWhiteSpace(promotionStartDate))
            {
                throw new ArgumentNullException("Missing config argument 'startDate'");
            }

            string promotionEndDate = config["endDate"];

            if (string.IsNullOrWhiteSpace(promotionEndDate))
            {
                throw new ArgumentNullException("Missing config argument 'endDate'");
            }

            _PromotionStartDate = Convert.ToDateTime(promotionStartDate);
            _PromotionEndDate   = Convert.ToDateTime(promotionEndDate);

            config.Remove("name");
            config.Remove("type");
            config.Remove("startDate");
            config.Remove("endDate");

            if (config.Count > 0)
            {
                throw new ApplicationException("Unknown config arguments detected.");
            }
        }
        public CommerceManager(IStoreRepository storeRepository, IConfigurationFactory configurationFactory)
        {
            this._storeRepository = storeRepository;

            this._mailingProvider  = configurationFactory.GetMailer();
            this._paymentProvider  = configurationFactory.GetPaymentProcessor();
            this._shippingProvider = configurationFactory.GetShippingProcessor();
            this._commerceEvents   = configurationFactory.GetCommerceEvents();
        }
        public void Initialize(CommerceEvents events, NameValueCollection config)
        {
            events.SendNotification += args =>
            {
                Console.WriteLine("");
                Console.WriteLine("send invoice email");
                Console.WriteLine("#################");
                Console.WriteLine("");

                args.MailingProvider.SendInvoiceEmail(args.OrderData);
            };
        }
        public void Initialize(CommerceEvents events, NameValueCollection config)
        {
            events.SetShippingCost += args =>
            {
                Console.WriteLine("");
                Console.WriteLine("#################");
                Console.WriteLine("get shipping cost");
                Console.WriteLine("");

                args.ShippingCost = args.ShippingProvider.GetShippingCost(args.OrderData);
            };
        }
        public void Initialize(CommerceEvents events, NameValueCollection config)
        {
            events.ValidateCustomer += args =>
            {
                var customer = args.StoreRepository.GetCustomerByEmail(args.OrderData.CustomerEmail);
                if (customer == null)
                {
                    throw new ArgumentNullException($"no customer with the email {args.OrderData.CustomerEmail}");
                }

                Console.WriteLine("");
                Console.WriteLine("customer validation");
                Console.WriteLine("#################");
                Console.WriteLine("");
                Console.WriteLine("\tCustomer has benn validazed.");

                args.Customer = customer;
            };
        }
        public void Initialize(CommerceEvents events, NameValueCollection config)
        {
            events.OrderItemProcessed += args =>
            {
                // just for the case if i want to have access to the host's db
                // args.StoreRepository...

                // in the case that i want access to my own db - other then from host's
                if (this._minerRepository == null)
                {
                    this._minerRepository = new MinerRepository();
                }

                if (args.OrderLineItemData.Sku == 102)
                {
                    Console.WriteLine("\t### Product with Sku 101 was purchased on {0} ###", DateTime.Now.ToLongDateString());
                }
            };
        }
示例#10
0
        public void Initialize(CommerceEvents events, NameValueCollection config)
        {
            events.BillingCart += args =>
            {
                Console.WriteLine("");
                Console.WriteLine("process customer credit card");
                Console.WriteLine("#################");
                Console.WriteLine("");

                var amount = args.OrderData.LineItems.Sum(lineItem => (lineItem.PurchasePrice * lineItem.Quantity));
                amount += args.ShippingCost;

                var paymentSuccess = args.PaymentProvider.ProcessCreditCard(
                    args.Customer.Name, args.OrderData.CreditCard, args.OrderData.ExpirationDate, amount);
                if (!paymentSuccess)
                {
                    throw new ApplicationException($"\tCredit card {args.OrderData.CreditCard} could not be processed.");
                }
            };
        }
示例#11
0
        public ConfigurationFactory()
        {
            CommerceEngineConfigurationSection config = ConfigurationManager.GetSection("commerceEngine") as CommerceEngineConfigurationSection;

            if (config != null)
            {
                IPaymentProcessor paymentProcessor = Activator.CreateInstance(Type.GetType(config.PaymentProcessor.Type)) as IPaymentProcessor;
                IMailer           mailer           = Activator.CreateInstance(Type.GetType(config.Mailer.Type)) as IMailer;
                mailer.FromAddress = config.Mailer.FromAddress;
                mailer.SmtpServer  = config.Mailer.SmtpServer;

                _PaymentProcessor = paymentProcessor;
                _Mailer           = mailer;

                // initialize modules
                _Events = new CommerceEvents();
                foreach (ProviderSettings moduleElement in config.Modules)
                {
                    ICommerceModule module = Activator.CreateInstance(Type.GetType(moduleElement.Type)) as ICommerceModule;
                    module.Initialize(_Events, moduleElement.Parameters);
                }
            }
        }
示例#12
0
 public void Initialize(CommerceEvents events, NameValueCollection config)
 {
     events.UpdateCart += args =>
     {
         Console.WriteLine("");
         Console.WriteLine("update customer records with purchase");
         Console.WriteLine("#################");
         Console.WriteLine("");
         foreach (var lineItem in args.OrderData.LineItems)
         {
             for (var i = 0; i < lineItem.Quantity; i++)
             {
                 args.Customer.Purchases.Add(
                     new PurchasedItem
                 {
                     Sku           = lineItem.Sku,
                     PurchasePrice = lineItem.PurchasePrice,
                     PurchasedOn   = DateTime.Now
                 });
             }
             Console.WriteLine($"\tAdded {lineItem.Quantity} unit(s) or product {lineItem.Sku} to customer's purchase history.");
         }
     };
 }
 public void Initialize(CommerceEvents events)
 {
     events.OrderItemProcessed += OnOrderItemProcessed;
 }
        public void Initialize(CommerceEvents events, NameValueCollection config)
        {
            events.AdjustOrder += args =>
            {
                foreach (var lineItem in args.OrderData.LineItems)
                {
                    #region 1 - Check for promotion

                    if (events.OrderItemProcessed != null)
                    {
                        var e = new OrderItemProcessedEventArgs(args.Customer, lineItem, null);
                        events.OrderItemProcessed(e);

                        if (e.Cancel)
                        {
                            // do something important
                            throw new ApplicationException(e.Message);
                        }
                    }

                    #endregion

                    #region 2 - Get product

                    var product =
                        args.StoreRepository.Products.FirstOrDefault(item => item.Sku == lineItem.Sku);
                    if (product == null)
                    {
                        throw new ApplicationException($"Sku {lineItem.Sku} not found in store inventory.");
                    }

                    #endregion

                    #region 3 - Get line item by sku

                    var inventoryOnHand =
                        args.StoreRepository.ProductInventory.FirstOrDefault(
                            item => item.Sku == lineItem.Sku);
                    if (inventoryOnHand == null)
                    {
                        throw new ApplicationException(
                                  $"Error attempting to determine on-hand inventory quantity for product {lineItem.Sku}.");
                    }

                    #endregion

                    #region 4 - Check if line item in stock

                    if (inventoryOnHand.QuantityInStock < lineItem.Quantity)
                    {
                        throw new ApplicationException(
                                  $"Not enough quantity on-hand to satisfy product {lineItem.Sku} purchase of {lineItem.Quantity} units.");
                    }

                    #endregion

                    #region 5 - Change stock of the line item

                    inventoryOnHand.QuantityInStock -= lineItem.Quantity;

                    Console.WriteLine(
                        $"\tInventory for product {lineItem.Sku} reduced by {lineItem.Quantity} units.");
                    Console.WriteLine();

                    #endregion
                }
            };
        }
示例#15
0
 /// <summary>
 /// Register service events
 /// </summary>
 /// <param name="services"></param>
 /// <returns></returns>
 public static IServiceCollection RegisterCommerceEvents(this IServiceCollection services)
 {
     //register commerce events
     CommerceEvents.RegisterEvents();
     return(services);
 }