Пример #1
0
        public static Shipping Create(ShippingRequest sr)
        {
            if (sr == null)
            {
                return(null);
            }

            // todo :: automapper
            return(new Shipping
            {
                Number = NewNumber(),
                AccountId = sr.AccountId,
                Name = sr.Name,
                Currency = sr.Currency,
                OrderId = sr.OrderId,
                Amount = sr.Amount,
                Street = sr.Street,
                PostalCode = sr.PostalCode,
                City = sr.City,
                Region = sr.Region,
                Country = sr.Country,
                Status = sr.Status.Parse <ShippingStatus>(),
                Provider = sr.Provider.Parse <ShippingProvider>()
            });
        }
Пример #2
0
        internal async Task <CalculateShippingRatesResponse> CalculateShippingRates(ShippingRequest request)
        {
            var apiResponse =
                await _client.PostAsync <CalculateShippingRatesResponse, ShippingRequest>("shipping/rates", request);

            return(apiResponse);
        }
Пример #3
0
        public static IOrderAddress ShippingRequestToOrderAddress(ShippingRequest shippingRequest, ICart cart)
        {
            var addressId    = $"{shippingRequest.AddressLine1}{shippingRequest.AddressLine2}{shippingRequest.City}";
            var orderAddress = cart.CreateOrderAddress(_orderGroupFactory.Service, addressId);

            orderAddress.City        = shippingRequest.City;
            orderAddress.CountryCode = "NOR";
            orderAddress.CountryName = shippingRequest.Country;
            orderAddress.Line1       = shippingRequest.AddressLine1;
            orderAddress.Line2       = shippingRequest.AddressLine2;
            orderAddress.PostalCode  = shippingRequest.PostalCode;

            return(orderAddress);
        }
Пример #4
0
        public async Task <ShippingRatesResult> ListAsync(Proxy proxy, string api, ShippingRequest shippingrequest)
        {
            return(await Task.Factory.StartNew(() =>
            {
                HttpWebRequest webRequest =
                    WebRequest.Create("https://api.printful.com/shipping/rates") as HttpWebRequest;

                if (proxy != null)
                {
                    webRequest.Proxy = proxy.Get();
                    webRequest.Credentials = proxy.GetCredential();
                }
                webRequest.Method = "POST";
                webRequest.ContentType = "application/json; charset=utf-8";
                webRequest.Headers.Add("Authorization", "Basic " + Manager.API.Encode(api));

                string data = JsonConvert.SerializeObject(shippingrequest); //replace <value>
                byte[] data_form = Encoding.UTF8.GetBytes(data);

                webRequest.ContentLength = data_form.Length;
                Stream newStream = webRequest.GetRequestStream();
                // Send the data.
                newStream.Write(data_form, 0, data_form.Length);
                newStream.Close();

                WebResponse response = webRequest.GetResponse();
                if (((HttpWebResponse)response).StatusCode == HttpStatusCode.OK)
                {
                    // Get the stream containing content returned by the server.
                    Stream dataStream = response.GetResponseStream();
                    if (dataStream != null)
                    {
                        // Open the stream using a StreamReader for easy access.
                        StreamReader reader = new StreamReader(dataStream);
                        // Read the content.
                        string responseFromServer = reader.ReadToEnd();
                        // Display the content.
                        ShippingRatesResult result =
                            JsonConvert.DeserializeObject <ShippingRatesResult>(responseFromServer, Converter.Settings);

                        return result;
                    }
                }
                return null;
            }));
        }
