Beispiel #1
0
 private static void SetFreightDeclaredValue(RateRequest request)
 {
     request.RequestedShipment.FreightShipmentDetail.DeclaredValuePerUnit                 = new Money();
     request.RequestedShipment.FreightShipmentDetail.DeclaredValuePerUnit.Currency        = "USD";
     request.RequestedShipment.FreightShipmentDetail.DeclaredValuePerUnit.Amount          = 50.0M;
     request.RequestedShipment.FreightShipmentDetail.DeclaredValuePerUnit.AmountSpecified = true;
 }
Beispiel #2
0
        public async Task <IActionResult> Post([FromBody] RateRequest request)
        {
            try
            {
                //TODO: Do some snaity checking on the request model
                ServiceEventSource.Current.ServiceMessage(
                    this.context,
                    "Received request for hotel",
                    request.HotelName);

                IReliableQueue <RateRequest> queue = await this.stateManager.GetOrAddAsync <IReliableQueue <RateRequest> >(RatesService.RateQueueName);

                using (ITransaction tx = this.stateManager.CreateTransaction())
                {
                    // Queue the request
                    await queue.EnqueueAsync(tx, request);

                    // Commit
                    await tx.CommitAsync();
                }

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Beispiel #3
0
        private Dictionary <string, ProviderShipRateQuote> GetProviderQuotes(Warehouse origin, CommerceBuilder.Users.Address destination, PackageList packageList)
        {
            RateRequest request     = CreateRateRequest(origin, destination, packageList);
            RateService rateService = new RateService();
            RateReply   reply;

            this.RecordCommunication("FedExWS", CommunicationDirection.Send, new UTF8Encoding().GetString(XmlUtility.Serialize(request)));
            // This is the call to the web service passing in a RateRequest and returning a RateReply
            try
            {
                reply = rateService.getRates(request); // Service call
            }
            catch (System.Web.Services.Protocols.SoapException se)
            {
                Logger.Error("Soap Exception", se);
                Logger.Debug(se.Detail.InnerXml);
                return(new Dictionary <string, ProviderShipRateQuote>());
            }
            this.RecordCommunication("FedExWS", CommunicationDirection.Receive, new UTF8Encoding().GetString(XmlUtility.Serialize(reply)));

            if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful
            {
                //ShowRateReply(reply);
                return(ParseRates(reply));
            }
            else
            {
                //Console.WriteLine(reply.Notifications[0].Message);
                return(new Dictionary <string, ProviderShipRateQuote>());
            }
        }
Beispiel #4
0
 /// <summary>
 /// Sets the origin
 /// </summary>
 /// <param name="request"></param>
 protected void SetOrigin(RateRequest request)
 {
     request.RequestedShipment.Shipper = new Party
     {
         Address = Shipment.OriginAddress.GetFedExAddress()
     };
 }
Beispiel #5
0
        /// <summary>
        /// Sets package line items
        /// </summary>
        /// <param name="request"></param>
        protected void SetPackageLineItems(RateRequest request)
        {
            request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[Shipment.PackageCount];

            var i = 0;

            foreach (var package in Shipment.Packages)
            {
                request.RequestedShipment.RequestedPackageLineItems[i] = new RequestedPackageLineItem()
                {
                    SequenceNumber    = (i + 1).ToString(),
                    GroupPackageCount = "1",

                    // Package weight
                    Weight = new Weight()
                    {
                        Units          = WeightUnits.LB,
                        UnitsSpecified = true,
                        Value          = package.RoundedWeight,
                        ValueSpecified = true
                    },

                    // Package dimensions
                    Dimensions = new Dimensions()
                    {
                        Length         = package.RoundedLength.ToString(),
                        Width          = package.RoundedWidth.ToString(),
                        Height         = package.RoundedHeight.ToString(),
                        Units          = LinearUnits.IN,
                        UnitsSpecified = true
                    }
                };

                if (_allowInsuredValues)
                {
                    // package insured value
                    request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue = new Money
                    {
                        Amount          = package.InsuredValue,
                        AmountSpecified = package.InsuredValue > 0,
                        Currency        = "USD"
                    };
                }

                if (package.SignatureRequiredOnDelivery)
                {
                    var signatureOptionDetail = new SignatureOptionDetail {
                        OptionType = SignatureOptionType.DIRECT
                    };
                    var specialServicesRequested = new PackageSpecialServicesRequested()
                    {
                        SignatureOptionDetail = signatureOptionDetail
                    };

                    request.RequestedShipment.RequestedPackageLineItems[i].SpecialServicesRequested = specialServicesRequested;
                }

                i++;
            }
        }
Beispiel #6
0
 /// <summary>
 /// Sets the destination
 /// </summary>
 /// <param name="request"></param>
 protected void SetDestination(RateRequest request)
 {
     request.RequestedShipment.Recipient = new Party
     {
         Address = Shipment.DestinationAddress.GetFedExAddress()
     };
 }
Beispiel #7
0
        /// <summary>
        /// 获取渠道报价列表
        /// </summary>
        /// <param name="rateRequest"></param>
        /// <returns></returns>
        public static RateResponse GetRate(RateRequest rateRequest)
        {
            var request = new Request("api/rate");
            var result  = request.Execute(rateRequest);

            return(XmlUtilHelper.DeSerializedEntity <RateResponse>(result));
        }
Beispiel #8
0
        public static RateRequest FedExCreateRateRequest(Person shipto, ProductCollection cart)
        {
            // Build a RateRequest
            RateRequest request = new RateRequest();

            //
            request.WebAuthenticationDetail = new WebAuthenticationDetail();
            request.WebAuthenticationDetail.UserCredential          = new WebAuthenticationCredential();
            request.WebAuthenticationDetail.UserCredential.Key      = ConfigurationManager.AppSettings["FedexKey"];
            request.WebAuthenticationDetail.UserCredential.Password = ConfigurationManager.AppSettings["FedexPassword"];
            //
            request.ClientDetail = new ClientDetail();
            request.ClientDetail.AccountNumber = ConfigurationManager.AppSettings["FedexLMAccountNumber"];
            request.ClientDetail.MeterNumber   = ConfigurationManager.AppSettings["FedexLMMeterNumber"];
            //
            request.TransactionDetail = new TransactionDetail();
            request.TransactionDetail.CustomerTransactionId = "***Rate v10 Request using VC#***"; // This is a reference field for the customer.  Any value can be used and will be provided in the response.
            //
            request.Version = new VersionId();                                                    // WSDL version information, value is automatically set from wsdl
            //
            request.ReturnTransitAndCommit          = true;
            request.ReturnTransitAndCommitSpecified = true;
            //
            FedExSetShipmentDetails(request, shipto, cart);
            //
            return(request);
        }
Beispiel #9
0
 private static void SetFreightShipmentLineItems(RateRequest request)
 {
     request.RequestedShipment.FreightShipmentDetail.LineItems    = new FreightShipmentLineItem[1];
     request.RequestedShipment.FreightShipmentDetail.LineItems[0] = new FreightShipmentLineItem();
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].FreightClass          = FreightClassType.CLASS_050;
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].FreightClassSpecified = true;
     //
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Packaging          = PhysicalPackagingType.BOX;
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].PackagingSpecified = true;
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Description        = "Freight line item description";
     //
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Weight                = new Weight();
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Weight.Units          = WeightUnits.LB;
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Weight.UnitsSpecified = true;
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Weight.Value          = 1000.0M;
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Weight.ValueSpecified = true;
     //
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Dimensions                = new Dimensions();
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Dimensions.Length         = "90";
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Dimensions.Width          = "60";
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Dimensions.Height         = "50";
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Dimensions.Units          = LinearUnits.IN;
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Dimensions.UnitsSpecified = true;
     //
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Volume                = new Volume();
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Volume.Units          = VolumeUnits.CUBIC_FT;
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Volume.UnitsSpecified = true;
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Volume.Value          = 30M;
     request.RequestedShipment.FreightShipmentDetail.LineItems[0].Volume.ValueSpecified = true;
 }
