예제 #1
0
        public static OrderClientInfo ExtractFromOrder(ByDesignOrderAPI.GetOrderResponse_V2 responseOrderInfo)
        {
            string custOrRep = string.Empty;

            bool isRep = false;

            if (!string.IsNullOrEmpty(responseOrderInfo.CustomerNumber))
            {
                custOrRep = responseOrderInfo.CustomerNumber;
            }
            else
            {
                custOrRep = responseOrderInfo.RepNumber;
                isRep     = true;
            }

            OrderClientInfo result = new OrderClientInfo
            {
                ClientNumber = custOrRep,
                IsRep        = isRep
            };

            return(result);
        }
예제 #2
0
        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);
        }
예제 #3
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));
        }