private ProviderUnits GetProviderUnits(Country originCountry) { ProviderUnits pUnits = new ProviderUnits(); pUnits.MeasurementUnit = MeasurementUnit.Centimeters; pUnits.WeightUnit = WeightUnit.Grams; return(pUnits); }
private PackageList PreparePackages(Warehouse origin, Address destination, BasketItemCollection contents) { PackageList plist = PackageManager.GetPackageList(contents); if (plist == null || plist.Count == 0) { return(null); } ProviderUnits pUnits = GetProviderUnits(origin.Country); //GET UNITS USED BY STORE Store store = Token.Instance.Store; MeasurementUnit storeMeasurementUnit = store.MeasurementUnit; WeightUnit storeWeightUnit = store.WeightUnit; bool requireMC = storeMeasurementUnit != pUnits.MeasurementUnit; bool requireWC = storeWeightUnit != pUnits.WeightUnit; if (requireMC && requireWC) { plist.ConvertBoth(pUnits.WeightUnit, pUnits.MeasurementUnit); } else if (requireWC) { plist.ConvertWeight(pUnits.WeightUnit); } else if (requireMC) { plist.ConvertDimensions(pUnits.MeasurementUnit); } WeightUnit sourceUnit = (Token.Instance.Store.WeightUnit == WeightUnit.Grams || Token.Instance.Store.WeightUnit == WeightUnit.Kilograms) ? WeightUnit.Kilograms : WeightUnit.Pounds; LSDecimal maxWeight = LocaleHelper.ConvertWeight(sourceUnit, MaxPackageWeight, pUnits.WeightUnit); LSDecimal minWeight = LocaleHelper.ConvertWeight(sourceUnit, MinPackageWeight, pUnits.WeightUnit); if (EnablePackageBreakup && maxWeight > 0) { //compose packages (splits items larger than the maximum carrier weight) plist.Compose(maxWeight, minWeight); } else { plist.EnsureMinimumWeight(minWeight); } //convert weight and dimensions to whole numbers plist.ConvertDimsToWholeNumbers(); plist.RoundWeight(1); return(plist); }
private PackageList PreparePackages(Warehouse origin, BasketItemCollection contents) { PackageList plist = PackageManager.GetPackageList(contents); if (plist == null || plist.Count == 0) { return(null); } ProviderUnits pUnits = GetProviderUnits(origin.Country); //GET UNITS USED BY STORE Store store = StoreDataSource.Load(Token.Instance.StoreId); MeasurementUnit storeMeasurementUnit = store.MeasurementUnit; WeightUnit storeWeightUnit = store.WeightUnit; bool requireMC = storeMeasurementUnit != pUnits.MeasurementUnit; bool requireWC = storeWeightUnit != pUnits.WeightUnit; if (requireMC && requireWC) { plist.ConvertBoth(pUnits.WeightUnit, pUnits.MeasurementUnit); } else if (requireWC) { plist.ConvertWeight(pUnits.WeightUnit); } else if (requireMC) { plist.ConvertDimensions(pUnits.MeasurementUnit); } LSDecimal maxWeight = LocaleHelper.ConvertWeight(WeightUnit.Kilograms, MaxPackageWeight, pUnits.WeightUnit); LSDecimal minWeight = LocaleHelper.ConvertWeight(WeightUnit.Kilograms, MinPackageWeight, pUnits.WeightUnit); if (EnablePackageBreakup && maxWeight > 0) { //compose packages (splits items larger than the maximum carrier weight) plist.Compose(maxWeight, minWeight); } else { plist.EnsureMinimumWeight(minWeight); } return(plist); }
private ProviderUnits GetProviderUnits(Country originCountry) { ProviderUnits pUnits = new ProviderUnits(); //DETERMINE FEDEX REQUIRED UNITS string[] imperialUnits = { "US", "PR", "DO", "BS" }; if (Array.IndexOf(imperialUnits, originCountry.CountryCode) > -1) { pUnits.MeasurementUnit = MeasurementUnit.Inches; pUnits.WeightUnit = WeightUnit.Pounds; } else { pUnits.MeasurementUnit = MeasurementUnit.Centimeters; pUnits.WeightUnit = WeightUnit.Kilograms; } return(pUnits); }
private XmlDocument BuildProviderRequest(Warehouse warehouse, Address destination, Package package) { ProviderUnits pUnits = GetProviderUnits(warehouse.Country); //CREATE PROVIDER REQUEST DOCUMENT XmlDocument providerRequest = new XmlDocument(); providerRequest.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><FDXRateAvailableServicesRequest xmlns:api=\"http://www.fedex.com/fsmapi\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"FDXRateAvailableServicesRequest.xsd\"></FDXRateAvailableServicesRequest>"); XmlElement nodRequestHeader = (XmlElement)providerRequest.DocumentElement.AppendChild(providerRequest.CreateElement("RequestHeader")); XmlUtility.SetElementValue(nodRequestHeader, "AccountNumber", this.AccountNumber); XmlUtility.SetElementValue(nodRequestHeader, "MeterNumber", this.MeterNumber); //update the shipment settings XmlUtility.SetElementValue(providerRequest.DocumentElement, "ShipDate", DateTime.Now.ToString("yyyy'-'MM'-'dd")); XmlUtility.SetElementValue(providerRequest.DocumentElement, "DropoffType", DropOffType.ToString()); XmlUtility.SetElementValue(providerRequest.DocumentElement, "Packaging", PackagingType.ToString()); XmlUtility.SetElementValue(providerRequest.DocumentElement, "WeightUnits", GetWeightUnitCode(pUnits.WeightUnit)); XmlUtility.SetElementValue(providerRequest.DocumentElement, "Weight", String.Format("{0:F1}", package.Weight)); XmlElement nodOriginAddress = (XmlElement)providerRequest.DocumentElement.AppendChild(providerRequest.CreateElement("OriginAddress")); XmlUtility.SetElementValue(nodOriginAddress, "StateOrProvinceCode", StringHelper.Truncate(warehouse.Province, 2)); XmlUtility.SetElementValue(nodOriginAddress, "PostalCode", warehouse.PostalCode); XmlUtility.SetElementValue(nodOriginAddress, "CountryCode", warehouse.CountryCode); //set the destination XmlElement nodDestinationAddress = (XmlElement)providerRequest.DocumentElement.AppendChild(providerRequest.CreateElement("DestinationAddress")); XmlUtility.SetElementValue(nodDestinationAddress, "StateOrProvinceCode", StringHelper.Truncate(destination.Province, 2)); XmlUtility.SetElementValue(nodDestinationAddress, "PostalCode", destination.PostalCode); XmlUtility.SetElementValue(nodDestinationAddress, "CountryCode", destination.CountryCode); //set payment type XmlUtility.SetElementValue(providerRequest.DocumentElement, "Payment/PayorType", "SENDER"); if (PackagingType == FDXPackagingType.YOURPACKAGING) { //set the package dimensions LSDecimal decPkgLength = package.Length; LSDecimal decPkgWidth = package.Width; LSDecimal decPkgHeight = package.Height; if (decPkgLength > 0 && decPkgWidth > 0 && decPkgHeight > 0) { //REORDER DIMENSIONS LSDecimal[] arrDims = new LSDecimal[3]; arrDims[0] = decPkgLength; arrDims[1] = decPkgWidth; arrDims[2] = decPkgHeight; Array.Sort(arrDims); //length is longest dimension; decPkgLength = arrDims[2]; //width is middle dimension decPkgWidth = arrDims[1]; //height is shortest dimension decPkgHeight = arrDims[0]; //trial and error, these were the smallest supported dimensions I could find if (decPkgHeight < LocaleHelper.ConvertMeasurement(MeasurementUnit.Inches, 2, pUnits.MeasurementUnit)) { decPkgHeight = LocaleHelper.ConvertMeasurement(MeasurementUnit.Inches, 2, pUnits.MeasurementUnit); } if (decPkgLength < LocaleHelper.ConvertMeasurement(MeasurementUnit.Inches, 7, pUnits.MeasurementUnit)) { decPkgLength = LocaleHelper.ConvertMeasurement(MeasurementUnit.Inches, 7, pUnits.MeasurementUnit); } if (decPkgWidth < LocaleHelper.ConvertMeasurement(MeasurementUnit.Inches, 4, pUnits.MeasurementUnit)) { decPkgWidth = LocaleHelper.ConvertMeasurement(MeasurementUnit.Inches, 4, pUnits.MeasurementUnit); } XmlElement nodDimensions = (XmlElement)providerRequest.DocumentElement.AppendChild(providerRequest.CreateElement("Dimensions")); XmlUtility.SetElementValue(nodDimensions, "Length", "" + ((int)decPkgLength)); XmlUtility.SetElementValue(nodDimensions, "Width", "" + ((int)decPkgWidth)); XmlUtility.SetElementValue(nodDimensions, "Height", "" + ((int)decPkgHeight)); XmlUtility.SetElementValue(nodDimensions, "Units", GetMeasurementUnitCode(pUnits.MeasurementUnit)); } } //CHECK DECLARED VALUE OPTION if (this.IncludeDeclaredValue) { //SET DECLARED VALUE OF SHIPMENT, USE BASE CURRENCY OF STORE XmlElement nodDeclaredValue = (XmlElement)providerRequest.DocumentElement.AppendChild(providerRequest.CreateElement("DeclaredValue")); XmlUtility.SetElementValue(nodDeclaredValue, "Value", String.Format("{0:F2}", package.RetailValue)); string currencyCode = Token.Instance.Store.BaseCurrency.ISOCode; if (currencyCode.Length != 3) { currencyCode = "USD"; } XmlUtility.SetElementValue(nodDeclaredValue, "CurrencyCode", currencyCode); } //SET RESIDENTIAL FLAG if (destination.Residence) { XmlUtility.SetElementValue(providerRequest.DocumentElement, "SpecialServices/ResidentialDelivery", "1"); } XmlUtility.SetElementValue(providerRequest.DocumentElement, "PackageCount", "1"); //RETURN THE REQUEST return(providerRequest); }
private RateRequest CreateRateRequest(Warehouse origin, CommerceBuilder.Users.Address destination, PackageList packageList) { // Build the RateRequest RateRequest request = new RateRequest(); // request.WebAuthenticationDetail = new WebAuthenticationDetail(); request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential(); request.WebAuthenticationDetail.UserCredential.Key = this.Key; request.WebAuthenticationDetail.UserCredential.Password = this.Password; // request.ClientDetail = new ClientDetail(); request.ClientDetail.AccountNumber = this.AccountNumber; request.ClientDetail.MeterNumber = this.MeterNumber; // request.TransactionDetail = new TransactionDetail(); request.TransactionDetail.CustomerTransactionId = "*** Rate v5 Request ***"; // request.Version = new VersionId(); // WSDL version information, value is automatically set from wsdl // // Origin information request.CarrierCodes = new CarrierCodeType[2]; request.CarrierCodes[0] = CarrierCodeType.FDXE; request.CarrierCodes[1] = CarrierCodeType.FDXG; request.RequestedShipment = new RequestedShipment(); request.RequestedShipment.Shipper = new Party(); request.RequestedShipment.Shipper.Address = new CommerceBuilder.Shipping.Providers.FedExWS.RateServiceWebReference.Address(); request.RequestedShipment.Shipper.Address.StreetLines = new string[1] { origin.Address1 }; request.RequestedShipment.Shipper.Address.City = origin.City; request.RequestedShipment.Shipper.Address.StateOrProvinceCode = origin.Province; request.RequestedShipment.Shipper.Address.PostalCode = origin.PostalCode; request.RequestedShipment.Shipper.Address.CountryCode = origin.CountryCode; // // Destination Information request.RequestedShipment.Recipient = new Party(); request.RequestedShipment.Recipient.Address = new CommerceBuilder.Shipping.Providers.FedExWS.RateServiceWebReference.Address(); request.RequestedShipment.Recipient.Address.StreetLines = new string[1] { destination.Address1 }; request.RequestedShipment.Recipient.Address.City = destination.City; request.RequestedShipment.Recipient.Address.StateOrProvinceCode = destination.Province; request.RequestedShipment.Recipient.Address.PostalCode = destination.PostalCode; request.RequestedShipment.Recipient.Address.CountryCode = destination.CountryCode; if (destination.Residence) { request.RequestedShipment.Recipient.Address.Residential = destination.Residence; request.RequestedShipment.Recipient.Address.ResidentialSpecified = true; } // // Payment Information request.RequestedShipment.ShippingChargesPayment = new Payment(); request.RequestedShipment.ShippingChargesPayment.PaymentType = PaymentType.SENDER; request.RequestedShipment.ShippingChargesPayment.PaymentTypeSpecified = true; if (!string.IsNullOrEmpty(this.PayorAccountNumber)) { request.RequestedShipment.ShippingChargesPayment.Payor = new Payor(); request.RequestedShipment.ShippingChargesPayment.Payor.AccountNumber = this.PayorAccountNumber; } // request.RequestedShipment.DropoffType = this.DropoffType; request.RequestedShipment.PackagingType = this.PackagingType; request.RequestedShipment.PackagingTypeSpecified = true; request.RequestedShipment.ServiceTypeSpecified = false; // //request.RequestedShipment.TotalInsuredValue = new Money(); //request.RequestedShipment.TotalInsuredValue.Amount = 100; //request.RequestedShipment.TotalInsuredValue.Currency = "USD"; //request.RequestedShipment.ShipTimestamp = DateTime.Now; // Shipping date and time //request.RequestedShipment.ShipTimestampSpecified = true; request.RequestedShipment.RateRequestTypes = new RateRequestType[1]; request.RequestedShipment.RateRequestTypes[0] = RateRequestType.ACCOUNT; //request.RequestedShipment.RateRequestTypes[0] = RateRequestType.LIST; //???? // // The RateRequest can be populated with one of the following: // // RequestedPackageSummary - Details of multi piece shipment rate request - Use this to rate a total piece total weight shipment. // Array of RequestedPackage - Details of single piece shipment rate request or multiple packages with differing parameters. // //bool bPassRateRequestPackageSummary = false; // //if (bPassRateRequestPackageSummary) //{ // ----------------------------------------- // Passing multi piece shipment rate request // ----------------------------------------- // request.RequestedShipment.TotalWeight = new Weight(); // request.RequestedShipment.TotalWeight.Value = 20.0M; // request.RequestedShipment.TotalWeight.Units = WeightUnits.LB; // // request.RequestedShipment.PackageCount = "2"; // request.RequestedShipment.PackageDetail = RequestedPackageDetailType.PACKAGE_SUMMARY; // // request.RequestedShipment.RequestedPackageSummary = new RequestedPackageSummary(); // request.RequestedShipment.RequestedPackageSummary.Dimensions = new Dimensions(); // package dimensions, applies to each package // request.RequestedShipment.RequestedPackageSummary.Dimensions.Length = "10"; // request.RequestedShipment.RequestedPackageSummary.Dimensions.Width = "10"; // request.RequestedShipment.RequestedPackageSummary.Dimensions.Height = "3"; // request.RequestedShipment.RequestedPackageSummary.Dimensions.Units = LinearUnits.IN; // } // else // { // ------------------------------------------ // Passing individual pieces rate request // ------------------------------------------ request.RequestedShipment.PackageCount = packageList.Count.ToString(); request.RequestedShipment.PackageDetail = RequestedPackageDetailType.INDIVIDUAL_PACKAGES; // request.RequestedShipment.RequestedPackages = new RequestedPackage[packageList.Count]; ProviderUnits pUnits = GetProviderUnits(origin.Country); for (int i = 0; i < packageList.Count; i++) { Package pkg = packageList[i]; request.RequestedShipment.RequestedPackages[i] = new RequestedPackage(); request.RequestedShipment.RequestedPackages[i].SequenceNumber = (i + 1).ToString(); // request.RequestedShipment.RequestedPackages[i].Weight = new Weight(); // package weight request.RequestedShipment.RequestedPackages[i].Weight.Units = GetWeightUnits(pUnits.WeightUnit); request.RequestedShipment.RequestedPackages[i].Weight.Value = (decimal)pkg.Weight; // request.RequestedShipment.RequestedPackages[i].Dimensions = new Dimensions(); // package dimensions request.RequestedShipment.RequestedPackages[i].Dimensions.Length = pkg.Length.ToString(); request.RequestedShipment.RequestedPackages[i].Dimensions.Width = pkg.Width.ToString(); request.RequestedShipment.RequestedPackages[i].Dimensions.Height = pkg.Height.ToString(); request.RequestedShipment.RequestedPackages[i].Dimensions.Units = GetLinearUnits(pUnits.MeasurementUnit); // if (IncludeDeclaredValue) { request.RequestedShipment.RequestedPackages[i].InsuredValue = new Money(); // insured value request.RequestedShipment.RequestedPackages[i].InsuredValue.Amount = (decimal)pkg.RetailValue; request.RequestedShipment.RequestedPackages[i].InsuredValue.Currency = Token.Instance.Store.BaseCurrency.ISOCode; } } //} return(request); }