Exemplo n.º 1
0
        public IPurchaseOrder GetByPayeeReference(string payeeReference)
        {
            OrderSearchOptions searchOptions = new OrderSearchOptions
            {
                CacheResults      = false,
                StartingRecord    = 0,
                RecordsToRetrieve = 1,
                Classes           = new System.Collections.Specialized.StringCollection {
                    "PurchaseOrder"
                },
                Namespace = "Mediachase.Commerce.Orders"
            };

            var parameters = new OrderSearchParameters
            {
                SqlMetaWhereClause = $"META.{Constants.SwedbankPayPayeeReference} = '{payeeReference}'"
            };

            var purchaseOrder = OrderContext.Current.Search <PurchaseOrder>(parameters, searchOptions)?.FirstOrDefault();

            if (purchaseOrder != null)
            {
                return(_orderRepository.Load <IPurchaseOrder>(purchaseOrder.OrderGroupId));
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finds the purchase orders.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public PurchaseOrder[] FindPurchaseOrders(OrderSearchParameters parameters, OrderSearchOptions options)
        {
            int totalRecords = 0;

            PurchaseOrder[] pos = FindPurchaseOrders(parameters, options, out totalRecords);
            return(pos);
        }
Exemplo n.º 3
0
        public static PurchaseOrder GetOrderByTrackingNumber(string orderId)
        {
            var orderSearchParameters = new OrderSearchParameters {
                SqlMetaWhereClause = $@"META.TrackingNumber = '{orderId}'"
            };

            var orderSearchOptions = new OrderSearchOptions {
                Namespace = "Mediachase.Commerce.Orders"
            };

            orderSearchOptions.Classes.Add("PurchaseOrder");
            orderSearchOptions.Classes.Add("Shipment");
            orderSearchOptions.CacheResults      = false;
            orderSearchOptions.RecordsToRetrieve = 1;

            var purchaseOrders = OrderContext.Current.FindPurchaseOrders(orderSearchParameters, orderSearchOptions).ToList();

            if (purchaseOrders.Count > 0)
            {
                // order was found
                return(purchaseOrders.FirstOrDefault());
            }
            else if (int.TryParse(orderId, out var orderIdNumeric))
            {
                // order was not found; try to get by id
                return(OrderContext.Current.GetPurchaseOrderById(orderIdNumeric));
            }

            return(null);
        }
Exemplo n.º 4
0
        public virtual IHttpActionResult GetOrders(int start, int maxCount)
        {
            Logger.LogGet("GetOrders", Request, new [] { start.ToString(), maxCount.ToString() });

            if (maxCount < 1 || maxCount > 100)
            {
                maxCount = 10;
            }

            try
            {
                // http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Commerce/9/Orders/Searching-for-orders/
                var searchOptions = new OrderSearchOptions
                {
                    CacheResults      = false,
                    StartingRecord    = start,
                    RecordsToRetrieve = maxCount,
                    Namespace         = "Mediachase.Commerce.Orders"
                };

                var parameters = new OrderSearchParameters();
                searchOptions.Classes.Add("PurchaseOrder");
                parameters.SqlMetaWhereClause = "META.TrackingNumber LIKE '%PO%'";
                parameters.SqlWhereClause     = "OrderGroupId IN (SELECT OrdergroupId FROM Shipment WHERE NOT ShipmentTrackingNumber IS NULL)";

                var orders = OrderContext.Current.FindPurchaseOrders(parameters, searchOptions);
                return(Ok(orders.Select(x => x.ConvertToPurchaseOrder()).ToArray()));
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                return(InternalServerError(exception));
            }
        }
Exemplo n.º 5
0
        public IPurchaseOrder GetPurchaseOrderByKlarnaOrderId(string orderId)
        {
            OrderSearchOptions searchOptions = new OrderSearchOptions
            {
                CacheResults      = false,
                StartingRecord    = 0,
                RecordsToRetrieve = 1,
                Classes           = new System.Collections.Specialized.StringCollection {
                    "PurchaseOrder"
                },
                Namespace = "Mediachase.Commerce.Orders"
            };

            var parameters = new OrderSearchParameters();

            parameters.SqlMetaWhereClause = $"META.{Constants.KlarnaOrderIdField} LIKE '{orderId}'";

            var purchaseOrder = OrderContext.Current.FindPurchaseOrders(parameters, searchOptions)?.FirstOrDefault();

            if (purchaseOrder != null)
            {
                return(_orderRepository.Load <IPurchaseOrder>(purchaseOrder.OrderGroupId));
            }
            return(null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Finds the payment plans.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public PaymentPlan[] FindPaymentPlans(OrderSearchParameters parameters, OrderSearchOptions options)
        {
            int totalRecords = 0;

            PaymentPlan[] plans = FindPaymentPlans(parameters, options, out totalRecords);
            return(plans);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Finds the carts.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public Cart[] FindCarts(OrderSearchParameters parameters, OrderSearchOptions options)
        {
            int totalRecords = 0;

            Cart[] carts = FindCarts(parameters, options, out totalRecords);
            return(carts);
        }
Exemplo n.º 8
0
        public virtual IHttpActionResult GetCarts(int start, int maxCount)
        {
            Logger.LogGet("GetCarts", Request, new [] { start.ToString(), maxCount.ToString() });

            if (maxCount < 1 || maxCount > 100)
            {
                maxCount = 10;
            }

            Cart[] carts;

            try
            {
                // http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Commerce/9/Orders/Searching-for-orders/
                OrderSearchOptions searchOptions = new OrderSearchOptions
                {
                    CacheResults      = false,
                    StartingRecord    = start,
                    RecordsToRetrieve = maxCount,
                    Namespace         = "Mediachase.Commerce.Orders"
                };

                OrderSearchParameters parameters = new OrderSearchParameters();
                searchOptions.Classes.Add("LineItemEx");
                parameters.SqlWhereClause = "OrderGroupId IN (Select ObjectId FROM OrderGroup_ShoppingCart)";
                carts = OrderContext.Current.FindCarts(parameters, searchOptions);
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                return(InternalServerError(exception));
            }

            return(Ok(carts));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Finds the carts.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="options">The options.</param>
        /// <param name="totalRecords">The total records.</param>
        /// <returns></returns>
        public Cart[] FindCarts(OrderSearchParameters parameters, OrderSearchOptions options, out int totalRecords)
        {
            OrderSearch search = new OrderSearch(this);

            search.SearchOptions    = options;
            search.SearchParameters = parameters;
            MetaStorageCollectionBase <Cart> orders = Cart.Search(search, out totalRecords);

            return(orders.ToArray());
        }
Exemplo n.º 10
0
        /// <summary>
        /// Finds the payment plans.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="options">The options.</param>
        /// <param name="totalRecords">The total records.</param>
        /// <returns></returns>
        public PaymentPlan[] FindPaymentPlans(OrderSearchParameters parameters, OrderSearchOptions options, out int totalRecords)
        {
            OrderSearch search = new OrderSearch(this);

            search.SearchOptions    = options;
            search.SearchParameters = parameters;

            MetaStorageCollectionBase <PaymentPlan> orders = PaymentPlan.Search(search, out totalRecords);

            return(orders.ToArray());
        }
Exemplo n.º 11
0
        private PurchaseOrder GetMockOrder()
        {
            var parameters = new OrderSearchParameters
            {
                SqlMetaWhereClause = "[ObjectId] = (SELECT TOP 1 OrderGroupId FROM OrderGroup order by Total desc)"
            };

            var options = new OrderSearchOptions
            {
                RecordsToRetrieve = 1,
                Classes = new StringCollection { "PurchaseOrder" }
            };

            return OrderContext.Current.FindPurchaseOrders(parameters, options).FirstOrDefault();
        }
Exemplo n.º 12
0
        private PurchaseOrder GetMockOrder()
        {
            var parameters = new OrderSearchParameters
            {
                SqlMetaWhereClause = "[ObjectId] = (SELECT TOP 1 OrderGroupId FROM OrderGroup order by Total desc)"
            };

            var options = new OrderSearchOptions
            {
                RecordsToRetrieve = 1,
                Classes           = new StringCollection {
                    "PurchaseOrder"
                }
            };

            return(OrderContext.Current.FindPurchaseOrders(parameters, options).FirstOrDefault());
        }
Exemplo n.º 13
0
        private IPurchaseOrder GetPurchaseOrder(string orderId, bool cacheResults)
        {
            var searchOptions = new OrderSearchOptions
            {
                CacheResults      = cacheResults,
                StartingRecord    = 0,
                RecordsToRetrieve = 1,
                Classes           = new StringCollection {
                    "PurchaseOrder"
                },
                Namespace = "Mediachase.Commerce.Orders"
            };

            var parameters = new OrderSearchParameters
            {
                SqlMetaWhereClause = $"META.{VippsConstants.VippsOrderIdField} = '{orderId}'"
            };

            return(OrderContext.Current.Search <PurchaseOrder>(parameters, searchOptions)?.FirstOrDefault());
        }
        public static List<PurchaseOrder> GetOrders(string sqlWhereClause, string sqlMetaWhereClause, int recordCount = int.MaxValue)
        {
            var orderSearchParameters = new OrderSearchParameters();
            if (!string.IsNullOrEmpty(sqlWhereClause))
            {
                orderSearchParameters.SqlWhereClause = sqlWhereClause;
            }

            if (!string.IsNullOrEmpty(sqlMetaWhereClause))
            {
                orderSearchParameters.SqlMetaWhereClause = sqlMetaWhereClause;
            }

            var orderSearchOptions = new OrderSearchOptions();
            orderSearchOptions.Namespace = "Mediachase.Commerce.Orders";
            orderSearchOptions.Classes.Add("PurchaseOrder");
            orderSearchOptions.Classes.Add("Shipment");
            orderSearchOptions.CacheResults = false;
            orderSearchOptions.RecordsToRetrieve = recordCount;

            return OrderContext.Current.FindPurchaseOrders(orderSearchParameters, orderSearchOptions).ToList();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Processes the application.
        /// </summary>
        /// <param name="applicationName">Name of the application.</param>
        void ProcessApplication(string applicationName)
        {
            _Log.Info(String.Format("Processing Payment Plans for \"{0}\" application.", applicationName));

            try
            {
                int totalRecords                 = -1;
                int startRowIndex                = 0;
                OrderSearchOptions    options    = new OrderSearchOptions();
                OrderSearchParameters parameters = new OrderSearchParameters();
                options.Namespace = "Mediachase.Commerce.Orders";
                options.Classes.Add("PaymentPlan");
                options.RecordsToRetrieve = 50;
                parameters.OrderByClause  = String.Format("OrderGroupId DESC");

                do
                {
                    options.StartingRecord = startRowIndex;
                    PaymentPlan[] orders = OrderContext.Current.FindPaymentPlans(parameters, options, out totalRecords);

                    if (orders != null)
                    {
                        foreach (PaymentPlan plan in orders)
                        {
                            // Charge the plan
                            ProcessPlan(plan);
                        }
                    }

                    startRowIndex += options.RecordsToRetrieve;
                }while (totalRecords > 0);

                _Log.Info("Successfully completed.");
            }
            catch (Exception ex)
            {
                _Log.Error("Processing Payment Plans failed.", ex);
            }
        }
Exemplo n.º 16
0
        public static List <PurchaseOrder> GetOrders(string sqlWhereClause, string sqlMetaWhereClause, int recordCount = int.MaxValue)
        {
            var orderSearchParameters = new OrderSearchParameters();

            if (!string.IsNullOrEmpty(sqlWhereClause))
            {
                orderSearchParameters.SqlWhereClause = sqlWhereClause;
            }

            if (!string.IsNullOrEmpty(sqlMetaWhereClause))
            {
                orderSearchParameters.SqlMetaWhereClause = sqlMetaWhereClause;
            }

            var orderSearchOptions = new OrderSearchOptions();

            orderSearchOptions.Namespace = "Mediachase.Commerce.Orders";
            orderSearchOptions.Classes.Add("PurchaseOrder");
            orderSearchOptions.Classes.Add("Shipment");
            orderSearchOptions.CacheResults      = false;
            orderSearchOptions.RecordsToRetrieve = recordCount;

            return(OrderContext.Current.FindPurchaseOrders(orderSearchParameters, orderSearchOptions).ToList());
        }
    /// <summary>
    /// Returns a Cart based on the PayEx orderReference
    /// </summary>
    /// <param name="orderRef">PayEx orderReference</param>
    /// <param name="orderNumber">Order number</param>
    /// <returns>Cart</returns>
    private Cart GetCartByOrderRef(string orderRef, out string orderNumber)
    {
        var parameters = new OrderSearchParameters
        {
            SqlMetaWhereClause = "",
            SqlWhereClause     = "OrderGroupId IN (SELECT OrderGroupId FROM OrderFormPayment WHERE TransactionType LIKE 'Authorization' AND Status LIKE 'Pending')"
        };
        var options = new OrderSearchOptions
        {
            Classes = new StringCollection {
                "ShoppingCart"
            },
            CacheResults      = false,
            RecordsToRetrieve = 10000,
            Namespace         = "Mediachase.Commerce.Orders"
        };

        var carts = OrderContext.Current.FindCarts(parameters, options);

        foreach (var cart in carts)
        {
            var payment = GetPayExPayment(cart);
            if (payment == null || string.IsNullOrWhiteSpace(payment.PayExOrderRef))
            {
                continue;
            }

            if (payment.PayExOrderRef.Equals(orderRef))
            {
                orderNumber = payment.OrderNumber;
                return(cart);
            }
        }
        orderNumber = string.Empty;
        return(null);
    }
Exemplo n.º 18
0
        public IPurchaseOrder GetByTrackingNumber(string trackingNumber)
        {
            OrderSearchOptions searchOptions = new OrderSearchOptions();

            searchOptions.CacheResults      = false;
            searchOptions.StartingRecord    = 0;
            searchOptions.RecordsToRetrieve = 1;
            searchOptions.Classes           = new System.Collections.Specialized.StringCollection {
                "PurchaseOrder"
            };
            searchOptions.Namespace = "Mediachase.Commerce.Orders";

            var parameters = new OrderSearchParameters();

            parameters.SqlMetaWhereClause = $"META.TrackingNumber = '{trackingNumber}'";

            var purchaseOrder = OrderContext.Current.FindPurchaseOrders(parameters, searchOptions)?.FirstOrDefault();

            if (purchaseOrder != null)
            {
                return(_orderRepository.Load <IPurchaseOrder>(purchaseOrder.OrderGroupId));
            }
            return(null);
        }
Exemplo n.º 19
0
        public virtual IHttpActionResult SearchOrders(int start, int maxCount, [FromUri(Name = "")] SearchOrdersRequest request)
        {
            Logger.LogGet("GetOrders", Request, new[] { start.ToString(), maxCount.ToString(), $"{request?.OrderShipmentStatus}", $"{request?.ShippingMethodId}" });

            if (maxCount < 1 || maxCount > 100)
            {
                maxCount = 10;
            }

            try
            {
                var searchOptions = new OrderSearchOptions
                {
                    CacheResults      = false,
                    StartingRecord    = start,
                    RecordsToRetrieve = maxCount,
                    Namespace         = "Mediachase.Commerce.Orders"
                };

                var parameters = new OrderSearchParameters();
                searchOptions.Classes.Add("PurchaseOrder");
                parameters.SqlMetaWhereClause = string.Empty;

                if (request?.ModifiedFrom.HasValue ?? false)
                {
                    parameters.SqlMetaWhereClause = $"META.Modified >= '{request.ModifiedFrom.Value:s}'";
                }

                if (request?.OrderShipmentStatus != null && request.ShippingMethodId != null && request.ShippingMethodId != Guid.Empty)
                {
                    parameters.SqlWhereClause =
                        $"[OrderGroupId] IN (SELECT [OrderGroupId] FROM [Shipment] WHERE [Status] = '{request.OrderShipmentStatus}' AND [ShippingMethodId] = '{request.ShippingMethodId}')";
                }
                else if (request?.OrderShipmentStatus != null)
                {
                    parameters.SqlWhereClause = $"[OrderGroupId] IN (SELECT [OrderGroupId] FROM [Shipment] WHERE [Status] = '{request.OrderShipmentStatus}')";
                }
                else if (request?.ShippingMethodId != null && request.ShippingMethodId != Guid.Empty)
                {
                    parameters.SqlWhereClause = $"[OrderGroupId] IN (SELECT [OrderGroupId] FROM [Shipment] WHERE [ShippingMethodId] = '{request.ShippingMethodId}')";
                }

                if (request != null && request.Status?.Length > 0)
                {
                    if (!string.IsNullOrEmpty(parameters.SqlWhereClause))
                    {
                        parameters.SqlWhereClause += " AND ";
                    }

                    var statusesParam = string.Join(",", request.Status.Select(x => $"'{x}'"));
                    parameters.SqlWhereClause += $"Status IN ({statusesParam})";
                }

                var orders = OrderContext.Current.FindPurchaseOrders(parameters, searchOptions);
                return(Ok(orders.Select(x => x.ConvertToPurchaseOrder()).ToArray()));
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                return(InternalServerError(exception));
            }
        }