Пример #5
0
        public List <ProductModel> CreateShipments(List <ProductModel> products, Models.AddressModel addr)
        {
            products.ForEach(x =>
            {
                var fedExReq = new ShippingRequest
                {
                    DeclaredValue    = x.Total,
                    FromZIP          = 12345,
                    ToZIP            = addr.ZIP,
                    Weight           = x.Weight,
                    CentimetersCubed = x.Height * x.Length * x.Width
                };
                //x.ShippingGuid = _upsService.CreateNewShipment(fedExReq, _upsLicense).TrackingNumber;
            });

            return(products);
        }
 public void Dispose()
 {
     if (GetPayBalanceRequest != null)
     {
         GetPayBalanceRequest.GetInvocationList().ToList().ForEach(x => GetPayBalanceRequest -= (RequestEventHandler <int>)x);
     }
     if (PaymentBackRequest != null)
     {
         PaymentBackRequest.GetInvocationList().ToList().ForEach(x => PaymentBackRequest -= (RequestEventHandler <bool>)x);
     }
     if (GetCoinsRequest != null)
     {
         GetCoinsRequest.GetInvocationList().ToList().ForEach(x => GetCoinsRequest -= (RequestEventHandler <int, CoinType>)x);
     }
     if (PaymentRequest != null)
     {
         PaymentRequest.GetInvocationList().ToList().ForEach(x => PaymentRequest -= (RequestEventHandler <bool, Dictionary <CoinType, int> >)x);
     }
     if (GetDrinksQtyRequest != null)
     {
         GetDrinksQtyRequest.GetInvocationList().ToList().ForEach(x => GetDrinksQtyRequest -= (RequestEventHandler <int, Guid>)x);
     }
     if (ShippingRequest != null)
     {
         ShippingRequest.GetInvocationList().ToList().ForEach(x => ShippingRequest -= (RequestEventHandler <bool, int>)x);
     }
     if (GetDrinksPriceRequest != null)
     {
         GetDrinksPriceRequest.GetInvocationList().ToList().ForEach(x => GetDrinksPriceRequest -= (RequestEventHandler <int, Guid>)x);
     }
     if (PurchaseRequest != null)
     {
         PurchaseRequest.GetInvocationList().ToList().ForEach(x => PurchaseRequest -= (VoidEventHandler <Guid>)x);
     }
     if (ThanksMessageRequest != null)
     {
         ThanksMessageRequest.GetInvocationList().ToList().ForEach(x => ThanksMessageRequest -= (VoidEventHandler)x);
     }
     if (InsufficientMessageRequest != null)
     {
         InsufficientMessageRequest.GetInvocationList().ToList().ForEach(x => InsufficientMessageRequest -= (VoidEventHandler)x);
     }
 }
        public IHttpActionResult InsertRegionTerritory(ShippingRequest obj)
        {
            ShippingResponse response = new ShippingResponse();

            if (obj == null)
            {
                return(BadRequest());
            }

            using (NORTHWNDEntitiesNew dbContext = new NORTHWNDEntitiesNew())
            {
                dbContext.Shippers.Add(new Shipper {
                    CompanyName = obj.CompanyName, Phone = obj.Phone
                });
                dbContext.SaveChanges();

                response.success = "Yes"; response.failure = "No";
            }
            return(Ok(response));
        }
Пример #8
0
        public bool CreateOrder(int orderId, PaymentInfoModel paymentInfo)
        {
            //              vvv
            var orderRepo = new OrderRepo(_connString);
            var order     = orderRepo.GetOrderById(orderId).CTM();

            bool paymentStatus = ProcessPayment(paymentInfo, order.Total);

            if (!paymentStatus)
            {
                return(false);
            }

            order.Status = orderRepo.UpdateOrderStatus(OrderStatus.Paid).CTM();

            //                 vvv
            var customerRepo = new CustomerRepo(_connString);
            var customerInfo = customerRepo.GetCustomerById(order.CustomerID);
            var custAddr     = customerInfo.Address;

            order.Products.ForEach(x =>
            {
                var upsRequest = new ShippingRequest
                {
                    DeclaredValue    = x.Total,
                    FromZIP          = 12345,
                    ToZIP            = custAddr.ZIP,
                    Weight           = x.Weight,
                    CentimetersCubed = x.Height * x.Length * x.Width,
                };
                //x.ShippingGuid = new UPSService().CreateNewShipment(upsRequest, _upsLicense).TrackingNumber;
            });

            order.Status = orderRepo.UpdateOrderStatus(OrderStatus.Shipped).CTM();

            return(true);
        }
