private void PurshaceProviderLabels(ShipmentProviderType providerType, Action <OrderShippingInfoDTO> purchaseCallback) { _log.Info("PurchaceProviderLabels. Started, providerType=" + providerType); var info = GetNextShipping(providerType); while (info != null) { _log.Info("Purchasing label, orderId=" + info.OrderAmazonId); purchaseCallback(info); if (info.LabelPurchaseResult == (int)LabelPurchaseResultType.Error) { ExpectedCost -= info.StampsShippingCost ?? 0; } else { var cost = info.StampsShippingCost.HasValue ? info.StampsShippingCost.Value : 0; ActualCost += cost; _log.Info("Actual cost: " + cost); } info = GetNextShipping(providerType); } _log.Info("PurchaceProviderLabels. End"); }
public ScheduledPickupDTO GetLast(ShipmentProviderType providerType) { return(GetAllAsDto() .Where(p => p.ProviderType == (int)providerType) .OrderByDescending(p => p.RequestPickupDate) .ThenByDescending(p => p.ReadyByTime) .FirstOrDefault()); }
public void CallCancelLabels(string[] trackingNumberList, ShipmentProviderType providerType) { var labelService = new LabelService(GetShipmentProviders(_company), _log, _time, _dbFactory, _emailService, _pdfMaker, AddressService.Default); foreach (var trackingNumber in trackingNumberList) { labelService.CancelLabel(providerType, trackingNumber, false); } }
public OrderShippingInfoDTO GetNextShipping(ShipmentProviderType providerType) { lock (_toPrintSync) { var info = _toPrint.FirstOrDefault(sh => sh.ShipmentProviderType == (int)providerType); _log.Info("GetNextShipping, providerType=" + providerType + (info != null ? info.OrderAmazonId : "[null]")); _toPrint.Remove(info); return(info); } }
public static string GetShortName(ShipmentProviderType type) { var typeInt = (int)type; var res = GetAllShippingProviderList().FirstOrDefault(x => x.Type == typeInt); if (res != null) { return(StringHelper.GetFirstNotEmpty(res.ShortName, res.Name)); } return("-"); }
public static string GetName(ShipmentProviderType type) { var typeInt = (int)type; var res = GetAllShippingProviderList().FirstOrDefault(x => x.Type == typeInt); if (res != null) { return(res.Name); } return("-"); }
public void ProcessRecords(IList <DhlInvoiceDTO> invoices, ShipmentProviderType type) { using (var db = _dbFactory.GetRWDb()) { foreach (var invoice in invoices) { var existInvoice = db.DhlInvoices.GetAllAsDto() .FirstOrDefault(iv => iv.InvoiceNumber == invoice.InvoiceNumber && iv.BillNumber == invoice.BillNumber); if (existInvoice == null) { var order = db.Orders.GetByOrderIdAsDto(invoice.OrderNumber); decimal?chargeEstimated = null; if (order != null) { var shippingInfoList = db.OrderShippingInfos.GetAllAsDto() .Where(sh => sh.OrderId == order.Id && sh.IsActive) .ToList(); chargeEstimated = shippingInfoList.Where( sh => sh.ShipmentProviderType == (int)type) .Sum(sh => sh.StampsShippingCost); invoice.Estimated = chargeEstimated; if (Math.Abs((chargeEstimated ?? 0) - invoice.ChargedSummary) < 1) //$1 { invoice.Status = (int)DhlInvoiceStatusEnum.Matched; } else { invoice.Status = (int)DhlInvoiceStatusEnum.Incorrect; } } else { invoice.Status = (int)DhlInvoiceStatusEnum.OrderNotFound; } db.DhlInvoices.Store(invoice); } else { invoice.Id = existInvoice.Id; db.DhlInvoices.Update(invoice); } _log.Info("Invoice was processed, invoice #: " + invoice.InvoiceNumber + ", order #: " + invoice.OrderNumber + ", airbill: " + invoice.BillNumber + ", status: " + invoice.Status); } } }
private void StoreNewTokenInfo(IDbFactory dbFactory, ShipmentProviderType type, TokenInfo token) { using (var db = dbFactory.GetRWDb()) { var marketInfo = db.ShipmentProviders.GetAll().FirstOrDefault(m => m.Type == (int)type); if (marketInfo != null) { marketInfo.Key4 = token.Token; db.Commit(); } } }
private static IList <ShippingMethodDTO> GetShippingMethods(IUnitOfWork db, string countryTo, string countryFrom, int?weightLb, decimal?weightOz, ShipmentProviderType providerType) { var isInternational = countryTo != countryFrom; var oz = (double)(weightOz + weightLb * 16); var providerList = new List <int>() { (int)providerType }; if (providerType == ShipmentProviderType.Stamps) { providerList.Add((int)ShipmentProviderType.StampsPriority); } return(db.ShippingMethods .GetAllAsDto() .Where(sh => sh.IsActive && providerList.Contains(sh.ShipmentProviderType) && sh.IsInternational == isInternational && (!sh.MaxWeight.HasValue || oz < sh.MaxWeight || sh.MaxWeight == 0)) .ToList()); //if (!ShippingUtils.IsInternational(countryTo) // && !ShippingUtils.IsInternational(countryFrom) // && weightLb == 0 // && weightOz == 0) //{ // return db.ShippingMethods.GetAllAsDto().ToList(); //} //if (!ShippingUtils.IsInternational(countryTo) // && !ShippingUtils.IsInternational(countryFrom)) //(string.IsNullOrEmpty(countryTo) || countryTo == "US") && (string.IsNullOrEmpty(countryFrom) || countryFrom == "US")) //{ // return db.ShippingMethods // .GetAllAsDto() // .Where(m => (!(weightLb > 0) && weightOz <= 16) || m.AllowOverweight || m.IsInternational) // .ToList(); //} ////TODO: m.b. add country correction / isInternational logic //return db.ShippingMethods.GetAllAsDto().Where(m => m.IsInternational == ((countryFrom != countryTo) || string.IsNullOrEmpty(countryFrom) || string.IsNullOrEmpty(countryTo)) // && ((!(weightLb > 0) && weightOz <= 16) || m.AllowOverweight || ((countryFrom != countryTo) || string.IsNullOrEmpty(countryFrom) || string.IsNullOrEmpty(countryTo)))) // .ToList(); }
private TokenInfo GetFreshTokenInfo(IDbFactory dbFactory, ShipmentProviderType type) { using (var db = dbFactory.GetRWDb()) { var marketInfo = db.ShipmentProviders.GetAllAsDto().FirstOrDefault(m => m.Type == (int)type); if (marketInfo != null) { return(new TokenInfo() { Token = marketInfo.Key4 }); } } return(null); }
public static IList <ShippingMethodViewModel> GetShippingOptions(IUnitOfWork db, string countryTo, string countryFrom, int weightLb, decimal weightOz, ShipmentProviderType providerType) { var methodList = GetShippingMethods(db, countryFrom, countryTo, weightLb, weightOz, providerType); return(methodList.Select(m => new ShippingMethodViewModel() { Id = m.Id, Name = m.Name }).ToList()); }
public void GetIntlRatesTest(string orderId, ShipmentProviderType type) { using (var db = _dbFactory.GetRWDb()) { var order = db.ItemOrderMappings.GetOrderWithItems(_weightService, orderId, unmaskReferenceStyle: false, includeSourceItems: true); var shippingService = ShippingUtils.InitialShippingServiceIncludeUpgrade(order.InitialServiceType, order.UpgradeLevel); //order.ShippingService var orderItemInfoes = OrderHelper.BuildAndGroupOrderItems(order.Items); var sourceOrderItemInfoes = OrderHelper.BuildAndGroupOrderItems(order.SourceItems); var providers = GetShipmentProviders(_company); var provider = providers.FirstOrDefault(p => p.Type == type); var companyAddress = new CompanyAddressService(_company); if (ShippingUtils.IsInternational(order.ShippingCountry)) { var rates = provider.GetInternationalRates( companyAddress.GetReturnAddress(order.GetMarketId()), companyAddress.GetPickupAddress(order.GetMarketId()), order.GetAddressDto(), _time.GetAppNowTime(), order.WeightD, null, order.IsInsured ? order.TotalPrice : 0, order.IsSignConfirmation, new OrderRateInfo() { ShippingService = shippingService, OrderNumber = order.OrderId, Items = orderItemInfoes, SourceItems = sourceOrderItemInfoes, TotalPrice = order.TotalPrice, Currency = order.TotalPriceCurrency, }, RetryModeType.Normal); Console.WriteLine(rates.Rates.Count); } else { var rates = provider.GetLocalRate( companyAddress.GetReturnAddress(order.GetMarketId()), companyAddress.GetPickupAddress(order.GetMarketId()), order.GetAddressDto(), _time.GetAppNowTime(), order.WeightD, null, order.IsInsured ? order.TotalPrice : 0, order.IsSignConfirmation, new OrderRateInfo() { ShippingService = shippingService, InitialServiceType = order.InitialServiceType, OrderNumber = order.OrderId, Items = orderItemInfoes, SourceItems = sourceOrderItemInfoes, TotalPrice = order.TotalPrice, Currency = order.TotalPriceCurrency, }, RetryModeType.Normal); Console.WriteLine(rates.Rates.Count); } } }
public IShipmentApi GetShipmentProviderByType( ShipmentProviderType providerType, ILogService log, ITime time, IDbFactory dbFactory, IWeightService weightService, IList <ShipmentProviderDTO> shipmentProviderInfos, string defaultCustomType, string outputDirectory, string reserveDirectory, string templateDirectory) { var trackingNumberService = new TrackingNumberService(log, time, dbFactory); var supportedShippingMethods = new List <ShippingMethodDTO>(); using (var db = dbFactory.GetRDb()) { supportedShippingMethods = db.ShippingMethods .GetAllAsDto() .Where(m => m.ShipmentProviderType == (int)providerType && m.IsActive) .ToList(); } switch (providerType) { case ShipmentProviderType.Stamps: var stampsProvider = shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.Stamps); if (stampsProvider != null) { var authList = shipmentProviderInfos.Where(p => p.Type == (int)ShipmentProviderType.Stamps || p.Type == (int)ShipmentProviderType.StampsPriority) .ToList(); return(new StampsShipmentApi(stampsProvider.Id, (ShipmentProviderType)stampsProvider.Type, log, time, weightService, trackingNumberService, authList.ToList <IStampsAuthInfo>(), LabelFormat.Jpg, false, "Children Clothes", true, outputDirectory, reserveDirectory, false)); } return(null); case ShipmentProviderType.StampsPriority: var stampsPriorityProvider = shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.StampsPriority); if (stampsPriorityProvider != null) { var authList = shipmentProviderInfos.Where(p => p.Type == (int)ShipmentProviderType.Stamps || p.Type == (int)ShipmentProviderType.StampsPriority) .ToList(); return(new StampsShipmentApi(stampsPriorityProvider.Id, (ShipmentProviderType)stampsPriorityProvider.Type, log, time, weightService, trackingNumberService, authList.ToList <IStampsAuthInfo>(), LabelFormat.Jpg, false, "Children Clothes", true, outputDirectory, reserveDirectory, false)); } return(null); case ShipmentProviderType.Amazon: var amazonProvider = shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.Amazon); if (amazonProvider != null) { return(new AmazonShipmentApi(amazonProvider.Id, log, time, weightService, supportedShippingMethods, amazonProvider.Key1, amazonProvider.Key2, amazonProvider.Password, amazonProvider.StampUsername, amazonProvider.EndPointUrl, outputDirectory, reserveDirectory, templateDirectory)); } return(null); case ShipmentProviderType.Dhl: var dhlProvider = shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.Dhl); if (dhlProvider != null) { return(new DhlShipmentApi(dhlProvider.Id, log, time, dhlProvider.EndPointUrl, dhlProvider.UserName, dhlProvider.Password, dhlProvider.Key1, dhlProvider.Key2, outputDirectory, reserveDirectory, templateDirectory)); } return(null); case ShipmentProviderType.DhlECom: var dhlEComProvider = shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.DhlECom); if (dhlEComProvider != null) { return(new DhlECommerceShipmentApi(dhlEComProvider.Id, log, time, dbFactory, weightService, dhlEComProvider.UserName, dhlEComProvider.Password, dhlEComProvider.Key1, dhlEComProvider.Key2, dhlEComProvider.Key3, defaultCustomType, outputDirectory, reserveDirectory, GetFreshTokenInfo(dbFactory, ShipmentProviderType.DhlECom)?.Token, () => GetFreshTokenInfo(dbFactory, ShipmentProviderType.DhlECom), (t) => StoreNewTokenInfo(dbFactory, ShipmentProviderType.DhlECom, t))); } return(null); case ShipmentProviderType.IBC: var ibcProvider = shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.IBC); if (ibcProvider != null) { return(new IBCShipmentApi(ibcProvider.Id, log, time, dbFactory, weightService, PortalEnum.PA, ibcProvider.EndPointUrl, ibcProvider.UserName, ibcProvider.Password, ibcProvider.Key1, defaultCustomType, outputDirectory, reserveDirectory)); } return(null); case ShipmentProviderType.SkyPostal: var skyPostalProvider = shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.SkyPostal); if (skyPostalProvider != null) { return(new SkyPostalShipmentApi(skyPostalProvider.Id, log, time, dbFactory, weightService, PortalEnum.PA, skyPostalProvider.EndPointUrl, skyPostalProvider.UserName, skyPostalProvider.Password, skyPostalProvider.Key1, skyPostalProvider.Key2, skyPostalProvider.Key3, defaultCustomType, outputDirectory, reserveDirectory)); } return(null); case ShipmentProviderType.FedexSmartPost: case ShipmentProviderType.FedexOneRate: case ShipmentProviderType.FedexGeneral: var fedexProvider = shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)providerType); if (fedexProvider != null) { return(new FedexShipmentApi(PortalEnum.PA, fedexProvider.Id, log, time, weightService, fedexProvider.EndPointUrl, fedexProvider.UserName, fedexProvider.Password, fedexProvider.Key1, fedexProvider.Key2, fedexProvider.Key3, (FedexRateTypes)Int32.Parse(fedexProvider.Key4), defaultCustomType, outputDirectory, reserveDirectory, templateDirectory)); } return(null); case ShipmentProviderType.FIMS: var fimsProvider = shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)providerType); if (fimsProvider != null) { return(new FIMSShipmentApi(fimsProvider.Id, log, time, fimsProvider.EndPointUrl, fimsProvider.Key1, fimsProvider.Key2, fimsProvider.Key3, //air bill number defaultCustomType, outputDirectory, reserveDirectory, templateDirectory)); } return(null); } return(null); }
public ITrackingProvider GetTrackingProviderByType( ShipmentProviderType providerType, CompanyDTO company, IList <ShipmentProviderDTO> shipmentProviderInfos, IDbFactory dbFactory, ILogService log, ITime time) { var providerInfo = company.ShipmentProviderInfoList.FirstOrDefault(sh => sh.Type == (int)providerType); if (providerInfo == null) { return(null); } //throw new NotSupportedException("Tracking providerType=" + providerType + " - not supported"); switch (providerType) { case ShipmentProviderType.Dhl: return(new DhlTrackingProvider(log, time, providerInfo.EndPointUrl, providerInfo.UserName, providerInfo.Password, providerInfo.Key1)); case ShipmentProviderType.Stamps: //return new ComposedUspsAndCanadaPostTrackingProvider(log, // time, // company.USPSUserId, // company.CanadaPostKeys); return(new UspsTrackingProvider(log, time, company.USPSUserId)); case ShipmentProviderType.DhlECom: return(new DhlECommerceTrackingProvider(log, time, providerInfo.UserName, providerInfo.Password, providerInfo.Key1, providerInfo.Key2, providerInfo.Key3, GetFreshTokenInfo(dbFactory, ShipmentProviderType.DhlECom)?.Token, () => GetFreshTokenInfo(dbFactory, ShipmentProviderType.DhlECom), (t) => StoreNewTokenInfo(dbFactory, ShipmentProviderType.DhlECom, t))); case ShipmentProviderType.FedexGeneral: case ShipmentProviderType.FedexOneRate: case ShipmentProviderType.FedexSmartPost: return(new FedexTrackingApi(log, time, providerInfo.EndPointUrl, providerInfo.UserName, providerInfo.Password, providerInfo.Key1, providerInfo.Key2, providerInfo.Key3, company.ShortName)); } throw new NotSupportedException("No implementation for trackingProvider=" + providerType); }
public static bool ValidateLenghts(AddressDTO address, ShipmentProviderType type, long?dropShipperId) { if (dropShipperId == DSHelper.AshfordDsId) { //Address length max 30 if (!String.IsNullOrEmpty(address.Address1) && address.Address1.Length > 30) //Checked { return(false); } if (!String.IsNullOrEmpty(address.Address2) && address.Address2.Length > 30) //Checked { return(false); } } if (type == ShipmentProviderType.IBC) { /*<ShipTo> * <Company>40</Company> * <Attn>40</Attn> * <AddressLine1>40</AddressLine1> * <AddressLine2>40</AddressLine2> * <AddressLine3>40</AddressLine3> * <City>40</City> * <StateCode>15</StateCode> * <Zip>10</Zip> * <Zip4>10</Zip4> * <CountryCode>5</CountryCode> * <CountryName>40</CountryName> * <PhoneAreaCode>3</PhoneAreaCode> * <Phone>20</Phone> * <PhoneExt>10</PhoneExt> * <Fax>15</Fax> * <EMail>65</EMail> * <Department>40</Department> * <Reference>N/A</Reference> * <ResidentialFlag>false</ResidentialFlag> * <IsPOBox>false</IsPOBox> * </ShipTo>*/ if (String.IsNullOrEmpty(address.FullName) || address.FullName.Length < 2 || address.FullName.Length > 40) { return(false); } if (!String.IsNullOrEmpty(address.Address1) && address.Address1.Length > 40) //Checked { return(false); } if (!String.IsNullOrEmpty(address.Address2) && address.Address2.Length > 40) //Checked { return(false); } if (!String.IsNullOrEmpty(address.City) && address.City.Length > 40) { return(false); } if (!String.IsNullOrEmpty(address.State) && address.State.Length > 15) //Checked { return(false); } if (!String.IsNullOrEmpty(address.Zip) && address.Zip.Length > 10) { return(false); } if (!String.IsNullOrEmpty(address.Country) && address.Country.Length > 40) { return(false); } } if (type == ShipmentProviderType.Dhl) { if (String.IsNullOrEmpty(address.FullName) || address.FullName.Length < 2 || address.FullName.Length > 35) { return(false); } if (!String.IsNullOrEmpty(address.Address1) && address.Address1.Length > 35) { return(false); } if (!String.IsNullOrEmpty(address.Address2) && address.Address2.Length > 35) { return(false); } if (!String.IsNullOrEmpty(address.City) && address.City.Length > 35) { return(false); } if (!String.IsNullOrEmpty(address.State) && address.State.Length > 35) { return(false); } if (!String.IsNullOrEmpty(address.Zip) && address.Zip.Length > 12) { return(false); } if (!String.IsNullOrEmpty(address.Country) && address.Country.Length > 35) { return(false); } } if (type == ShipmentProviderType.DhlECom) { if (String.IsNullOrEmpty(address.FullName) || address.FullName.Length < 2 || address.FullName.Length > 30) { return(false); } if (!String.IsNullOrEmpty(address.Address1) && address.Address1.Length > 40) { return(false); } if (!String.IsNullOrEmpty(address.Address2) && address.Address2.Length > 40) { return(false); } if (!String.IsNullOrEmpty(address.City) && address.City.Length > 30) { return(false); } if (!String.IsNullOrEmpty(address.State) && address.State.Length > 30) { return(false); } if (!String.IsNullOrEmpty(address.Zip) && (address.Zip.Length > 11 || address.Zip.Length < 5)) { return(false); } if (!String.IsNullOrEmpty(address.Country) && address.Country.Length != 2) { return(false); } } if (type == ShipmentProviderType.Stamps) { var isInternational = ShippingUtils.IsInternational(address.FinalCountry); if (String.IsNullOrEmpty(address.FullName) || address.FullName.Length < 2) { return(false); } if (!String.IsNullOrEmpty(address.Address1) && address.Address1.Length > 50) { return(false); } if (!String.IsNullOrEmpty(address.Address2) && address.Address2.Length > 50) { return(false); } if (!String.IsNullOrEmpty(address.City) && address.City.Length > 50) { return(false); } if (!String.IsNullOrEmpty(address.State) && address.State.Length > 30) { return(false); } if (!String.IsNullOrEmpty(address.Zip) && (!isInternational && address.Zip.Length > 5)) { return(false); } if (!String.IsNullOrEmpty(address.ZipAddon) && (!isInternational && address.ZipAddon.Length > 4)) { return(false); } if (!String.IsNullOrEmpty(address.Country) && address.Country.Length > 35) { return(false); } } if (type == ShipmentProviderType.IBC) { var isInternational = ShippingUtils.IsInternational(address.FinalCountry); if (String.IsNullOrEmpty(address.FullName) || address.FullName.Length < 2) { return(false); } if (!String.IsNullOrEmpty(address.Address1) && address.Address1.Length > 50) { return(false); } if (!String.IsNullOrEmpty(address.Address2) && address.Address2.Length > 50) { return(false); } if (!String.IsNullOrEmpty(address.City) && address.City.Length > 50) { return(false); } if (!String.IsNullOrEmpty(address.State) && address.State.Length > 30) { return(false); } if (!String.IsNullOrEmpty(address.Zip) && (!isInternational && address.Zip.Length > 5)) { return(false); } if (!String.IsNullOrEmpty(address.ZipAddon) && (!isInternational && address.ZipAddon.Length > 4)) { return(false); } if (!String.IsNullOrEmpty(address.Country) && address.Country.Length > 35) { return(false); } } if (type == ShipmentProviderType.Amazon) { //No validation, do not pass, changes have no effects } return(true); }