Exemple #1
0
        public void CheckFor(string repNumber, int currentOrderId)
        {
            var orderApiClient = ByDesignAPIHelper.CreateOrderAPIClient();
            var orderApiCred   = orderApiClient.CreateCredentials();

            string[] startKitIds     = Properties.Settings.Default.Freedom_StartKitItemId.Split(',');
            bool     isStartKitFound = false;

            var requestOrderListRange  = new GetOrderListRangeRequest(orderApiCred, Properties.Settings.Default.Freedom_StartKitCheckDateFrom, DateTime.Now, null);
            var responseOrderListRange = orderApiClient.GetOrderListRange(requestOrderListRange);

            foreach (var orderList in responseOrderListRange.GetOrderListRangeResult
                     .OrderBy(x => x.OrderID))
            {
                if (isStartKitFound)
                {
                    break;
                }

                if (orderList.Success > 0)
                {
                    var responseOrderInfo = orderApiClient.GetOrderInfo_V2(orderApiCred, orderList.OrderID);
                    if (responseOrderInfo.Success == 0)
                    {
                        throw new InvalidOperationException(responseOrderInfo.Message);
                    }

                    if (responseOrderInfo.RepNumber.Equals(repNumber))
                    {
                        foreach (var startKitId in startKitIds)
                        {
                            var responseOrderDetails = orderApiClient.GetOrderDetailsInfo_V2(orderApiCred, orderList.OrderID);
                            if (responseOrderDetails.Success == 0)
                            {
                                throw new InvalidOperationException(responseOrderDetails.Message);
                            }

                            isStartKitFound = responseOrderDetails.OrderDetailsResponse
                                              .Any(x => x.ProductID.Equals(startKitId));

                            if (isStartKitFound)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            if (!isStartKitFound)
            {
                throw new InvalidOperationException("Стартовый продуктовый набор должен быть заказан");
            }
        }
Exemple #2
0
        private void FillFromFreedom(DeliveryParameters deliveryParameters, int orderId)
        {
            var orderApiClient       = ByDesignAPIHelper.CreateOrderAPIClient();
            var orderDetailsResponse = orderApiClient.GetOrderDetailsInfo_V2(orderApiClient.CreateCredentials(), orderId);

            if (orderDetailsResponse.Success == 0)
            {
                throw new InvalidOperationException(orderDetailsResponse.Message);
            }

            List <DeliveryItem> deliveryItems = new List <DeliveryItem>();

            foreach (var responseItem in orderDetailsResponse.OrderDetailsResponse)
            {
                deliveryItems.Add(new DeliveryItem
                {
                    ItemId   = responseItem.ProductID,
                    Name     = responseItem.Description,
                    Quantity = responseItem.Quantity,
                    Cost     = decimal.Parse(responseItem.TaxableAmount, CultureInfo.InvariantCulture),
                    PayCost  = decimal.Parse(responseItem.TaxableAmount, CultureInfo.InvariantCulture)
                });
            }

            var orderInfoResponse = orderApiClient.GetOrderInfo_V2(orderApiClient.CreateCredentials(), orderId);

            if (orderInfoResponse.Success == 0)
            {
                throw new InvalidOperationException(orderInfoResponse.Message);
            }

            Address deliveryAddress = new Address
            {
                PostIndex = orderInfoResponse.ShipPostalCode,
                Country   = orderInfoResponse.ShipCountry,
                State     = orderInfoResponse.ShipState,
                Place     = orderInfoResponse.ShipCity,
                Street_1  = orderInfoResponse.ShipStreet1,
                Street_2  = orderInfoResponse.ShipStreet2
            };

            DeliveryRecipient recipient = new DeliveryRecipient
            {
                FullName = orderInfoResponse.ShipName1,
                Phone    = orderInfoResponse.ShipPhone,
                Email    = orderInfoResponse.ShipEmail
            };

            deliveryParameters.Items           = deliveryItems.ToArray();
            deliveryParameters.DeliveryAddress = deliveryAddress;
            deliveryParameters.Recipient       = recipient;
        }
        private void FillFromFreedomHeader(DeliveryParameters deliveryParameters)
        {
            var orderApiClient = ByDesignAPIHelper.CreateOrderAPIClient();

            var responseOrderInfo = orderApiClient.GetOrderInfo_V2(orderApiClient.CreateCredentials(), deliveryParameters.OrderId);

            if (responseOrderInfo.Success == 0)
            {
                throw new InvalidOperationException(responseOrderInfo.Message);
            }

            deliveryParameters.Status       = responseOrderInfo.Status;
            deliveryParameters.ShipMethodId = responseOrderInfo.ShipMethodID;
            deliveryParameters.ShipMethod   = responseOrderInfo.ShipMethod;
        }
        public void CheckFor(string custNumber, int currentOrderId)
        {
            var orderApiClient = ByDesignAPIHelper.CreateOrderAPIClient();
            var orderApiCred   = orderApiClient.CreateCredentials();

            string[] startKitIds     = Properties.Settings.Default.Freedom_StartKitItemId.Split(',');
            bool     isStartKitFound = false;

            foreach (var startKitId in startKitIds)
            {
                if (isStartKitFound)
                {
                    break;
                }

                var responseClientDidOrder = orderApiClient.CheckOrderedItemForCustomerDIDWithinDate_V2(
                    orderApiCred,
                    custNumber,
                    startKitId,
                    Properties.Settings.Default.Freedom_StartKitCheckDateFrom);

                if (responseClientDidOrder.Success == 0)
                {
                    throw new InvalidOperationException($"Не удается проверить заказы с товаром '{startKitId}' для клиента '{custNumber}'");
                }

                isStartKitFound = (responseClientDidOrder.OrderID > 0); // checking without payment

                if (!isStartKitFound)
                {
                    var orderDetailsResponse = orderApiClient.GetOrderDetailsInfo_V2(orderApiCred, currentOrderId);
                    if (orderDetailsResponse.Success == 0)
                    {
                        throw new InvalidOperationException(orderDetailsResponse.Message);
                    }

                    isStartKitFound = orderDetailsResponse.OrderDetailsResponse
                                      .Any(x => x.ProductID.Equals(startKitId));
                }
            }

            if (!isStartKitFound)
            {
                throw new InvalidOperationException("Стартовый продуктовый набор должен быть заказан");
            }
        }
        private List <DeliveryParameters> ReadOrdersToDelivery()
        {
            var result = new List <DeliveryParameters>();

            var orderApiClient = ByDesignAPIHelper.CreateOrderAPIClient();
            var orderApiCred   = orderApiClient.CreateCredentials();

            var requestOrderListRecent = new GetOrderListRecentRequest();

            requestOrderListRecent.Credentials          = orderApiCred;
            requestOrderListRecent.PeriodType           = Properties.Settings.Default.Freedom_RecentPeriodType;
            requestOrderListRecent.PeriodLength         = Properties.Settings.Default.Freedom_RecentPeriodLength;
            requestOrderListRecent.EvalDateLastModified = true;
            var responseOrderList = orderApiClient.GetOrderListRecent(requestOrderListRecent);

            foreach (var orderList in responseOrderList.GetOrderListRecentResult)
            {
                var orderToDelivery = new DeliveryParameters
                {
                    OrderId    = orderList.OrderID,
                    CreatedAt  = orderList.CreatedDate,
                    ModifiedAt = orderList.LastModifiedDate
                };

                FillFromFreedomHeader(orderToDelivery);

                if (orderToDelivery.IsPosted && !orderToDelivery.IsSelfPickup)
                {
                    FillFromFreedomDetails(orderToDelivery);
                    FillItemWeights(orderToDelivery);

                    result.Add(orderToDelivery);
                }
            }

            return(result);
        }
Exemple #6
0
        public void ProcessNotification(PaymentNotificationData data)
        {
            try
            {
                int orderId = 0;
                if (int.TryParse(data.mnt_transaction_id, out orderId))
                {
                    var orderApiClient = ByDesignAPIHelper.CreateOrderAPIClient();
                    var orderApiCred   = orderApiClient.CreateCredentials();
                    var response       = orderApiClient.GetOrderInfo_V2(orderApiCred, orderId);

                    if (response.Success > 0)
                    {
                        int custNum = 0;
                        if (int.TryParse(response.CustomerNumber, out custNum))
                        {
                            if (custNum >= 2000)
                            {
                                var orderDetailsResponse = orderApiClient.GetOrderDetailsInfo_V2(orderApiCred, orderId);
                                if (orderDetailsResponse.Success == 0)
                                {
                                    throw new InvalidOperationException(orderDetailsResponse.Message);
                                }

                                if (orderDetailsResponse.OrderDetailsResponse
                                    .Any(x => x.ProductID.Equals(Properties.Settings.Default.Freedom_VipKitItemId)))
                                {
                                    // change customer type
                                    var onlineApiClient = ByDesignAPIHelper.CreateOnlineAPIClient();
                                    var onlineApiCred   = onlineApiClient.CreateCredentials();

                                    var types         = onlineApiClient.GetCustomerTypes(onlineApiCred);
                                    var preferredType = types.FirstOrDefault(x => x.Abbreviation.Equals(CustomerType_Preferred));
                                    if (preferredType != null)
                                    {
                                        onlineApiClient.SetCustomerType(onlineApiCred, response.CustomerNumber, preferredType.ID);
                                    }
                                }
                            }
                        }

                        OrderStatus currentStatus = OrderStatus.Unknown;
                        if (Enum.TryParse(response.Status, out currentStatus))
                        {
                            if (currentStatus == OrderStatus.Entered)
                            {
                                orderApiClient.SetStatusPosted(orderApiCred, orderId, 0);

                                using (BiWellEntities context = new BiWellEntities())
                                {
                                    order_payment payment = new order_payment
                                    {
                                        order_id   = orderId,
                                        amount     = decimal.Parse(data.mnt_amount, CultureInfo.InvariantCulture),
                                        created_at = DateTime.UtcNow
                                    };

                                    context.order_payment.Add(payment);
                                    context.SaveChanges();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _looger.Log(ex.Message);
            }
        }
        private void FillFromFreedomDetails(DeliveryParameters deliveryParameters)
        {
            var orderApiClient = ByDesignAPIHelper.CreateOrderAPIClient();

            var orderDetailsResponse = orderApiClient.GetOrderDetailsInfo_V2(orderApiClient.CreateCredentials(), deliveryParameters.OrderId);

            if (orderDetailsResponse.Success == 0)
            {
                throw new InvalidOperationException(orderDetailsResponse.Message);
            }

            List <DeliveryItem> deliveryItems = new List <DeliveryItem>();

            foreach (var responseItem in orderDetailsResponse.OrderDetailsResponse)
            {
                DeliveryItem deliveryItem = new DeliveryItem
                {
                    ItemId   = responseItem.ProductID,
                    Name     = responseItem.Description,
                    Quantity = responseItem.Quantity,
                    Cost     = decimal.Parse(responseItem.TaxableAmount, CultureInfo.InvariantCulture),
                    PayCost  = decimal.Parse(responseItem.TaxableAmount, CultureInfo.InvariantCulture)
                };

                FillItemCosts(deliveryItem);

                deliveryItems.Add(deliveryItem);
            }

            var responseOrderInfo = orderApiClient.GetOrderInfo_V2(orderApiClient.CreateCredentials(), deliveryParameters.OrderId);

            if (responseOrderInfo.Success == 0)
            {
                throw new InvalidOperationException(responseOrderInfo.Message);
            }

            OrderClientInfo   orderClientInfo = OrderClientInfo.ExtractFromOrder(responseOrderInfo); // extracting order client info
            var               onlineApiClient = ByDesignAPIHelper.CreateOnlineAPIClient();
            ClientContactInfo contactInfo     = new ClientContactInfo();

            if (orderClientInfo.IsRep)
            {
                var responseRepInfo = onlineApiClient.GetRepInfo_V3(onlineApiClient.CreateCredentials(), orderClientInfo.ClientNumber);
                if (responseRepInfo.Success == 0)
                {
                    throw new InvalidOperationException(responseOrderInfo.Message);
                }

                contactInfo.FirstName = responseRepInfo.Firstname;
                contactInfo.LastName  = responseRepInfo.Lastname;
                contactInfo.Email     = responseRepInfo.Email;
                contactInfo.Phone     = responseRepInfo.Phone1;
            }
            else
            {
                var responseCustInfo = onlineApiClient.GetCustomerInfo_v3(onlineApiClient.CreateCredentials(), orderClientInfo.ClientNumber);
                if (responseCustInfo.Success == 0)
                {
                    throw new InvalidOperationException(responseOrderInfo.Message);
                }

                contactInfo.FirstName = responseCustInfo.FirstName;
                contactInfo.LastName  = responseCustInfo.LastName;
                contactInfo.Email     = responseCustInfo.Email;
                contactInfo.Phone     = responseCustInfo.Phone1;
            }

            Address deliveryAddress = new Address
            {
                PostIndex = responseOrderInfo.ShipPostalCode,
                Country   = responseOrderInfo.ShipCountry,
                State     = responseOrderInfo.ShipState,
                Place     = responseOrderInfo.ShipCity,
                Street_1  = responseOrderInfo.ShipStreet1,
                Street_2  = responseOrderInfo.ShipStreet2
            };

            DeliveryRecipient recipient = new DeliveryRecipient
            {
                FullName = responseOrderInfo.ShipName1,
                Phone    = responseOrderInfo.ShipPhone,
                Email    = responseOrderInfo.ShipEmail
            };

            deliveryParameters.Items           = deliveryItems.ToArray();
            deliveryParameters.DeliveryAddress = deliveryAddress;
            deliveryParameters.Recipient       = recipient;
            deliveryParameters.ContactInfo     = contactInfo;

            var responseTotals = orderApiClient.GetTotals(orderApiClient.CreateCredentials(), deliveryParameters.OrderId);

            if (responseTotals.Success == 0)
            {
                throw new InvalidOperationException(responseTotals.Message);
            }

            deliveryParameters.ShippingTotal = decimal.Parse(responseTotals.ShippingTotal, CultureInfo.InvariantCulture);
        }
Exemple #8
0
        public ActionResult Payment(OrderDetails orderDetails)
        {
            try
            {
                if (string.IsNullOrEmpty(orderDetails.OrderId))
                {
                    throw new InvalidOperationException("Номер заказа не указан");
                }

                int orderId = 0;
                if (!int.TryParse(orderDetails.OrderId, out orderId))
                {
                    throw new InvalidCastException("Некорректный формат номера заказа");
                }

                var orderApiClient = ByDesignAPIHelper.CreateOrderAPIClient();
                var orderApiCred   = orderApiClient.CreateCredentials();

                if (Properties.Settings.Default.Freedom_StartKitCheckEnabled)
                {
                    var responseOrderInfo = orderApiClient.GetOrderInfo_V2(orderApiCred, orderId);
                    if (responseOrderInfo.Success == 0)
                    {
                        throw new InvalidOperationException(responseOrderInfo.Message);
                    }

                    OrderClientInfo orderClientInfo = OrderClientInfo.ExtractFromOrder(responseOrderInfo);

                    if (!string.IsNullOrEmpty(orderClientInfo.ClientNumber))
                    {
                        IStartKitOrderChecker startKitChecker = null;
                        if (orderClientInfo.IsRep)
                        {
                            startKitChecker = new RepStartKitOrderChecker();
                        }
                        else
                        {
                            startKitChecker = new CustomerStartKitOrderChecker();
                        }

                        startKitChecker.CheckFor(orderClientInfo.ClientNumber, orderId);
                    }
                    else
                    {
                        throw new InvalidOperationException("Некоррекный формат кода кастомера");
                    }
                }

                var responseTotals = orderApiClient.GetTotals(orderApiCred, orderId);
                if (responseTotals.Success == 0)
                {
                    throw new InvalidOperationException(responseTotals.Message);
                }

                var balanceDue = decimal.Parse(responseTotals.BalanceDue, CultureInfo.InvariantCulture);
                balanceDue          = Math.Floor(balanceDue * 100) / 100;
                orderDetails.Amount = balanceDue;
            }
            catch (Exception ex)
            {
                return(View("OrderError", ex));
            }

            return(View(orderDetails));
        }