Пример #9
0
        public virtual ShippingDetailsResponse GetShippingDetails(string orderId, string contactId, string marketId, string cartName, ShippingRequest shippingRequest)
        {
            var cart = _vippsService.GetCartByContactId(contactId, marketId, cartName);

            var shippingMethods = ShippingManager.GetShippingMethodsByMarket(cart.MarketId.Value, false).ShippingMethod.ToList().OrderBy(x => x.Ordering);

            var shippingDetails = new List <ShippingDetails>();

            var counter = 1;

            foreach (var shippingMethod in shippingMethods)
            {
                lock (cart)
                {
                    var shipment = cart.GetFirstShipment();
                    shipment.ShippingAddress  = AddressHelper.ShippingRequestToOrderAddress(shippingRequest, cart);
                    shipment.ShippingMethodId = shippingMethod.ShippingMethodId;
                    cart.ApplyDiscounts();

                    shippingDetails.Add(new ShippingDetails
                    {
                        ShippingMethodId = shippingMethod.ShippingMethodId.ToString(),
                        ShippingCost     = Convert.ToDouble(cart.GetShippingTotal().Amount),
                        ShippingMethod   = shippingMethod.DisplayName,
                        Priority         = shippingMethod.IsDefault ? 0 : counter++
                    });
                }
            }

            return(new ShippingDetailsResponse
            {
                OrderId = orderId,
                ShippingDetails = shippingDetails
            });
        }
        public IHttpActionResult ShippingDetails(string contactId, string marketId, string cartName, string orderId, [FromBody] ShippingRequest shippingRequest)
        {
            try
            {
                var response = _responseFactory.GetShippingDetails(orderId, contactId, marketId, cartName, shippingRequest);
                return(Ok(response));
            }

            catch (Exception ex)
            {
                _logger.Error($"{ex.Message} {ex.StackTrace}");
                return(InternalServerError(ex));
            }
        }
