public UPSService(UPSServiceGlobalSettings globalSettings, MerchantTribe.Web.Logging.ILogger logger) { _Logger = logger; GlobalSettings = globalSettings; Settings = new UPSServiceSettings(); InitializeCodes(); }
public DomesticProvider(USPostalServiceGlobalSettings globalSettings, MerchantTribe.Web.Logging.ILogger logger) { _Logger = logger; this.GlobalSettings = globalSettings; Settings = new USPostalServiceSettings(); InitializeCodes(); }
public InternationalProvider(USPostalServiceGlobalSettings globalSettings, MerchantTribe.Web.Logging.ILogger logger) { _Logger = logger; this.GlobalSettings = globalSettings; Settings = new USPostalServiceSettings(); InitializeCodes(); }
public static ShippingRate RatePackage(FedExGlobalServiceSettings globals, MerchantTribe.Web.Logging.ILogger logger, FedExServiceSettings settings, IShipment package) { ShippingRate result = new ShippingRate(); // Get ServiceType ServiceType currentServiceType = ServiceType.FEDEXGROUND; currentServiceType = (ServiceType)settings.ServiceCode; // Get PackageType PackageType currentPackagingType = PackageType.YOURPACKAGING; currentPackagingType = (PackageType)settings.Packaging; // Set max weight by service CarrierCodeType carCode = GetCarrierCode(currentServiceType); result.EstimatedCost = RateSinglePackage(globals, logger, package, currentServiceType, currentPackagingType, carCode); return(result); }
public RateRequest(FedExGlobalServiceSettings globalSettings, MerchantTribe.Web.Logging.ILogger logger) { RequestHeader = new Header(); ReturnType = ReturnShipmentIndicatorType.NONRETURN; ShipDate = DateTime.Now.AddHours(4); globals = globalSettings; _logger = logger; Service = ServiceType.FEDEXGROUND; Packaging = PackageType.YOURPACKAGING; WeightUnits = WeightType.LBS; OriginAddress = new Address(); DestinationAddress = new Address(); Dimensions = new DimensionsBlock(); this.ContainsAlcohol = false; this.SpecialServices = new RateSpecialServices(); this.PackageCount = 0; }
public FedExProvider(FedExGlobalServiceSettings globalSettings, MerchantTribe.Web.Logging.ILogger logger) { _Logger = logger; GlobalSettings = globalSettings; Settings = new FedExServiceSettings(); }
private static decimal RateSinglePackage(FedExGlobalServiceSettings globalSettings, MerchantTribe.Web.Logging.ILogger logger, IShipment pak, ServiceType service, PackageType packaging, CarrierCodeType carCode) { decimal result = 0m; try { // Auth Header Data var req = new FedExRateServices.RateRequest(); req.WebAuthenticationDetail = new WebAuthenticationDetail(); req.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential(); req.WebAuthenticationDetail.UserCredential.Key = globalSettings.UserKey; req.WebAuthenticationDetail.UserCredential.Password = globalSettings.UserPassword; req.ClientDetail = new ClientDetail(); req.ClientDetail.AccountNumber = globalSettings.AccountNumber; req.ClientDetail.MeterNumber = globalSettings.MeterNumber; req.ClientDetail.IntegratorId = "BVSoftware"; req.Version = new VersionId(); // Basic Transaction Data req.TransactionDetail = new TransactionDetail(); req.TransactionDetail.CustomerTransactionId = System.Guid.NewGuid().ToString(); req.ReturnTransitAndCommit = false; req.CarrierCodes = new CarrierCodeType[1] { carCode }; // Shipment Details req.RequestedShipment = new RequestedShipment(); req.RequestedShipment.LabelSpecification = new LabelSpecification(); req.RequestedShipment.LabelSpecification.ImageType = ShippingDocumentImageType.PDF; req.RequestedShipment.LabelSpecification.LabelFormatType = LabelFormatType.COMMON2D; req.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail = new CustomerSpecifiedLabelDetail(); req.RequestedShipment.DropoffType = GetDropOffType(globalSettings.DefaultDropOffType); req.RequestedShipment.PackagingType = GetPackageType(packaging); req.RequestedShipment.TotalWeight = new Weight(); req.RequestedShipment.TotalWeight.Value = Math.Round(pak.Items.Sum(y => y.BoxWeight), 1); if (pak.Items[0].BoxWeightType == Shipping.WeightType.Kilograms) { req.RequestedShipment.TotalWeight.Units = WeightUnits.KG; } else { req.RequestedShipment.TotalWeight.Units = WeightUnits.LB; } // Uncomment these lines to get insured values passed in // //var totalValue = pak.Items.Sum(y => y.BoxValue); //req.RequestedShipment.TotalInsuredValue = new Money(); //req.RequestedShipment.TotalInsuredValue.Amount = totalValue; //req.RequestedShipment.TotalInsuredValue.Currency = "USD"; req.RequestedShipment.PackageCount = pak.Items.Count.ToString(); req.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[pak.Items.Count]; for (int i = 0; i < pak.Items.Count; i++) { req.RequestedShipment.RequestedPackageLineItems[i] = new RequestedPackageLineItem(); req.RequestedShipment.RequestedPackageLineItems[i].GroupNumber = "1"; req.RequestedShipment.RequestedPackageLineItems[i].GroupPackageCount = (i + 1).ToString(); req.RequestedShipment.RequestedPackageLineItems[i].Weight = new Weight(); req.RequestedShipment.RequestedPackageLineItems[i].Weight.Value = pak.Items[i].BoxWeight; req.RequestedShipment.RequestedPackageLineItems[i].Weight.Units = pak.Items[i].BoxWeightType == Shipping.WeightType.Kilograms ? WeightUnits.KG : WeightUnits.LB; req.RequestedShipment.RequestedPackageLineItems[i].Dimensions = new Dimensions(); req.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Height = pak.Items[i].BoxHeight.ToString(); req.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Length = pak.Items[i].BoxLength.ToString(); req.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Width = pak.Items[i].BoxWidth.ToString(); req.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Units = pak.Items[i].BoxLengthType == LengthType.Centimeters ? LinearUnits.CM : LinearUnits.IN; } req.RequestedShipment.Recipient = new Party(); req.RequestedShipment.Recipient.Address = new FedExRateServices.Address(); req.RequestedShipment.Recipient.Address.City = pak.DestinationAddress.City; req.RequestedShipment.Recipient.Address.CountryCode = GetCountryCode(pak.DestinationAddress.CountryData); req.RequestedShipment.Recipient.Address.PostalCode = pak.DestinationAddress.PostalCode; if (pak.DestinationAddress.CountryData.Bvin == "bf7389a2-9b21-4d33-b276-23c9c18ea0c0" || // US or Canada pak.DestinationAddress.CountryData.Bvin == "94052dcf-1ac8-4b65-813b-b17b12a0491f") { req.RequestedShipment.Recipient.Address.StateOrProvinceCode = pak.DestinationAddress.RegionData.Abbreviation; // GetStateCode(pak.DestinationAddress.RegionData); } else { req.RequestedShipment.Recipient.Address.StateOrProvinceCode = string.Empty; } req.RequestedShipment.Recipient.Address.StreetLines = new string[2] { pak.DestinationAddress.Street, pak.DestinationAddress.Street2 }; if (service == ServiceType.GROUNDHOMEDELIVERY) { req.RequestedShipment.Recipient.Address.Residential = true; req.RequestedShipment.Recipient.Address.ResidentialSpecified = true; } else if (service == ServiceType.FEDEXGROUND) { req.RequestedShipment.Recipient.Address.Residential = false; req.RequestedShipment.Recipient.Address.ResidentialSpecified = true; } else { req.RequestedShipment.Recipient.Address.ResidentialSpecified = false; } req.RequestedShipment.Shipper = new Party(); req.RequestedShipment.Shipper.AccountNumber = globalSettings.AccountNumber; req.RequestedShipment.Shipper.Address = new FedExRateServices.Address(); req.RequestedShipment.Shipper.Address.City = pak.SourceAddress.City; req.RequestedShipment.Shipper.Address.CountryCode = GetCountryCode(pak.SourceAddress.CountryData); req.RequestedShipment.Shipper.Address.PostalCode = pak.SourceAddress.PostalCode; req.RequestedShipment.Shipper.Address.Residential = false; if (pak.SourceAddress.CountryData.Bvin == "bf7389a2-9b21-4d33-b276-23c9c18ea0c0" || // US or Canada pak.SourceAddress.CountryData.Bvin == "94052dcf-1ac8-4b65-813b-b17b12a0491f") { req.RequestedShipment.Shipper.Address.StateOrProvinceCode = pak.SourceAddress.RegionData.Abbreviation; } else { req.RequestedShipment.Shipper.Address.StateOrProvinceCode = string.Empty; } req.RequestedShipment.Shipper.Address.StreetLines = new string[2] { pak.SourceAddress.Street, pak.SourceAddress.Street2 }; var svc = new FedExRateServices.RateService(); RateReply res = svc.getRates(req); if (res.HighestSeverity == NotificationSeverityType.ERROR || res.HighestSeverity == NotificationSeverityType.FAILURE) { if (globalSettings.DiagnosticsMode == true) { foreach (var err in res.Notifications) { logger.LogMessage("FEDEX", err.Message, Web.Logging.EventLogSeverity.Debug); } } result = 0m; } else { result = 0m; var lookingForService = GetServiceType(service); var matchingResponse = res.RateReplyDetails.Where(y => y.ServiceType == lookingForService).FirstOrDefault(); if (matchingResponse != null) { var matchedRate = matchingResponse.RatedShipmentDetails.Where( y => y.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_PACKAGE || y.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_SHIPMENT).FirstOrDefault(); if (matchedRate != null) { result = matchedRate.ShipmentRateDetail.TotalNetCharge.Amount; } } } } catch (Exception ex) { result = 0m; logger.LogException(ex); } return(result); }
private static decimal RateSinglePackage(FedExGlobalServiceSettings globalSettings, MerchantTribe.Web.Logging.ILogger logger, IShipment pak, ServiceType service, PackageType packaging, CarrierCode carCode) { decimal result = 0m; //Try RateRequest req = new RateRequest(globalSettings, logger); req.RequestHeader.AccountNumber = globalSettings.AccountNumber; req.RequestHeader.MeterNumber = globalSettings.MeterNumber; req.RequestHeader.CarrierCode = carCode; req.DeclaredValue = 0.1m; // Destination Address Country destinationCountry = Country.FindByBvin(pak.DestinationAddress.CountryData.Bvin); if (destinationCountry != null) { req.DestinationAddress.CountryCode = destinationCountry.IsoCode; if (destinationCountry.IsoCode == "US" | destinationCountry.IsoCode == "CA") { Region destinationRegion = destinationCountry .Regions .Where(y => y.Abbreviation == pak.DestinationAddress.RegionData.Abbreviation) .SingleOrDefault(); req.DestinationAddress.StateOrProvinceCode = destinationRegion.Abbreviation; } } req.DestinationAddress.PostalCode = pak.DestinationAddress.PostalCode; // Origin Address Country originCountry = Country.FindByBvin(pak.SourceAddress.CountryData.Bvin); if (originCountry != null) { req.OriginAddress.CountryCode = originCountry.IsoCode; if (originCountry.IsoCode == "US" | originCountry.IsoCode == "CA") { Region originRegion = originCountry.Regions.Where(y => y.Abbreviation == pak.SourceAddress.RegionData.Abbreviation) .SingleOrDefault(); req.OriginAddress.StateOrProvinceCode = originRegion.Abbreviation; } } req.OriginAddress.PostalCode = pak.SourceAddress.PostalCode; // Dimensions req.Dimensions.Length = pak.Items[0].BoxLength; req.Dimensions.Width = pak.Items[0].BoxWidth; req.Dimensions.Height = pak.Items[0].BoxHeight; //switch () //{ // case MerchantTribe.Commerce.Shipping.LengthType.Centimeters: // req.Dimensions.Units = DimensionType.CM; // break; //case MerchantTribe.Commerce.Shipping.LengthType.Inches: req.Dimensions.Units = DimensionType.IN; // break; //} req.PackageCount = 1; req.Packaging = packaging; req.ReturnType = ReturnShipmentIndicatorType.NONRETURN; req.Service = service; req.SpecialServices.ResidentialDelivery = globalSettings.ForceResidentialRates; req.Weight = pak.Items[0].BoxWeight; //switch (WebAppSettings.ApplicationWeightUnits) //{ // case MerchantTribe.Commerce.Shipping.WeightType.Kilograms: // req.WeightUnits = WeightType.KGS; // break; // case MerchantTribe.Commerce.Shipping.WeightType.Pounds: req.WeightUnits = WeightType.LBS; // break; //} RateResponse res = req.Send(); if (res.Errors.Count > 0) { result = 0m; } else { if (globalSettings.UseListRates) { if (res.EstimatedCharges.ListCharges.NetCharge > 0) { result = res.EstimatedCharges.ListCharges.NetCharge; } else { result = res.EstimatedCharges.DiscountedCharges.NetCharge; } } else { result = res.EstimatedCharges.DiscountedCharges.NetCharge; } } return(result); }