コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting Notifications Service");

            while (true)
            {
                var utilityFactory = new UtilityFactory(new AmbientContext());
                var asyncUtility   = utilityFactory.CreateUtility <IAsyncUtility>();
                var item           = asyncUtility.CheckForNewItem();
                if (item != null)
                {
                    // If the queued message contains a Context then pass it along instead of creating a new one
                    var managerFactory      = new ManagerFactory(item.AmbientContext ?? new AmbientContext());
                    var notificationManager = managerFactory.CreateManager <INotificationManager>();

                    if (item.EventType == AsyncEventTypes.OrderSubmitted)
                    {
                        notificationManager.SendNewOrderNotices(item.EventId);
                    }
                    if (item.EventType == AsyncEventTypes.OrderShipped)
                    {
                        notificationManager.SendOrderFulfillmentNotices(item.EventId);
                    }
                }

                Thread.Sleep(5000); // sleep 5 seconds
            }
        }
コード例 #2
0
        BackOffice.OrderDataResponse BackOffice.IBackOfficeRemittanceManager.Totals()
        {
            try
            {
                // authenticate the user as a seller
                if (UtilityFactory.CreateUtility <ISecurityUtility>().BackOfficeAdminAuthenticated())
                {
                    var sellerOrderData = AccessorFactory.CreateAccessor <IRemittanceAccessor>()
                                          .SalesTotal();

                    if (sellerOrderData != null && sellerOrderData.Length > 0)
                    {
                        var result = new BackOffice.OrderDataResponse();
                        var items  = new List <BackOffice.SellerOrderData>();

                        foreach (var item in sellerOrderData)
                        {
                            var mapped = DTOMapper.Map <BackOffice.SellerOrderData>(item);

                            var calcResult = EngineFactory.CreateEngine <IRemittanceCalculationEngine>()
                                             .CalculateFee(mapped.SellerId, mapped.OrderTotal);

                            mapped.FeeAmount        = calcResult.FeeAmount;
                            mapped.RemittanceAmount = calcResult.RemittanceAmount;

                            items.Add(mapped);
                        }

                        result.Success         = true;
                        result.SellerOrderData = items.ToArray();
                        return(result);
                    }
                    else
                    {
                        return(new BackOffice.OrderDataResponse()
                        {
                            Success = false,
                            Message = "No orders"
                        });
                    }
                }
                return(new BackOffice.OrderDataResponse()
                {
                    Success = false,
                    Message = "BackOfficeAdmin not authenticated"
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(new BackOffice.OrderDataResponse()
                {
                    Success = false,
                    Message = "There was a problem accessing sellers orders"
                });
            }
        }
コード例 #3
0
        Admin.AdminCatalogResponse Admin.IAdminCatalogManager.SaveCatalog(Admin.WebStoreCatalog catalog)
        {
            try
            {
                // authenticate the user as a seller
                if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated())
                {
                    // map to the accessor DTO
                    DTO.WebStoreCatalog accCatalog = new DTO.WebStoreCatalog();
                    DTOMapper.Map(catalog, accCatalog);

                    accCatalog = AccessorFactory.CreateAccessor <ICatalogAccessor>().SaveCatalog(accCatalog);

                    if (accCatalog != null)
                    {
                        Admin.WebStoreCatalog result = new Admin.WebStoreCatalog();
                        DTOMapper.Map(accCatalog, result);

                        return(new Admin.AdminCatalogResponse()
                        {
                            Success = true,
                            Catalog = result
                        });
                    }
                    return(new Admin.AdminCatalogResponse()
                    {
                        Success = false,
                        Message = "Catalog not saved"
                    });
                }
                return(new Admin.AdminCatalogResponse()
                {
                    Success = false,
                    Message = "Seller not authenticated"
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(new Admin.AdminCatalogResponse()
                {
                    Success = false,
                    Message = "There was a problem saving the catalog"
                });
            }
        }
コード例 #4
0
        Admin.AdminProductResponse Admin.IAdminCatalogManager.ShowProduct(int catalogId, int productId)
        {
            try
            {
                //authenticate the seller
                if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated())
                {
                    var product = AccessorFactory.CreateAccessor <ICatalogAccessor>()
                                  .FindProduct(productId);

                    if (product != null)
                    {
                        if (product.CatalogId == catalogId)
                        {
                            Admin.Product result = new Admin.Product();
                            DTOMapper.Map(product, result);

                            return(new Admin.AdminProductResponse()
                            {
                                Success = true,
                                Product = result
                            });
                        }
                    }
                    return(new Admin.AdminProductResponse()
                    {
                        Success = false,
                        Message = "Product not found"
                    });
                }
                return(new Admin.AdminProductResponse()
                {
                    Success = false,
                    Message = "Seller not authenticated"
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(new Admin.AdminProductResponse()
                {
                    Success = false,
                    Message = "There was a problem accessing the product"
                });
            }
        }
コード例 #5
0
        Admin.AdminCatalogResponse Admin.IAdminCatalogManager.ShowCatalog(int catalogId)
        {
            try
            {
                // authenticate the user as a seller
                if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated())
                {
                    var catalog = AccessorFactory.CreateAccessor <ICatalogAccessor>()
                                  .Find(catalogId);

                    if (catalog != null)
                    {
                        if (catalog.SellerId == Context.SellerId)
                        {
                            Admin.WebStoreCatalog result = new Admin.WebStoreCatalog();
                            DTOMapper.Map(catalog, result);

                            return(new Admin.AdminCatalogResponse()
                            {
                                Success = true,
                                Catalog = result
                            });
                        }
                    }
                    return(new Admin.AdminCatalogResponse()
                    {
                        Success = false,
                        Message = "Catalog not found"
                    });
                }
                return(new Admin.AdminCatalogResponse()
                {
                    Success = false,
                    Message = "Seller not authenticated"
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(new Admin.AdminCatalogResponse()
                {
                    Success = false,
                    Message = "There was a problem accessing the catalog"
                });
            }
        }
コード例 #6
0
        Admin.AdminProductResponse Admin.IAdminCatalogManager.SaveProduct(int catalogId, Admin.Product product)
        {
            try
            {
                // authenticate the user as a seller
                if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated())
                {
                    // map to the accessor DTO
                    DTO.Product accProduct = new DTO.Product();
                    DTOMapper.Map(product, accProduct);

                    accProduct = AccessorFactory.CreateAccessor <ICatalogAccessor>().SaveProduct(catalogId, accProduct);

                    if (accProduct != null)
                    {
                        Admin.Product result = new Admin.Product();
                        DTOMapper.Map(accProduct, result);

                        return(new Admin.AdminProductResponse()
                        {
                            Success = true,
                            Product = result
                        });
                    }
                    return(new Admin.AdminProductResponse()
                    {
                        Success = false,
                        Message = "Product not saved"
                    });
                }
                return(new Admin.AdminProductResponse()
                {
                    Success = false,
                    Message = "Seller not authenticated"
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(new Admin.AdminProductResponse()
                {
                    Success = false,
                    Message = "There was a problem saving the product"
                });
            }
        }
コード例 #7
0
 public Admin.SalesTotalsResponse Totals()
 {
     try
     {
         // authenticate the user as a seller
         if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated())
         {
             var sellerSalesTotals = AccessorFactory.CreateAccessor <IOrderAccessor>()
                                     .SalesTotal();
             if (sellerSalesTotals != null)
             {
                 return(new Admin.SalesTotalsResponse()
                 {
                     Success = true,
                     OrderCount = sellerSalesTotals.OrderCount,
                     OrderTotal = sellerSalesTotals.OrderTotal
                 });
             }
             else
             {
                 return(new Admin.SalesTotalsResponse()
                 {
                     Success = false,
                     Message = "No orders for this Seller"
                 });
             }
         }
         return(new Admin.SalesTotalsResponse()
         {
             Success = false,
             Message = "Seller not authenticated"
         });
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         return(new Admin.SalesTotalsResponse()
         {
             Success = false,
             Message = "There was a problem accessing this seller's orders"
         });
     }
 }
コード例 #8
0
        public AdminOpenOrdersResponse GetOrdersToFulfill()
        {
            try
            {
                // authenticate the seller
                if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated())
                {
                    // get the unfilfilled orders for the seller
                    var orders = AccessorFactory.CreateAccessor <SalesAcc.IOrderAccessor>().UnfulfilledOrders();

                    List <AdminUnfulfilledOrder> orderList = new List <AdminUnfulfilledOrder>();
                    foreach (var order in orders)
                    {
                        // map them to the contract dto and add to the list
                        AdminUnfulfilledOrder unfulfilledOrder = new AdminUnfulfilledOrder();
                        DTOMapper.Map(order, unfulfilledOrder);
                        orderList.Add(unfulfilledOrder);
                    }
                    return(new AdminOpenOrdersResponse()
                    {
                        Success = true,
                        Orders = orderList.ToArray()
                    });
                }
                return(new AdminOpenOrdersResponse()
                {
                    Success = false,
                    Message = "Seller not authenticated"
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                return(new AdminOpenOrdersResponse()
                {
                    Success = false,
                    Message = "There was a problem returning the unfulfilled orders"
                });
            }
        }
コード例 #9
0
        Admin.AdminCatalogsResponse Admin.IAdminCatalogManager.FindCatalogs()
        {
            try
            {
                // authenticate the user as a seller
                if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated())
                {
                    var catalogs = AccessorFactory.CreateAccessor <ICatalogAccessor>()
                                   .FindAllSellerCatalogs();

                    List <Admin.WebStoreCatalog> catalogList = new List <Admin.WebStoreCatalog>();
                    foreach (var catalog in catalogs)
                    {
                        Admin.WebStoreCatalog result = new Admin.WebStoreCatalog();
                        DTOMapper.Map(catalog, result);
                        catalogList.Add(result);
                    }
                    return(new Admin.AdminCatalogsResponse()
                    {
                        Success = true,
                        Catalogs = catalogList.ToArray()
                    });
                }
                return(new Admin.AdminCatalogsResponse()
                {
                    Success = false,
                    Message = "Seller not authenticated"
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(new Admin.AdminCatalogsResponse()
                {
                    Success = false,
                    Message = "There was a problem accessing this seller's catalogs"
                });
            }
        }
コード例 #10
0
        public AdminFulfillmentResponse FulfillOrder(int orderId)
        {
            try
            {
                // authenticate the seller
                if (UtilityFactory.CreateUtility <ISecurityUtility>().SellerAuthenticated())
                {
                    var orderAccessor = AccessorFactory.CreateAccessor <SalesAcc.IOrderAccessor>();
                    var order         = orderAccessor.FindOrder(orderId);
                    // Make sure the order is available and has a staus that is appropriate for fulfillment
                    if (order != null && order.Status == OrderStatuses.Authorized)
                    {
                        // capture the payment
                        var captureResult = AccessorFactory.CreateAccessor <SalesAcc.IPaymentAccessor>()
                                            .Capture(order.AuthorizationCode);

                        if (captureResult.Success)
                        {
                            // update the order status
                            order = orderAccessor.UpdateOrderStatus(orderId, OrderStatuses.Captured, "");

                            // notify the shipping provider
                            var shippingResult = AccessorFactory.CreateAccessor <SalesAcc.IShippingAccessor>().RequestShipping(order.Id);
                            if (shippingResult.Success)
                            {
                                // fulfill the order
                                order = orderAccessor.FulfillOrder(orderId, shippingResult.ShippingProvider, shippingResult.TrackingCode, "");

                                // send the fullfillment event
                                UtilityFactory.CreateUtility <IAsyncUtility>().SendEvent(AsyncEventTypes.OrderShipped, order.Id);

                                // return the result
                                return(new AdminFulfillmentResponse()
                                {
                                    Success = true
                                });
                            }
                            //TODO: send a message to manual order management
                            //Update the order notes with message from shipping failure
                            order = orderAccessor.UpdateOrderStatus(orderId, order.Status, "Unable to request shipping for order");
                            return(new AdminFulfillmentResponse()
                            {
                                Success = false,
                                Message = order.Notes
                            });
                        }
                        // TODO: send a message to manual order management
                        // Update the order notes with message from capture failure
                        order = orderAccessor.UpdateOrderStatus(orderId, order.Status, "Capture failed for authorization");
                        return(new AdminFulfillmentResponse()
                        {
                            Success = false,
                            Message = order.Notes
                        });
                    }
                    // TODO: send a message to manual order management
                    return(new AdminFulfillmentResponse()
                    {
                        Success = false,
                        Message = "Invalid order for fulfillment"
                    });
                }
                return(new AdminFulfillmentResponse()
                {
                    Success = false,
                    Message = "Seller not authenticated"
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                return(new AdminFulfillmentResponse()
                {
                    Success = false,
                    Message = "There was a problem fulfilling the order"
                });
            }
        }
コード例 #11
0
        public WebStore.WebStoreOrderResponse SubmitOrder(int catalogId, PaymentInstrument paymentInstrument)
        {
            try
            {
                var result = new WebStore.WebStoreOrder();

                // Get the shopping cart
                SalesAcc.ICartAccessor cartAccessor = AccessorFactory.CreateAccessor <SalesAcc.ICartAccessor>();

                var storedCart = cartAccessor.ShowCart(catalogId);

                // make sure we have a valid cart to start
                if (storedCart != null)
                {
                    // Calculate the cart totals and tax
                    var fullCart = GenerateCartPricingAndTax(storedCart);

                    // create the order records
                    SalesAcc.IOrderAccessor orderAccessor = AccessorFactory.CreateAccessor <SalesAcc.IOrderAccessor>();

                    var submittedOrder = new Order();
                    DTOMapper.Map(fullCart, submittedOrder);

                    // validate the order
                    var validationEngine   = EngineFactory.CreateEngine <IOrderValidationEngine>();
                    var validationResponse = validationEngine.ValidateOrder(submittedOrder);

                    if (validationResponse.Success)
                    {
                        submittedOrder.Status = OrderStatuses.Created;
                        var savedOrder = orderAccessor.SaveOrder(catalogId, submittedOrder);

                        // attempt the payment authorization if amount > 0
                        if (savedOrder.Total > 0)
                        {
                            SalesAcc.IPaymentAccessor paymentAccessor = AccessorFactory.CreateAccessor <SalesAcc.IPaymentAccessor>();
                            var authResult = paymentAccessor.Authorize(paymentInstrument, savedOrder.Id, savedOrder.Total);

                            if (authResult.Success)
                            {
                                // save the auth code for use in capture
                                savedOrder.AuthorizationCode = authResult.AuthCode;
                            }
                            else // problems with the authorization
                            {
                                // update the order status
                                savedOrder.Status = OrderStatuses.Failed;
                                savedOrder        = orderAccessor.SaveOrder(catalogId, savedOrder);

                                // Return the order response
                                DTOMapper.Map(savedOrder, result);
                                return(new WebStore.WebStoreOrderResponse()
                                {
                                    Success = false,
                                    Message = "There was a problem processing the payment",
                                    Order = result
                                });
                            }
                        }
                        // update the order status
                        savedOrder.Status = OrderStatuses.Authorized;
                        savedOrder        = orderAccessor.SaveOrder(catalogId, savedOrder);


                        // Delete the cart once the order is successful
                        cartAccessor.DeleteCart(catalogId);

                        // send order submission event
                        UtilityFactory.CreateUtility <IAsyncUtility>().SendEvent(AsyncEventTypes.OrderSubmitted, savedOrder.Id);

                        // Return the order response
                        DTOMapper.Map(savedOrder, result);
                        return(new WebStore.WebStoreOrderResponse()
                        {
                            Success = true,
                            Order = result
                        });
                    }
                    // order is not valid
                    return(new WebStore.WebStoreOrderResponse()
                    {
                        Success = false,
                        Message = validationResponse.Message
                    });
                }
                // cart not found or not valid
                return(new WebStore.WebStoreOrderResponse()
                {
                    Success = false,
                    Message = "Cart is not valid"
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);

                return(new WebStore.WebStoreOrderResponse()
                {
                    Success = false,
                    Message = "There was a problem processing the order"
                });
            }
        }
コード例 #12
0
        public ValidationResponse ValidateOrder(Order order)
        {
            var response = new ValidationResponse()
            {
                Success = false
            };
            decimal calculatedSubtotal = 0;

            // Make sure we don't have a null input
            if (order == null)
            {
                response.Message = "Order is invalid";
                return(response);
            }

            // Make sure the cart has items for purchase
            if (order.OrderLines == null || order.OrderLines.Length == 0)
            {
                response.Message = "Order has no order lines";
                return(response);
            }

            // make sure the cart amounts have been determined
            foreach (var orderLine in order.OrderLines)
            {
                decimal lineTotal = (orderLine.UnitPrice * orderLine.Quantity);
                if (lineTotal != orderLine.ExtendedPrice)
                {
                    response.Message = "Invalid order line pricing";
                    return(response);
                }

                calculatedSubtotal += lineTotal;
            }

            // make sure line amounts sum to order amounts
            if (order.SubTotal != calculatedSubtotal)
            {
                response.Message = "Invalid order subtotal";
                return(response);
            }

            // make sure remaining totals are valid
            if ((order.SubTotal + order.TaxAmount) != order.Total)
            {
                response.Message = "Invalid order total";
                return(response);
            }

            // make sure the shipping address is valid and complete
            var addressUtility = UtilityFactory.CreateUtility <IAddressUtility>();

            if (!addressUtility.ValidateAddress(order.ShippingAddress))
            {
                response.Message = "ShippingAddress address is not valid";
                return(response);
            }

            // if there is a cart total, make sure the billign address is valid and complete
            if (order.SubTotal > 0 && !addressUtility.ValidateAddress(order.BillingAddress))
            {
                response.Message = "BillingAddress address is not valid";
                return(response);
            }

            // all is good
            return(new ValidationResponse()
            {
                Success = true
            });
        }