Пример #11
0
        public IEnumerable <ShippingProviderMethod> GetAllShippingMethods(int id)
        {
            var methods  = new List <ShippingProviderMethod>();
            var provider = ShippingProviderHelper.GetShippingProvider(id);

            var helper  = new ShippingConfigHelper(provider);
            var request = new ShippingRequest();

            var orderInfo = OrderHelper.GetOrderInfo();

            var postalCodeFrom = helper.Settings["zipPostalCodeFrom"];

            var customerPostalCode = OrderHelper.CustomerInformationValue(orderInfo, "customerPostalCode");

            if (string.IsNullOrEmpty(customerPostalCode))
            {
                Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: customerPostalCode IsNullOrEmpty: CUSTOMER SHOULD ENTER A POSTALCODE FIRST!");

                return(methods);
            }

            var orderWeight = orderInfo.OrderLines.Sum(x => x.OrderLineWeight) / 1000;

            if (orderWeight < 0.1)
            {
                orderWeight = 0.1;
            }
            if (orderWeight > 20)
            {
                Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Weight > 20: Weight should be in grams");

                return(methods);
            }

            var orderWeightCulture = decimal.Parse(orderWeight.ToString(), NumberStyles.Currency, CultureInfo.GetCultureInfo("en-AU"));

            var orderWidth = orderInfo.OrderLines.Sum(x => x.ProductInfo.Weight);

            if (orderWidth < 5)
            {
                orderWidth = 5;
            }
            if (orderWidth > 105)
            {
                Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Wide > 105: width should be in cm");

                return(methods);
            }

            var orderWidthCulture = decimal.Parse(orderWidth.ToString(), NumberStyles.Currency, CultureInfo.GetCultureInfo("en-AU"));

            var orderHeight = orderInfo.OrderLines.Sum(x => x.ProductInfo.Height);

            if (orderHeight < 5)
            {
                orderHeight = 5;
            }
            if (orderHeight > 105)
            {
                Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Hight > 105: height should be in cm");

                return(methods);
            }

            var orderHeightCulture = decimal.Parse(orderHeight.ToString(), NumberStyles.Currency, CultureInfo.GetCultureInfo("en-AU"));

            var orderLength = orderInfo.OrderLines.Sum(x => x.ProductInfo.Length);

            if (orderLength < 5)
            {
                orderLength = 5;
            }
            if (orderLength > 105)
            {
                Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Length > 105: length should be in cm");

                return(methods);
            }

            var widthOrLength = orderWidth;

            if (orderLength > orderWidth)
            {
                widthOrLength = orderLength;
            }

            var girth = 2 * (Math.Round(widthOrLength, MidpointRounding.AwayFromZero) + Math.Round(orderHeight, MidpointRounding.AwayFromZero));

            if (girth < 16)
            {
                Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Girth < 16 (sizes should be in cm)");

                return(methods);
            }

            if (girth > 140)
            {
                Log.Instance.LogDebug("AUSPOST GetAllShippingMethods: Girth > 140 (sizes should be in cm)");

                return(methods);
            }

            var orderLengthCulture = decimal.Parse(orderLength.ToString(), NumberStyles.Currency, CultureInfo.GetCultureInfo("en-AU"));


            if (orderInfo.CustomerInfo.CountryCode.ToUpper() == "AU")
            {
                request.ShippingUrlBase = helper.Settings["ServiceUrlDomestic"];
                request.Parameters.Add("from_postcode", postalCodeFrom);
                request.Parameters.Add("to_postcode", customerPostalCode);
                request.Parameters.Add("length", Math.Round(orderLengthCulture, 2).ToString());
                request.Parameters.Add("width", Math.Round(orderWidthCulture, 2).ToString());
                request.Parameters.Add("height", Math.Round(orderHeightCulture, 2).ToString());
            }
            else
            {
                request.ShippingUrlBase = helper.Settings["ServiceUrlInternational"];
                request.Parameters.Add("country_code", orderInfo.CustomerInfo.CountryCode);
            }

            request.Parameters.Add("weight", Math.Round(orderWeightCulture, 2).ToString());

            var requestHeader = new WebHeaderCollection {
                { "AUTH-KEY", helper.Settings["authKey"] }
            };

            Log.Instance.LogDebug("AUSPOST API URL: " + request.ShippingUrlBase);
            Log.Instance.LogDebug("AUSPOST API ParametersAsString: " + request.ParametersAsString);
            Log.Instance.LogDebug("AUSPOST API requestHeader AUTH-KEY: " + requestHeader.GetValues("AUTH-KEY"));

            var issuerRequest = _requestSender.GetRequest(request.ShippingUrlBase, request.ParametersAsString, requestHeader);


            XNamespace ns        = string.Empty;
            var        issuerXml = XDocument.Parse(issuerRequest);

            foreach (var service in issuerXml.Descendants(ns + "service"))
            {
                var issuerId         = service.Descendants(ns + "code").First().Value;
                var issuerName       = service.Descendants(ns + "name").First().Value;
                var issuerPriceValue = service.Descendants(ns + "price").First().Value;

                decimal issuerPrice;

                decimal.TryParse(issuerPriceValue, out issuerPrice);

                var priceInCents = issuerPrice * 100;

                var paymentImageId = 0;

                var logoDictionaryItem = library.GetDictionaryItem(issuerId + "LogoId");

                if (string.IsNullOrEmpty(logoDictionaryItem))
                {
                    int.TryParse(library.GetDictionaryItem(issuerId + "LogoId"), out paymentImageId);
                }

                methods.Add(new ShippingProviderMethod {
                    Id = issuerId, Description = issuerName, Title = issuerName, Name = issuerName, ProviderName = GetName(), ImageId = paymentImageId, PriceInCents = (int)priceInCents, Vat = 21
                });
            }

            return(methods);
        }
Пример #12
0
 public ShippingResponse DeleteShipment(ShippingRequest shippingRequest)
 {
     throw new NotImplementedException();
 }
 protected bool Shipping(int price)
 {
     return(ShippingRequest?.Invoke(price) ?? false);
 }
Пример #14
0
 public decimal CalculateShippingFees(ShippingRequest request, string customerLicense) => 0;
Пример #15
0
 public TrackedShipment CreateNewShipment(ShippingRequest request, string customerLicense) => null;
Пример #16
0
        public async Task <CalculateShippingRatesResponse> CalculateShippingRates(ShippingRequest shippingRequest)
        {
            var calculateShippingRatesResponse = await _shippingService.CalculateShippingRates(shippingRequest);

            return(calculateShippingRatesResponse);
        }