Beispiel #10
0
        static void Main()
        {
            RateRequest request = CreateRateRequest();

            var service = new RateService();

            string productId = ConfigurationManager.AppSettings["productID"];

            if (productId == "Production")
            {
                service.Url = "https://ws.fedex.com:443/web-services/rate";
            }



            try
            {
                var reply = service.getRates(request);
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    ShowRateReply(reply);
                }
                ShowNotifications(reply);
            }
            catch (SoapException e)
            {
                Console.WriteLine(e.Detail.InnerText);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("Press any key to quit!");
            Console.ReadKey();
        }
        public override void GetRates()
        {
            RateRequest request = CreateRateRequest();
            var         service = new RateService();

            try
            {
                // Call the web service passing in a RateRequest and returning a RateReply
                RateReply reply = service.getRates(request);
                //
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    ProcessReply(reply);
                }
                ShowNotifications(reply);
            }
            catch (SoapException e)
            {
                Debug.WriteLine(e.Detail.InnerText);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Beispiel #12
0
 private static void SetCOD(RateRequest request)
 {
     // To get all COD rates, set both COD details at both package and shipment level
     // Set COD at Package level for Ground Services
     request.RequestedShipment.RequestedPackageLineItems[0].SpecialServicesRequested = new PackageSpecialServicesRequested();
     request.RequestedShipment.RequestedPackageLineItems[0].SpecialServicesRequested.SpecialServiceTypes    = new PackageSpecialServiceType[1];
     request.RequestedShipment.RequestedPackageLineItems[0].SpecialServicesRequested.SpecialServiceTypes[0] = PackageSpecialServiceType.COD;
     //
     request.RequestedShipment.RequestedPackageLineItems[0].SpecialServicesRequested.CodDetail = new CodDetail();
     request.RequestedShipment.RequestedPackageLineItems[0].SpecialServicesRequested.CodDetail.CollectionType                      = CodCollectionType.GUARANTEED_FUNDS;
     request.RequestedShipment.RequestedPackageLineItems[0].SpecialServicesRequested.CodDetail.CodCollectionAmount                 = new Money();
     request.RequestedShipment.RequestedPackageLineItems[0].SpecialServicesRequested.CodDetail.CodCollectionAmount.Amount          = 250;
     request.RequestedShipment.RequestedPackageLineItems[0].SpecialServicesRequested.CodDetail.CodCollectionAmount.AmountSpecified = true;
     request.RequestedShipment.RequestedPackageLineItems[0].SpecialServicesRequested.CodDetail.CodCollectionAmount.Currency        = "USD";
     // Set COD at Shipment level for Express Services
     request.RequestedShipment.SpecialServicesRequested = new ShipmentSpecialServicesRequested(); // Special service requested
     request.RequestedShipment.SpecialServicesRequested.SpecialServiceTypes    = new ShipmentSpecialServiceType[1];
     request.RequestedShipment.SpecialServicesRequested.SpecialServiceTypes[0] = ShipmentSpecialServiceType.COD;
     //
     request.RequestedShipment.SpecialServicesRequested.CodDetail = new CodDetail();
     request.RequestedShipment.SpecialServicesRequested.CodDetail.CodCollectionAmount                 = new Money();
     request.RequestedShipment.SpecialServicesRequested.CodDetail.CodCollectionAmount.Amount          = 150;
     request.RequestedShipment.SpecialServicesRequested.CodDetail.CodCollectionAmount.AmountSpecified = true;
     request.RequestedShipment.SpecialServicesRequested.CodDetail.CodCollectionAmount.Currency        = "USD";
     request.RequestedShipment.SpecialServicesRequested.CodDetail.CollectionType = CodCollectionType.GUARANTEED_FUNDS;// ANY, CASH, GUARANTEED_FUNDS
 }
Beispiel #13
0
        private static RateRequest CreateRateRequest()
        {
            // Build a RateRequest
            var request = new RateRequest
            {
                WebAuthenticationDetail = new WebAuthenticationDetail
                {
                    UserCredential = new WebAuthenticationCredential
                    {
                        Key      = ConfigurationManager.AppSettings["key"],
                        Password = ConfigurationManager.AppSettings["password"]
                    }
                },
                ClientDetail =
                    new ClientDetail
                {
                    AccountNumber = ConfigurationManager.AppSettings["accountnumber"],
                    MeterNumber   = ConfigurationManager.AppSettings["meternumber"]
                },
                TransactionDetail = new TransactionDetail {
                    CustomerTransactionId = "***Rate Request using VC#***"
                },
                Version = new VersionId(),
                ReturnTransitAndCommit          = true,
                ReturnTransitAndCommitSpecified = true
            };


            SetShipmentDetails(request);


            return(request);
        }
Beispiel #14
0
 private static void SetShipmentDetails(RateRequest request)
 {
     request.RequestedShipment = new RequestedShipment
     {
         ShipTimestamp          = DateTime.Now,
         ShipTimestampSpecified = true,
         DropoffType            = DropoffType.REGULAR_PICKUP,
         ServiceType            = ServiceType.INTERNATIONAL_PRIORITY,
         ServiceTypeSpecified   = true,
         PackagingType          = PackagingType.YOUR_PACKAGING,
         PackagingTypeSpecified = true, RateRequestTypes = new RateRequestType[]
         {
             RateRequestType.LIST, RateRequestType.PREFERRED
         },
         PreferredCurrency = "USD"
     };
     SetOrigin(request);
     SetDestination(request);
     SetPackageLineItems(request);
     SetCustomDetails(request);
     request.RequestedShipment.TotalInsuredValue =
         new Money {
         Amount = 100, Currency = "USD"
     };
     request.RequestedShipment.PackageCount = "1";
 }
Beispiel #15
0
 /// <summary>
 /// Sets shipment details
 /// </summary>
 /// <param name="request"></param>
 protected sealed override void SetShipmentDetails(RateRequest request)
 {
     SetOrigin(request);
     SetDestination(request);
     SetPackageLineItems(request);
     SetSmartPostDetails(request);
 }
Beispiel #16
0
        private static void SetPackageLineItems(RateRequest request)
        {
            // request.RequestedShipment.PackageCount = "1";
            var lineItem = new RequestedPackageLineItem
            {
                // SequenceNumber = "1",
                GroupPackageCount = "1",
                Weight            = new Weight
                {
                    Units          = WeightUnits.LB,
                    UnitsSpecified = true,
                    Value          = 2.0M,
                    ValueSpecified = true
                },
                Dimensions = new Dimensions
                {
                    Length         = "10",
                    Width          = "13",
                    Height         = "4",
                    Units          = LinearUnits.IN,
                    UnitsSpecified = true
                },
                // InsuredValue = new Money {Amount = 0, Currency = "USD"}
            };


            request.RequestedShipment.RequestedPackageLineItems = new[]
            {
                lineItem
            };
        }
Beispiel #17
0
        public List <ShippingOption> GetShippingOptions()
        {
            var shippingOptions = new List <ShippingOption>();

            try
            {
                var          service      = new RateService();
                RateRequest  request      = CreateRateRequest(service);
                RateResponse rateResponse = service.ProcessRate(request);
                shippingOptions = ParseAnswer(rateResponse);
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                Debug.LogError(ex, false);
            }
            catch (System.ServiceModel.CommunicationException ex)
            {
                Debug.LogError(ex, false);
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
            }
            return(shippingOptions);
        }
Beispiel #18
0
 private void CheckRateValid(RateRequest rateRequest)
 {
     if (rateRequest.MinAge < 0 || rateRequest.MinAge > 99)
     {
         throw new Exception("Rate must be between 0 and 99");
     }
 }
Beispiel #19
0
        private static void SetShipmentDetails(RateRequest request)
        {
            request.RequestedShipment = new RequestedShipment();
            request.RequestedShipment.ShipTimestamp          = DateTime.Now;               // Shipping date and time
            request.RequestedShipment.ShipTimestampSpecified = true;
            request.RequestedShipment.DropoffType            = DropoffType.REGULAR_PICKUP; //Drop off types are BUSINESS_SERVICE_CENTER, DROP_BOX, REGULAR_PICKUP, REQUEST_COURIER, STATION
            request.RequestedShipment.DropoffTypeSpecified   = true;
            request.RequestedShipment.PackagingType          = PackagingType.YOUR_PACKAGING;
            request.RequestedShipment.PackagingTypeSpecified = true;
            //
            SetOrigin(request);
            //
            SetDestination(request);
            //
            SetPackageLineItems(request);
            //
            request.RequestedShipment.PackageCount = "1";
            //set to true to request COD shipment
            bool isCodShipment = true;

            if (isCodShipment)
            {
                SetCOD(request);
            }
        }
Beispiel #20
0
        /// <summary>
        /// Sets shipment details
        /// </summary>
        /// <param name="request"></param>
        protected sealed override void SetShipmentDetails(RateRequest request)
        {
            request.RequestedShipment = new RequestedShipment();
            request.RequestedShipment.ShipTimestamp          = DateTime.Now;               // Shipping date and time
            request.RequestedShipment.ShipTimestampSpecified = true;
            request.RequestedShipment.DropoffType            = DropoffType.REGULAR_PICKUP; //Drop off types are BUSINESS_SERVICE_CENTER, DROP_BOX, REGULAR_PICKUP, REQUEST_COURIER, STATION
            request.RequestedShipment.DropoffTypeSpecified   = true;
            request.RequestedShipment.PackagingTypeSpecified = false;

            SetOrigin(request);

            SetDestination(request);

            SetPackageLineItems(request);

            request.RequestedShipment.RateRequestTypes = new RateRequestType[1];
            if (_useAccountRates)
            {
                request.RequestedShipment.RateRequestTypes[0] = RateRequestType.ACCOUNT;
            }
            else
            {
                request.RequestedShipment.RateRequestTypes[0] = RateRequestType.LIST;
            }

            request.RequestedShipment.PackageCount = Shipment.PackageCount.ToString();
        }
        public ActionResult <Paging <FullInfoDTO> > UpdateRanking([FromBody] RateRequest request, Guid reservationId, int currentPage = 1, int totalRecordsByPage = 10, OrderByCriteria orderByCriteria = 0)
        {
            try
            {
                _reservationStorage.UpdatekReservationRate(request.Rate, reservationId);
                var response     = _fullInfoStorageServices.GetFullInfo(currentPage, totalRecordsByPage, orderByCriteria);
                var totalRecords = _fullInfoStorageServices.Count();

                var totalPages = (int)Math.Ceiling((double)totalRecords / totalRecordsByPage);

                var paginated = new Paging <FullInfoDTO>()
                {
                    RecordsPerPage = totalRecordsByPage,
                    TotalRecords   = totalRecords,
                    TotalPages     = totalPages,
                    CurrentPage    = currentPage,
                    Outcome        = response
                };
                return(Ok(paginated));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Beispiel #22
0
        private static void SetShipmentDetails(RateRequest request, IShipment shipment, decimal totalWeight, int quantity)
        {
            request.RequestedShipment = new RequestedShipment
            {
                ShipTimestamp          = DateTime.Now,
                ShipTimestampSpecified = true,
                DropoffType            = DropoffType.REGULAR_PICKUP,
                DropoffTypeSpecified   = true,
                PackagingType          = PackagingType.YOUR_PACKAGING,
                PackagingTypeSpecified = true
            };

            SetOrigin(request, shipment);

            SetDestination(request, shipment);

            SetPackageLineItems(request, shipment, totalWeight, quantity);

            request.RequestedShipment.RateRequestTypes    = new RateRequestType[2];
            request.RequestedShipment.RateRequestTypes[0] = RateRequestType.ACCOUNT;
            request.RequestedShipment.RateRequestTypes[1] = RateRequestType.LIST;

            request.RequestedShipment.PackageCount = quantity.ToString();
            //set to true to request COD shipment
            var isCodShipment = false;

            if (isCodShipment)
            {
                SetCOD(request);
            }
        }
Beispiel #23
0
        private static void SetPackageLineItems(RateRequest request, IShipment shipment, decimal totalWeight, int quantity)
        {
            var count = 1;

            for (var i = 0; i < quantity; i++)
            {
                request.RequestedShipment.RequestedPackageLineItems    = new RequestedPackageLineItem[1];
                request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem
                {
                    SequenceNumber    = count.ToString(),
                    GroupPackageCount = "1",
                    Weight            =
                        new Weight
                    {
                        Units          = WeightUnits.LB,
                        UnitsSpecified = true,
                        Value          = totalWeight,
                        ValueSpecified = true
                    },
                    Dimensions = new Dimensions
                    {
                        Units          = LinearUnits.IN,
                        UnitsSpecified = true
                    }
                };
                count++;
            }
        }
Beispiel #24
0
        private void SetDestination(RateRequest request, GetShippingOptionRequest getShippingOptionRequest)
        {
            request.RequestedShipment.Recipient         = new Party();
            request.RequestedShipment.Recipient.Address = new RateServiceWebReference.Address();
            if (_fedexSettings.UseResidentialRates)
            {
                request.RequestedShipment.Recipient.Address.Residential          = true;
                request.RequestedShipment.Recipient.Address.ResidentialSpecified = true;
            }
            request.RequestedShipment.Recipient.Address.StreetLines = new string[1] {
                "Recipient Address Line 1"
            };
            request.RequestedShipment.Recipient.Address.City = getShippingOptionRequest.ShippingAddress.City;
            if (getShippingOptionRequest.ShippingAddress.StateProvince != null &&
                IncludeStateProvinceCode(getShippingOptionRequest.ShippingAddress.Country.TwoLetterIsoCode))
            {
                request.RequestedShipment.Recipient.Address.StateOrProvinceCode = getShippingOptionRequest.ShippingAddress.StateProvince.Abbreviation;
            }
            else
            {
                request.RequestedShipment.Recipient.Address.StateOrProvinceCode = string.Empty;
            }
            request.RequestedShipment.Recipient.Address.PostalCode  = getShippingOptionRequest.ShippingAddress.ZipPostalCode;
            request.RequestedShipment.Recipient.Address.CountryCode = getShippingOptionRequest.ShippingAddress.Country.TwoLetterIsoCode;

            Debug.WriteLine(String.Format("Destination: {0}, {1}  {2}",
                                          request.RequestedShipment.Recipient.Address.StateOrProvinceCode,
                                          request.RequestedShipment.Recipient.Address.PostalCode,
                                          request.RequestedShipment.Recipient.Address.CountryCode));
        }
Beispiel #25
0
        private void SetIndividualPackageLineItemsOneItemPerPackage(RateRequest request, GetShippingOptionRequest getShippingOptionRequest, decimal orderSubTotal, string currencyCode)
        {
            // Rate request setup - each Shopping Cart Item is a separate package

            var usedMeasureWeight    = GetUsedMeasureWeight();
            var usedMeasureDimension = GetUsedMeasureDimension();

            var items      = getShippingOptionRequest.Items;
            var totalItems = items.GetTotalProducts();

            request.RequestedShipment.PackageCount = totalItems.ToString();
            request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[totalItems];

            int i = 0;

            foreach (var sci in items)
            {
                int length = ConvertFromPrimaryMeasureDimension(sci.Item.Product.Length, usedMeasureDimension);
                int height = ConvertFromPrimaryMeasureDimension(sci.Item.Product.Height, usedMeasureDimension);
                int width  = ConvertFromPrimaryMeasureDimension(sci.Item.Product.Width, usedMeasureDimension);
                int weight = ConvertFromPrimaryMeasureWeight(sci.Item.Product.Weight, usedMeasureWeight);
                if (length < 1)
                {
                    length = 1;
                }
                if (height < 1)
                {
                    height = 1;
                }
                if (width < 1)
                {
                    width = 1;
                }
                if (weight < 1)
                {
                    weight = 1;
                }

                for (int j = 0; j < sci.Item.Quantity; j++)
                {
                    request.RequestedShipment.RequestedPackageLineItems[i] = new RequestedPackageLineItem();
                    request.RequestedShipment.RequestedPackageLineItems[i].SequenceNumber = (i + 1).ToString();                   // package sequence number
                    request.RequestedShipment.RequestedPackageLineItems[i].Weight         = new RateServiceWebReference.Weight(); // package weight
                    request.RequestedShipment.RequestedPackageLineItems[i].Weight.Units   = RateServiceWebReference.WeightUnits.LB;
                    request.RequestedShipment.RequestedPackageLineItems[i].Weight.Value   = (decimal)weight;

                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions        = new RateServiceWebReference.Dimensions(); // package dimensions
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Length = length.ToString();
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Height = height.ToString();
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Width  = width.ToString();
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Units  = RateServiceWebReference.LinearUnits.IN;

                    request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue          = new Money(); // insured value
                    request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue.Amount   = sci.Item.Product.Price;
                    request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue.Currency = currencyCode;

                    i++;
                }
            }
        }
Beispiel #26
0
        private static RateRequest CreateRateRequest(Delivery delivery, ServiceType stType)
        {
            // Build a RateRequest
            RateRequest request = new RateRequest();

            //
            request.WebAuthenticationDetail = new WebAuthenticationDetail();
            request.WebAuthenticationDetail.UserCredential          = new WebAuthenticationCredential();
            request.WebAuthenticationDetail.UserCredential.Key      = strFedExUserCredentialKey;
            request.WebAuthenticationDetail.UserCredential.Password = strFedExUserCredentialPassword;
            //
            request.ClientDetail = new ClientDetail();
            request.ClientDetail.AccountNumber = strFedExAccountNumber;
            request.ClientDetail.MeterNumber   = strFedExMeterNumber;
            //
            request.TransactionDetail = new TransactionDetail();
            request.TransactionDetail.CustomerTransactionId = "***Rate Request***"; // This is a reference field for the customer.  Any value can be used and will be provided in the response.
            //
            request.Version = new VersionId();
            //
            request.ReturnTransitAndCommit          = true;
            request.ReturnTransitAndCommitSpecified = true;
            //
            SetShipmentDetails(request, delivery, stType);
            //
            return(request);
        }
Beispiel #27
0
        public List <ShippingOption> GetShippingOptions()
        {
            var         shippingOptions = new List <ShippingOption>();
            RateRequest request         = CreateRateRequest();
            //
            var service = new RateService(); // Initialize the service

            try
            {
                // Call the web service passing in a RateRequest and returning a RateReply
                RateReply reply = service.getRates(request);

                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful
                {
                    shippingOptions = ParseAnswer(reply);
                }
                else
                {
                    Debug.LogError(new Exception(reply.Notifications[0].Message), false);
                }
            }
            catch (SoapException e)
            {
                Debug.LogError(e);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            return(shippingOptions);
        }
Beispiel #28
0
        private static void SetPackageLineItems(RateRequest request, Delivery delivery)
        {
            int i = 1;
            List <RequestedPackageLineItem> lstItems = new List <RequestedPackageLineItem>();

            foreach (DeliveryItem item in delivery.Items)
            {
                SKUInfo sku = item.Product;
                RequestedPackageLineItem ritem = new RequestedPackageLineItem();
                ritem.SequenceNumber    = i.ToString(); // package sequence number
                ritem.GroupPackageCount = i.ToString();
                // package weight
                ritem.Weight                = new Weight();
                ritem.Weight.Units          = WeightUnits.LB;
                ritem.Weight.UnitsSpecified = true;
                ritem.Weight.Value          = ValidationHelper.GetDecimal(sku.SKUWeight, 1) * item.Amount;
                ritem.Weight.ValueSpecified = true;
                // package dimensions
                ritem.Dimensions = new Dimensions();
                ritem.Dimensions.UnitsSpecified = false;
                lstItems.Add(ritem);
                i += 1;
            }
            request.RequestedShipment.RequestedPackageLineItems = lstItems.ToArray();
        }
Beispiel #29
0
        public static double FedExEstimatedRate(Person shipto, ProductCollection cart)
        {
            double temp = 0.0;                                                //return 0.0 if something is wrong

            RateRequest request = FedEx.FedExCreateRateRequest(shipto, cart); //TODO:  better to use shoppingcartV2 if it was available
            RateService service = new RateService();                          // Initialize the service

            try
            {
                // Call the web service passing in a RateRequest and returning a RateReply
                RateReply reply = service.getRates(request);
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful
                {
                    //ShowRateReply(reply);
                    for (int i = 0; i < reply.RateReplyDetails[0].RatedShipmentDetails.Count(); i++)
                    {
                        ShipmentRateDetail rateDetail = reply.RateReplyDetails[0].RatedShipmentDetails[i].ShipmentRateDetail;
                        if ((double)rateDetail.TotalNetCharge.Amount > temp)
                        {
                            temp = (double)rateDetail.TotalNetCharge.Amount;
                        }
                    }
                }
                FedEx.FedExShowNotifications(reply);
            }
            catch (Exception ex)
            {
                temp = 0.0;
            }
            return(temp);
        }
        private void SetPackageLineItems(RateRequest request)
        {
            request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[Shipment.PackageCount];

            int i = 0;

            foreach (Package package in Shipment.Packages)
            {
                request.RequestedShipment.RequestedPackageLineItems[i] = new RequestedPackageLineItem();
                request.RequestedShipment.RequestedPackageLineItems[i].SequenceNumber    = (i + 1).ToString();
                request.RequestedShipment.RequestedPackageLineItems[i].GroupPackageCount = "1";
                // package weight
                request.RequestedShipment.RequestedPackageLineItems[i].Weight       = new Weight();
                request.RequestedShipment.RequestedPackageLineItems[i].Weight.Units = WeightUnits.LB;
                request.RequestedShipment.RequestedPackageLineItems[i].Weight.Value = package.RoundedWeight;
                // package dimensions
                request.RequestedShipment.RequestedPackageLineItems[i].Dimensions        = new Dimensions();
                request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Length = package.RoundedLength.ToString();
                request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Width  = package.RoundedWidth.ToString();
                request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Height = package.RoundedHeight.ToString();
                request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Units  = LinearUnits.IN;
                // package insured value
                request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue                 = new Money();
                request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue.Amount          = package.InsuredValue;
                request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue.AmountSpecified = true;
                request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue.Currency        = "USD";
                i++;
            }
        }
Beispiel #31
0
 private RateRequest CreateRateRequest()
 {
     // Build the RateRequest
     var request = new RateRequest();
     //
     request.WebAuthenticationDetail = new WebAuthenticationDetail();
     request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
     request.WebAuthenticationDetail.UserCredential.Key = Key; // Replace "XXX" with the Key
     request.WebAuthenticationDetail.UserCredential.Password = Password; // Replace "XXX" with the Password
     //
     request.ClientDetail = new ClientDetail();
     request.ClientDetail.AccountNumber = AccountNumber; // Replace "XXX" with client's account number
     request.ClientDetail.MeterNumber = MeterNumber; // Replace "XXX" with client's meter number
     //
     request.TransactionDetail = new TransactionDetail();
     request.TransactionDetail.CustomerTransactionId = "***Rate for AdvantShop***"; // This is a reference field for the customer.  Any value can be used and will be provided in the response.
     //
     request.Version = new VersionId(); // WSDL version information, value is automatically set from wsdl
     //
     request.ReturnTransitAndCommit = true;
     request.ReturnTransitAndCommitSpecified = true;
     request.CarrierCodes = new CarrierCodeType[2];
     request.CarrierCodes[0] = CarrierCodeType.FDXE;
     request.CarrierCodes[1] = CarrierCodeType.FDXG;
     //
     SetShipmentDetails(request);
     //
     SetOrigin(request);
     //
     SetDestination(request);
     //
     SetPayment(request);
     //
     SetIndividualPackageLineItems(request);
     //
     return request;
 }
Beispiel #32
0
        private void SetIndividualPackageLineItems(RateRequest request)
        {
            // ------------------------------------------
            // Passing individual pieces rate request
            // ------------------------------------------
            var weight = ShoppingCart.TotalShippingWeight;
            if (!IsPackageTooHeavy(weight))
            {
                request.RequestedShipment.PackageCount = "1";

                request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[1];
                request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
                request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1"; // package sequence number
                request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight(); // package weight
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.KG;
                request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = (decimal)weight;
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions(); // package dimensions

                //it's better to don't pass dims now
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = "0";
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = "0";
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = "0";
                request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN;
                request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue = new Money(); // insured value

                request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Amount = (decimal)TotalPrice;
                request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Currency = CurrencyIso3;

            }
            else
            {
                int totalPackages = 1;
                int totalPackagesWeights = 1;
                if (IsPackageTooHeavy(weight))
                {
                    totalPackagesWeights = SQLDataHelper.GetInt(Math.Ceiling(weight / MaxPackageWeight));
                }

                totalPackages = totalPackagesWeights;
                if (totalPackages == 0)
                    totalPackages = 1;

                float weight2 = weight / totalPackages;

                if (weight2 < 1)
                    weight2 = 1;

                float orderSubTotal2 = ShoppingCart.TotalPrice / totalPackages;

                request.RequestedShipment.PackageCount = totalPackages.ToString();
                request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[totalPackages];

                for (int i = 0; i < totalPackages; i++)
                {
                    request.RequestedShipment.RequestedPackageLineItems[i] = new RequestedPackageLineItem();
                    request.RequestedShipment.RequestedPackageLineItems[i].SequenceNumber = (i + 1).ToString(); // package sequence number
                    request.RequestedShipment.RequestedPackageLineItems[i].Weight = new Weight(); // package weight
                    request.RequestedShipment.RequestedPackageLineItems[i].Weight.Units = WeightUnits.KG;
                    request.RequestedShipment.RequestedPackageLineItems[i].Weight.Value = (decimal)weight2;
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions = new Dimensions(); // package dimensions

                    //it's better to don't pass dims now
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Length = "0";
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Width = "0";
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Height = "0";
                    request.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Units = LinearUnits.CM;
                    request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue = new Money(); // insured value
                    request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue.Amount = (decimal)orderSubTotal2;
                    request.RequestedShipment.RequestedPackageLineItems[i].InsuredValue.Currency = CurrencyIso3;
                }
            }
        }
Beispiel #33
0
 private static void SetOrigin(RateRequest r)
 {
     r.RequestedShipment.Shipper = new Party();
     //r.RequestedShipment.Shipper.Address = _origin;
     r.RequestedShipment.Shipper.Address = new Address();
     r.RequestedShipment.Shipper.Address.PostalCode = _origin.PostalCode;
     r.RequestedShipment.Shipper.Address.CountryCode = _origin.CountryCode;
     r.RequestedShipment.Shipper.Address.Residential = false;
     r.RequestedShipment.Shipper.Address.ResidentialSpecified = true;
 }
Beispiel #34
0
 private void SetOrigin(RateRequest request)
 {
     request.RequestedShipment.Shipper = new Party();
     request.RequestedShipment.Shipper.Address = new Address();
     request.RequestedShipment.Shipper.Address.StreetLines = new string[1] { AddressFrom };
     request.RequestedShipment.Shipper.Address.City = CityFrom;
     request.RequestedShipment.Shipper.Address.StateOrProvinceCode = StateFrom;
     request.RequestedShipment.Shipper.Address.PostalCode = PostalCodeFrom;
     request.RequestedShipment.Shipper.Address.CountryCode = CountryCodeFrom;
 }
Beispiel #35
0
        private static RateRequest CreateRateRequest(FedExAuthentication auth)
        {
            // Build a RateRequest
            RateRequest req = new RateRequest();

            req.WebAuthenticationDetail = new WebAuthenticationDetail();
            req.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
            req.WebAuthenticationDetail.UserCredential.Key = auth.Key;
            req.WebAuthenticationDetail.UserCredential.Password = auth.Password;

            req.ClientDetail = new ClientDetail();
            req.ClientDetail.AccountNumber = auth.AccountNumber.ToString();
            req.ClientDetail.MeterNumber = auth.MeterNumber.ToString();

            req.TransactionDetail = new TransactionDetail();
            req.TransactionDetail.CustomerTransactionId = (auth.CustomerTransactionId != null) ? auth.CustomerTransactionId : "***Rate v10 Request using VC#***";

            req.Version = new VersionId();

            req.ReturnTransitAndCommit = true;
            req.ReturnTransitAndCommitSpecified = true;

            SetShipmentDetails(req);

            return req;
        }
Beispiel #36
0
        private static void SetShipmentDetails(RateRequest r)
        {
            r.RequestedShipment = new RequestedShipment();
            r.RequestedShipment.ShipTimestamp = DateTime.Now;
            r.RequestedShipment.ShipTimestampSpecified = true;
            r.RequestedShipment.DropoffType = DropoffType.REGULAR_PICKUP;
            r.RequestedShipment.DropoffTypeSpecified = true;
            r.RequestedShipment.PackagingType = PackagingType.YOUR_PACKAGING;
            r.RequestedShipment.PackagingTypeSpecified = true;
            if (_packageType != null) {
                foreach (PackagingType type in Enum.GetValues(typeof(PackagingType))) {
                    if (_packageType.ToUpper() == type.ToString()) {
                        r.RequestedShipment.PackagingType = type;
                    }
                }
            }
            r.RequestedShipment.PackagingTypeSpecified = true;
            r.RequestedShipment.FreightShipmentDetail = new FreightShipmentDetail();
            r.RequestedShipment.FreightShipmentDetail.Role = FreightShipmentRoleType.SHIPPER;

            SetOrigin(r);
            SetDestination(r);
            SetPackageLineItems(r);

            //r.RequestedShipment.ServiceType = ServiceType.GROUND_HOME_DELIVERY;
            /*if (_shipType != null && _shipType != "") { // Set the Service Type to a dynamically passed option
                if (Enum.IsDefined(typeof(ServiceType), _shipType)) {
                    r.RequestedShipment.ServiceType = (ServiceType)Enum.Parse(typeof(ServiceType), _shipType, true);
                }
            }
            r.RequestedShipment.ServiceTypeSpecified = true;*/

            if (_insure) {
                r.RequestedShipment.TotalInsuredValue = new Money();
                r.RequestedShipment.TotalInsuredValue.Amount = _insureAmount;
                r.RequestedShipment.TotalInsuredValue.Currency = "USD";
            }

            r.RequestedShipment.RateRequestTypes = new RateRequestType[1];
            r.RequestedShipment.RateRequestTypes[0] = RateRequestType.ACCOUNT;
            //r.RequestedShipment.RateRequestTypes[0] = RateRequestType.LIST;
            r.RequestedShipment.PackageCount = r.RequestedShipment.RequestedPackageLineItems.Count().ToString();
        }
Beispiel #37
0
 private static void SetDestination(RateRequest r)
 {
     r.RequestedShipment.Recipient = new Party();
     //r.RequestedShipment.Recipient.Address = _destination;
     r.RequestedShipment.Recipient.Address = new Address();
     r.RequestedShipment.Recipient.Address.PostalCode = _destination.PostalCode;
     r.RequestedShipment.Recipient.Address.CountryCode = _destination.CountryCode;
     r.RequestedShipment.Recipient.Address.Residential = _destination.Residential;
     r.RequestedShipment.Recipient.Address.ResidentialSpecified = true;
 }
Beispiel #38
0
 private void SetDestination(RateRequest request)
 {
     request.RequestedShipment.Recipient = new Party();
     request.RequestedShipment.Recipient.Address = new Address();
     request.RequestedShipment.Recipient.Address.StreetLines = new string[1] { AddressTo };
     request.RequestedShipment.Recipient.Address.City = CityTo;
     request.RequestedShipment.Recipient.Address.StateOrProvinceCode = StateTo;
     request.RequestedShipment.Recipient.Address.PostalCode = PostalCodeTo;
     request.RequestedShipment.Recipient.Address.CountryCode = CountryCodeTo;
 }
Beispiel #39
0
        private static void SetPackageLineItems(RateRequest r)
        {
            // Get the parts from the database
            List<PartPackage> items = new List<PartPackage>();
            CurtDevDataContext db = new CurtDevDataContext();
            foreach (int part in _parts) {
                // package type ID 1 = shipping box
                List<PartPackage> ppackages = db.PartPackages.Where(x => x.partID.Equals(part) && x.typeID.Equals(1)).ToList<PartPackage>();
                foreach (PartPackage ppackage in ppackages) {
                    for (int p = 0; p < ppackage.quantity; p++) {
                        items.Add(ppackage);
                    }
                }
            }
            List<RequestedPackageLineItem> packageitems = new List<RequestedPackageLineItem>();
            List<FreightShipmentLineItem> freightitems = new List<FreightShipmentLineItem>();
            //Weight TotalWeight = new Weight();
            //TotalWeight.Units = WeightUnits.LB;
            //TotalWeight.Value = 0;
            for (int i = 0; i < items.Count; i++) {
                Weight pweight = null;
                Dimensions pdims = null;
                Volume pvolume = null;

                // package weight
                if (items[i].weight != null && items[i].weight > 0) {
                    pweight = new Weight {
                        Units = WeightUnits.LB,
                        Value = (decimal)items[i].weight
                    };
                }
                if (items[i].height != null && items[i].height > 0 && items[i].width != null && items[i].width > 0 && items[i].length != null && items[i].length > 0) {
                    pdims = new Dimensions {
                        Height = Math.Ceiling((double)items[i].height).ToString(),
                        Width = Math.Ceiling((double)items[i].width).ToString(),
                        Length = Math.Ceiling((double)items[i].length).ToString(),
                        Units = LinearUnits.IN
                    };

                    pvolume = new Volume {
                        Units = VolumeUnits.CUBIC_FT,
                        UnitsSpecified = true,
                        Value = Convert.ToDecimal((items[i].height * items[i].width * items[i].length) / 1728),
                        ValueSpecified = true
                    };

                }
                RequestedPackageLineItem rpackage = new RequestedPackageLineItem {
                    SequenceNumber = (packageitems.Count() + 1).ToString(),
                    GroupPackageCount = "1",
                    Weight = pweight,
                    Dimensions = pdims
                };

                FreightShipmentLineItem rfreight = new FreightShipmentLineItem {
                    Dimensions = pdims,
                    Weight = pweight,
                    Volume = pvolume,
                    Packaging = PhysicalPackagingType.BOX,
                    PackagingSpecified = true,
                    FreightClass = getFreightClass(Convert.ToDouble(pweight.Value / pvolume.Value)),
                    FreightClassSpecified = true
                };
                packageitems.Add(rpackage);
                freightitems.Add(rfreight);
            }
            r.RequestedShipment.RequestedPackageLineItems = packageitems.ToArray<RequestedPackageLineItem>();
            r.RequestedShipment.FreightShipmentDetail.LineItems = freightitems.ToArray<FreightShipmentLineItem>();
            //r.RequestedShipment.TotalWeight = TotalWeight;
        }
Beispiel #40
0
 /// <remarks/>
 public void getRatesAsync(RateRequest RateRequest)
 {
     this.getRatesAsync(RateRequest, null);
 }
Beispiel #41
0
 /// <remarks/>
 public System.IAsyncResult BegingetRates(RateRequest RateRequest, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("getRates", new object[] {
                 RateRequest}, callback, asyncState);
 }
Beispiel #42
0
 /// <remarks/>
 public void getRatesAsync(RateRequest RateRequest, object userState)
 {
     if ((this.getRatesOperationCompleted == null)) {
         this.getRatesOperationCompleted = new System.Threading.SendOrPostCallback(this.OngetRatesOperationCompleted);
     }
     this.InvokeAsync("getRates", new object[] {
                 RateRequest}, this.getRatesOperationCompleted, userState);
 }
Beispiel #43
0
 private static void SetDestination(RateRequest request, Delivery delivery)
 {
     request.RequestedShipment.Recipient = new Party();
     request.RequestedShipment.Recipient.Address = new Address();
     request.RequestedShipment.Recipient.Address.StreetLines = new string[1] { delivery.DeliveryAddress.AddressLine1 };
     request.RequestedShipment.Recipient.Address.City = delivery.DeliveryAddress.AddressCity;
     request.RequestedShipment.Recipient.Address.PostalCode = delivery.DeliveryAddress.AddressZip;
     request.RequestedShipment.Recipient.Address.CountryCode = delivery.DeliveryAddress.GetCountryTwoLetterCode();
     request.RequestedShipment.Recipient.Address.StateOrProvinceCode = delivery.DeliveryAddress.GetStateCode();
 }
Beispiel #44
0
 private static void SetPackageLineItems(RateRequest request, Delivery delivery)
 {
     int i = 1;
     List<RequestedPackageLineItem> lstItems = new List<RequestedPackageLineItem>();
     foreach (DeliveryItem item in delivery.Items)
     {
         SKUInfo sku = item.Product;
         RequestedPackageLineItem ritem = new RequestedPackageLineItem();                
         ritem.SequenceNumber = i.ToString(); // package sequence number
         ritem.GroupPackageCount = i.ToString();
         // package weight
         ritem.Weight = new Weight();
         ritem.Weight.Units = WeightUnits.LB;
         ritem.Weight.UnitsSpecified = true;
         ritem.Weight.Value = ValidationHelper.GetDecimal(sku.SKUWeight, 1) * item.Amount;
         ritem.Weight.ValueSpecified = true;
         // package dimensions
         ritem.Dimensions = new Dimensions();
         ritem.Dimensions.UnitsSpecified = false;
         lstItems.Add(ritem);
         i += 1;
     }
     request.RequestedShipment.RequestedPackageLineItems = lstItems.ToArray();
 }
Beispiel #45
0
 private static void SetShipmentDetails(RateRequest request, Delivery delivery, ServiceType stType)
 {
     request.RequestedShipment = new RequestedShipment();
     request.RequestedShipment.ShipTimestamp = DateTime.Now; // Shipping date and time
     request.RequestedShipment.ShipTimestampSpecified = true;
     request.RequestedShipment.DropoffType = DropoffType.REGULAR_PICKUP; //Drop off types are BUSINESS_SERVICE_CENTER, DROP_BOX, REGULAR_PICKUP, REQUEST_COURIER, STATION
     request.RequestedShipment.ServiceType = stType; // Service types are STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND ...
     request.RequestedShipment.ServiceTypeSpecified = true;
     request.RequestedShipment.PackagingType = PackagingType.FEDEX_PAK; // Packaging type FEDEX_BOK, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
     request.RequestedShipment.PackagingTypeSpecified = true;
     //
     SetOrigin(request, delivery);
     //
     SetDestination(request, delivery);
     //
     SetPackageLineItems(request, delivery);
     //
     request.RequestedShipment.PackageCount = ValidationHelper.GetString(request.RequestedShipment.RequestedPackageLineItems.Length, "1");
 }
Beispiel #46
0
 private static void SetOrigin(RateRequest request, Delivery delivery)
 {
     request.RequestedShipment.Shipper = new Party();
     request.RequestedShipment.Shipper.Address = new Address();
     request.RequestedShipment.Shipper.Address.StreetLines = new string[1] { SettingsKeyInfoProvider.GetValue("SourceStreet", "123 Street") };
     request.RequestedShipment.Shipper.Address.City = SettingsKeyInfoProvider.GetValue("SourceCity", "Los Angeles");
     string[] strCountryState = SettingsKeyInfoProvider.GetValue("SourceCountryState", "US").Split(';');
     CountryInfo ci = CountryInfoProvider.GetCountryInfo(ValidationHelper.GetString(strCountryState[0], "USA"));
     request.RequestedShipment.Shipper.Address.CountryCode = ci.CountryTwoLetterCode;
     StateInfo si = StateInfoProvider.GetStateInfo(ValidationHelper.GetString(strCountryState[1], "California"));
     request.RequestedShipment.Shipper.Address.StateOrProvinceCode = si.StateCode;
     request.RequestedShipment.Shipper.Address.PostalCode = SettingsKeyInfoProvider.GetValue("SourceZip", "90001");
 }
Beispiel #47
0
 private void SetPayment(RateRequest request)
 {
     request.RequestedShipment.ShippingChargesPayment = new FedExRateServiceWebReference.Payment(); //new RateWebServiceClient.RateServiceWebReference.Payment();
     request.RequestedShipment.ShippingChargesPayment.PaymentType = PaymentType.SENDER; // Payment options are RECIPIENT, SENDER, THIRD_PARTY
     request.RequestedShipment.ShippingChargesPayment.PaymentTypeSpecified = true;
     request.RequestedShipment.ShippingChargesPayment.Payor = new Payor();
     request.RequestedShipment.ShippingChargesPayment.Payor.AccountNumber = AccountNumber; // Replace "XXX" with client's account number
 }
Beispiel #48
0
 private static RateRequest CreateRateRequest(Delivery delivery, ServiceType stType)
 {
     // Build a RateRequest
     RateRequest request = new RateRequest();
     //
     request.WebAuthenticationDetail = new WebAuthenticationDetail();
     request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
     request.WebAuthenticationDetail.UserCredential.Key = strFedExUserCredentialKey;
     request.WebAuthenticationDetail.UserCredential.Password = strFedExUserCredentialPassword;
     //
     request.ClientDetail = new ClientDetail();
     request.ClientDetail.AccountNumber = strFedExAccountNumber;
     request.ClientDetail.MeterNumber = strFedExMeterNumber;
     //
     request.TransactionDetail = new TransactionDetail();
     request.TransactionDetail.CustomerTransactionId = "***Rate Request***"; // This is a reference field for the customer.  Any value can be used and will be provided in the response.
     //
     request.Version = new VersionId();
     //
     request.ReturnTransitAndCommit = true;
     request.ReturnTransitAndCommitSpecified = true;
     //
     SetShipmentDetails(request, delivery, stType);
     //
     return request;
 }
Beispiel #49
0
        private void SetShipmentDetails(RateRequest request)
        {
            request.RequestedShipment = new RequestedShipment();
            request.RequestedShipment.DropoffType = DropoffType.REGULAR_PICKUP; //Drop off types are BUSINESS_SERVICE_CENTER, DROP_BOX, REGULAR_PICKUP, REQUEST_COURIER, STATION
            //request.RequestedShipment.ServiceType = ServiceType.INTERNATIONAL_PRIORITY; // Service types are STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND ...
            //request.RequestedShipment.ServiceTypeSpecified = true;
            //request.RequestedShipment.PackagingType = PackagingType.YOUR_PACKAGING; // Packaging type FEDEX_BOK, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
            //request.RequestedShipment.PackagingTypeSpecified = true;

            request.RequestedShipment.TotalInsuredValue = new Money();

            request.RequestedShipment.TotalInsuredValue.Amount = (decimal)TotalPrice; // Не использовать ShoppingCart.TotalPrice - не доступен из потока
            request.RequestedShipment.TotalInsuredValue.Currency = CurrencyIso3;
            request.RequestedShipment.ShipTimestamp = DateTime.Now; // Shipping date and time
            request.RequestedShipment.ShipTimestampSpecified = true;
            request.RequestedShipment.RateRequestTypes = new RateRequestType[2];
            request.RequestedShipment.RateRequestTypes[0] = RateRequestType.ACCOUNT;
            request.RequestedShipment.RateRequestTypes[1] = RateRequestType.LIST;
            request.RequestedShipment.PackageDetail = RequestedPackageDetailType.INDIVIDUAL_PACKAGES;
            request.RequestedShipment.PackageDetailSpecified = true;
        }
Beispiel #50
0
        private RateRequest CreateRateRequest(RateService rate)
        {
            RateRequest rateRequest = new RateRequest();
            UPSSecurity upss = new UPSSecurity();
            UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
            upssSvcAccessToken.AccessLicenseNumber = AccessKey;
            upss.ServiceAccessToken = upssSvcAccessToken;

            UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
            upssUsrNameToken.Username = UserName;
            upssUsrNameToken.Password = Password;
            upss.UsernameToken = upssUsrNameToken;
            rate.UPSSecurityValue = upss;

            RequestType request = new RequestType();
            String[] requestOption = { "Shop" };
            request.RequestOption = requestOption;
            rateRequest.Request = request;

            ShipmentType shipment = new ShipmentType();

            ShipperType shipper = new ShipperType();
            //shipper.ShipperNumber = "ISUS01";
            AddressType shipperAddress = new AddressType();
            String[] addressLine = { "Shipper\'s address line" };
            shipperAddress.AddressLine = addressLine;
            shipperAddress.City = "Shipper\'s city";
            shipperAddress.PostalCode = PostalCodeFrom;
            //shipperAddress.StateProvinceCode = UpsItem.CountryCode;
            shipperAddress.CountryCode = CountryCodeFrom;
            shipperAddress.AddressLine = addressLine;
            shipper.Address = shipperAddress;
            shipment.Shipper = shipper;

            ShipFromType shipFrom = new ShipFromType();
            AddressType shipFromAddress = new AddressType();
            shipFromAddress.AddressLine = addressLine;
            shipFromAddress.City = "ShipFrom city";
            shipFromAddress.PostalCode = PostalCodeFrom;
            //shipFromAddress.StateProvinceCode = "GA";
            shipFromAddress.CountryCode = CountryCodeFrom;
            shipFrom.Address = shipFromAddress;
            shipment.ShipFrom = shipFrom;

            ShipToType shipTo = new ShipToType();
            ShipToAddressType shipToAddress = new ShipToAddressType();
            String[] addressLine1 = { AddressTo };
            shipToAddress.AddressLine = addressLine1;
            shipToAddress.City = CityTo;
            shipToAddress.PostalCode = PostalCodeTo;
            shipToAddress.StateProvinceCode = StateTo;
            shipToAddress.CountryCode = CountryCodeTo;
            shipTo.Address = shipToAddress;
            shipment.ShipTo = shipTo;

            //CodeDescriptionType service = new CodeDescriptionType();
            //service.Code = "02";
            //shipment.Service = service;
            float weight = MeasureUnits.ConvertWeight(ShoppingCart.TotalShippingWeight, MeasureUnits.WeightUnit.Kilogramm, MeasureUnits.WeightUnit.Pound);

            var data = new List<PackageType>();
            if (!IsPackageTooHeavy(weight))
            {

                PackageType package = new PackageType();
                PackageWeightType packageWeight = new PackageWeightType();
                packageWeight.Weight = weight.ToString("F3").Replace(',', '.');

                CodeDescriptionType uom = new CodeDescriptionType();
                uom.Code = "LBS";
                uom.Description = "Pounds";
                packageWeight.UnitOfMeasurement = uom;
                package.PackageWeight = packageWeight;

                CodeDescriptionType packType = new CodeDescriptionType();
                packType.Code = "02";
                package.PackagingType = packType;
                data.Add(package);
            }
            else
            {
                int totalPackages = 1;
                int totalPackagesWeights = 1;
                if (IsPackageTooHeavy(weight))
                {
                    totalPackagesWeights = SQLDataHelper.GetInt(Math.Ceiling(weight / MaxPackageWeight));
                }

                totalPackages = totalPackagesWeights;
                if (totalPackages == 0)
                    totalPackages = 1;

                float weight2 = weight / totalPackages;

                if (weight2 < 1)
                    weight2 = 1;
                for (int i = 0; i < totalPackages; i++)
                {
                    PackageType package = new PackageType();
                    PackageWeightType packageWeight = new PackageWeightType();
                    packageWeight.Weight = weight2.ToString("F3");

                    CodeDescriptionType uom = new CodeDescriptionType();
                    uom.Code = "LBS";
                    uom.Description = "Pounds";
                    packageWeight.UnitOfMeasurement = uom;
                    package.PackageWeight = packageWeight;

                    CodeDescriptionType packType = new CodeDescriptionType();
                    packType.Code = GetPackagingTypeCode(PackagingType);
                    package.PackagingType = packType;
                    data.Add(package);
                }
            }

            PackageType[] pkgArray = data.ToArray();
            shipment.Package = pkgArray;
            rateRequest.Shipment = shipment;

            CodeDescriptionType pckup = new CodeDescriptionType() { Code = GetPickupTypeCode(PickupType) };
            rateRequest.PickupType = pckup;

            CodeDescriptionType ccustomer = new CodeDescriptionType() { Code = GetCustomerClassificationCode(CustomerType) };
            rateRequest.CustomerClassification = ccustomer;

            System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();

            return rateRequest;
        }