public static DataSet ListAmazonOrderLineByNextToken(string accountName, string token, string merchantId, string marketplaceId, string accessKeyId, string secretAccessKey) { DataSet amazonOrderLineListDs = new DataSet(); const string applicationName = "<Your Application Name>"; const string applicationVersion = "<Your Application Version>"; ListOrderItemsByNextTokenRequest request = new ListOrderItemsByNextTokenRequest(); string sellerId = merchantId; request.SellerId = sellerId; request.NextToken = token; MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig(); config.ServiceURL = "https://mws.amazonservices.com"; MarketplaceWebServiceOrdersClient client = new MarketplaceWebServiceOrdersClient(accessKeyId, secretAccessKey, applicationName, applicationVersion, config); try { IMWSResponse response = null; response = client.ListOrderItemsByNextToken(request); ResponseHeaderMetadata rhmd = response.ResponseHeaderMetadata; Console.WriteLine("RequestId: " + rhmd.RequestId); Console.WriteLine("Timestamp: " + rhmd.Timestamp); string responseXml = response.ToXML(); System.IO.File.WriteAllText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\AmazonOrderLineList.xml", responseXml); amazonOrderLineListDs.ReadXml(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\AmazonOrderLineList.xml", XmlReadMode.InferSchema); return(amazonOrderLineListDs); } catch (MarketplaceWebServiceOrdersException ex) { ResponseHeaderMetadata rhmd = ex.ResponseHeaderMetadata; //Console.WriteLine("Service Exception:"); //if (rhmd != null) //{ // Console.WriteLine("RequestId: " + rhmd.RequestId); // Console.WriteLine("Timestamp: " + rhmd.Timestamp); //} //Console.WriteLine("Message: " + ex.Message); //Console.WriteLine("StatusCode: " + ex.StatusCode); //Console.WriteLine("ErrorCode: " + ex.ErrorCode); //Console.WriteLine("ErrorType: " + ex.ErrorType); ExceptionUtility exceptionUtility = new ExceptionUtility(); exceptionUtility.ErrorWarningMethod("Amazon List Next Order Line Service Exception: " + accountName, "Message: " + ex.Message, senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum); return(amazonOrderLineListDs); } catch (Exception ex) { ExceptionUtility exceptionUtility = new ExceptionUtility(); exceptionUtility.ErrorWarningMethod("Amazon List Next Order Line Code General Error: " + accountName, "ex: " + ex.Message, senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum); return(amazonOrderLineListDs); } }
public static Dictionary <string, byte[]> GetDomesticLabel2(string orderNum, string channel) { Dictionary <string, byte[]> shippingLabelDic = new Dictionary <string, byte[]>(); DataRow orderHeaderInfoDr = MarketplaceDb.Db.GetOrderHeaderDrByOrderNum(orderNum, channel); DataTable orderRowInfoDt = MarketplaceDb.Db.GetOrderLineDtByOrderNum(orderNum, channel); int weightOz = 0; string reference = ""; List <string> infoList = new List <string>(); foreach (DataRow dr in orderRowInfoDt.Rows) { string sku = dr["ItemNum"].ToString(); DataRow itemDr = MarketplaceDb.Db.GetItemInfoBySKU(sku); int tempWeightOz = 0; if (itemDr == null) { tempWeightOz = 4; } else { tempWeightOz = ConvertUtility.ToInt(itemDr["Weight"]); } weightOz = weightOz + tempWeightOz; reference = reference + sku + "x" + ConvertUtility.ToInt(dr["Quantity"]) + "|"; } infoList.Add(reference); DhlLabelRequest dhlLabelReq = new DhlLabelRequest(); Credentials dhlCred = new Credentials(); dhlCred.Username = ConfigurationManager.AppSettings["firstMileAccount"]; dhlCred.Password = ConfigurationManager.AppSettings["firstMilePassword"]; dhlLabelReq.UserCredentials = dhlCred; dhlLabelReq.WeightOz = weightOz; Address shipToAddress = new Address(); string accountName = orderHeaderInfoDr["AccountName"].ToString(); shipToAddress.Name = orderHeaderInfoDr["ShipName"].ToString(); shipToAddress.Address1 = orderHeaderInfoDr["ShipAddress1"].ToString(); shipToAddress.Address2 = orderHeaderInfoDr["ShipAddress2"].ToString(); shipToAddress.City = orderHeaderInfoDr["ShipCity"].ToString(); shipToAddress.Region = orderHeaderInfoDr["ShipState"].ToString(); shipToAddress.RegionCode = orderHeaderInfoDr["ShipZip"].ToString(); shipToAddress.Country = orderHeaderInfoDr["ShipCountry"].ToString(); shipToAddress.CountryCode = orderHeaderInfoDr["ShipCountry"].ToString(); shipToAddress.PhoneNumber = orderHeaderInfoDr["ShipPhone"].ToString(); dhlLabelReq.ShipToAddress = shipToAddress; Address fromAddress = new Address(); fromAddress.Name = ConfigurationManager.AppSettings["FromName"]; fromAddress.Address1 = ConfigurationManager.AppSettings["FromAddress1"]; fromAddress.Address2 = ConfigurationManager.AppSettings["FromAddress2"]; fromAddress.City = ConfigurationManager.AppSettings["FromCity"]; fromAddress.Region = ConfigurationManager.AppSettings["FromRegion"]; fromAddress.RegionCode = ConfigurationManager.AppSettings["FromRegionCode"]; fromAddress.Country = ConfigurationManager.AppSettings["FromCountry"]; fromAddress.CountryCode = ConfigurationManager.AppSettings["FromCountryCode"]; fromAddress.PhoneNumber = ConfigurationManager.AppSettings["FromPhoneNum"]; dhlLabelReq.FromAddress = fromAddress; dhlLabelReq.IsTest = false; string reference2 = ""; string shipCountry = orderHeaderInfoDr["ShipCountry"].ToString(); if (weightOz >= 16) { dhlLabelReq.LabelType = DomesticLabelType.DhlSmParcelPlusExpedited; reference2 = "DhlSmParcelPlusExpedited"; } else { if (weightOz > 240) { ExceptionUtility exceptionUtility = new ExceptionUtility(); exceptionUtility.ErrorWarningMethod("Domestic Shipping Over Max Weight: " + orderNum, "Domestic Shipping Over Max Weight: " + orderNum, senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum); //shippingLabelDic.Add("EmailSent", "EmailSent"); return(shippingLabelDic); } else { dhlLabelReq.LabelType = DomesticLabelType.DhlSmParcelsExpedited; reference2 = "DhlSmParcelsExpedited"; } } dhlLabelReq.LabelImageFormat = ImageFormat.Gif; dhlLabelReq.LabelSize = LabelSize.Label4X6; dhlLabelReq.Reference1 = orderHeaderInfoDr["OrderNum"].ToString();// order number dhlLabelReq.DocTabValues = infoList.ToArray(); dhlLabelReq.GetRate = true; dhlLabelReq.OriginZipCode = ConfigurationManager.AppSettings["FromRegionCode"]; DhlWebApiClient client = new DhlWebApiClient("DhlApi", "http://ifslabelservice.com/api/DhlApi.svc"); DhlLabelResponse dhlLabelRes = client.GetLabel(dhlLabelReq); //string nativeCommand = dhlLabelRes.NativePrinterCommand; byte[] labelImg = dhlLabelRes.LabelImage; string trackingNum = dhlLabelRes.TrackingNumber; DomesticRateResponse drres = dhlLabelRes.RateInfo; decimal cost = drres.Cost; shippingLabelDic.Add(trackingNum, labelImg); MarketplaceDb.Db.SaveShipmentInfo(orderNum, accountName, channel, trackingNum, reference, reference2, cost, ""); return(shippingLabelDic); }
public static Dictionary <string, string> GetInternationalLabel(string orderNum, string channel) { Dictionary <string, string> shippingLabelDic = new Dictionary <string, string>(); DataRow orderHeaderInfoDr = MarketplaceDb.Db.GetOrderHeaderDrByOrderNum(orderNum, channel); DataTable orderRowInfoDt = MarketplaceDb.Db.GetOrderLineDtByOrderNum(orderNum, channel); int weightOz = 0; string reference = ""; List <string> infoList = new List <string>(); foreach (DataRow dr in orderRowInfoDt.Rows) { string sku = dr["ItemNum"].ToString(); DataRow itemDr = MarketplaceDb.Db.GetItemInfoBySKU(sku); int tempWeightOz = 0; if (itemDr == null) { tempWeightOz = 4; } else { tempWeightOz = ConvertUtility.ToInt(itemDr["Weight"]); } weightOz = weightOz + tempWeightOz; reference = reference + sku + "x" + ConvertUtility.ToInt(dr["Quantity"]) + "|"; } infoList.Add(reference); InternationalLabelRequest intelLabelReq = new InternationalLabelRequest(); Credentials dhlCred = new Credentials(); dhlCred.Username = ConfigurationManager.AppSettings["firstMileAccount"]; dhlCred.Password = ConfigurationManager.AppSettings["firstMilePassword"]; intelLabelReq.UserCredentials = dhlCred; intelLabelReq.WeightLbs = weightOz / 16; Address shipToAddress = new Address(); string accountName = orderHeaderInfoDr["AccountName"].ToString(); shipToAddress.Name = orderHeaderInfoDr["ShipName"].ToString(); shipToAddress.Address1 = orderHeaderInfoDr["ShipAddress1"].ToString(); shipToAddress.Address2 = orderHeaderInfoDr["ShipAddress2"].ToString(); shipToAddress.City = orderHeaderInfoDr["ShipCity"].ToString(); shipToAddress.Region = orderHeaderInfoDr["ShipState"].ToString(); shipToAddress.RegionCode = orderHeaderInfoDr["ShipZip"].ToString(); shipToAddress.Country = orderHeaderInfoDr["ShipCountry"].ToString(); shipToAddress.CountryCode = orderHeaderInfoDr["ShipCountry"].ToString(); shipToAddress.PhoneNumber = orderHeaderInfoDr["ShipPhone"].ToString(); intelLabelReq.ShipToAddress = shipToAddress; Address fromAddress = new Address(); fromAddress.Name = ConfigurationManager.AppSettings["FromName"]; fromAddress.Address1 = ConfigurationManager.AppSettings["FromAddress1"]; fromAddress.Address2 = ConfigurationManager.AppSettings["FromAddress2"]; fromAddress.City = ConfigurationManager.AppSettings["FromCity"]; fromAddress.Region = ConfigurationManager.AppSettings["FromRegion"]; fromAddress.RegionCode = ConfigurationManager.AppSettings["FromRegionCode"]; fromAddress.Country = ConfigurationManager.AppSettings["FromCountry"]; fromAddress.CountryCode = ConfigurationManager.AppSettings["FromCountryCode"]; fromAddress.PhoneNumber = ConfigurationManager.AppSettings["FromPhoneNum"]; intelLabelReq.FromAddress = fromAddress; intelLabelReq.IsoCurrencyCode = "USD"; string shipCountry = orderHeaderInfoDr["ShipCountry"].ToString(); string reference2 = ""; List <string> dhlGmParcelDirectCountryList = ConfigurationManager.AppSettings["DHLGMParcelDirectCountryList"].Split(',').ToList(); if (weightOz >= 704) { ExceptionUtility exceptionUtility = new ExceptionUtility(); exceptionUtility.ErrorWarningMethod("Internation Shipping Over Max Weight: " + orderNum, "Internation Shipping Over Max Weight: " + orderNum, senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum); shippingLabelDic.Add("EmailSent", "EmailSent"); return(shippingLabelDic); } else { if (dhlGmParcelDirectCountryList.Contains(shipCountry)) { intelLabelReq.LabelType = LabelType.DhlGMParcelDirect; reference2 = "DhlGMParcelDirect"; } else { intelLabelReq.LabelType = LabelType.DhlGMParcelPriority; reference2 = "DhlGMParcelPriority"; } } intelLabelReq.TaxIdNumber = ConfigurationManager.AppSettings["TaxId"]; intelLabelReq.IsTest = false; List <CustomsItem> customsItemList = new List <CustomsItem>(); CustomsItem customsItem = new CustomsItem(); customsItem.CountryOfOrigin = "CN"; //etc; customsItemList.Add(customsItem); intelLabelReq.CustomsItems = customsItemList.ToArray(); intelLabelReq.OrderValue = ConvertUtility.ToDecimal(orderHeaderInfoDr["Subtotal"]); intelLabelReq.PackageDescription = ConfigurationManager.AppSettings["PackageDescription"]; intelLabelReq.GetRate = true; intelLabelReq.OriginZipCode = ConfigurationManager.AppSettings["FromRegionCode"]; DhlWebApiClient client = new DhlWebApiClient("DhlApi", "http://ifslabelservice.com/api/DhlApi.svc"); InternationalLabelResponse intelLabelRes = client.GetInternationalLabel(intelLabelReq); string[] labelImagesBase64 = intelLabelRes.LabelImagesBase64; string trackingNum = intelLabelRes.TrackingNumber; InternationalRateResponse irres = intelLabelRes.RateInfo; decimal cost = irres.Cost; string nativeCommand = labelImagesBase64.ToString(); shippingLabelDic.Add(trackingNum, nativeCommand); MarketplaceDb.Db.SaveShipmentInfo(orderNum, channel, accountName, trackingNum, reference, reference2, cost, nativeCommand); return(shippingLabelDic); }
public static List<EbayOrderType> GetOrderFromEbay(string token,string accountNum) { string senderEmail = ConfigurationManager.AppSettings["senderEmail"]; string messageFromPassword= ConfigurationManager.AppSettings["messageFromPassword"]; string messageToEmail = ConfigurationManager.AppSettings["messageToEmail"]; string smtpClient = ConfigurationManager.AppSettings["smtpClient"]; int smtpPortNum = ConvertUtility.ToInt(ConfigurationManager.AppSettings["smtpPortNum"]); List<EbayOrderType> OrderList = new List<EbayOrderType>(); ApiContext context = new ApiContext(); context.ApiCredential.eBayToken = token; context.SoapApiServerUrl = "https://api.ebay.com/wsapi"; context.Site = SiteCodeType.US; DateTime createTimeFrom, createTimeTo; GetOrdersCall GetOrderCall = new GetOrdersCall(context); GetOrderCall.DetailLevelList = new DetailLevelCodeTypeCollection(); GetOrderCall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); createTimeFrom = DateTime.Now.AddDays(-15).ToUniversalTime(); createTimeTo = DateTime.Now.ToUniversalTime(); int pageNumber = 1; int errorCount = 0; GetOrderCall.CreateTimeFrom = createTimeFrom; GetOrderCall.CreateTimeTo = createTimeTo; GetOrderCall.OrderStatus = OrderStatusCodeType.Completed; while (pageNumber<100) { try { PaginationType pagination = new PaginationType(); pagination.EntriesPerPage = 100; GetOrderCall.Pagination = pagination; pagination.PageNumber = pageNumber; GetOrderCall.Execute(); int totalPageNumber = GetOrderCall.PaginationResult.TotalNumberOfPages; if (pageNumber > totalPageNumber) { break; } else { if (GetOrderCall.ApiResponse.Ack != AckCodeType.Failure) { if (GetOrderCall.ApiResponse.OrderArray.Count != 0) { foreach (OrderType orderType in GetOrderCall.ApiResponse.OrderArray) { try { EbayOrderType ebayOrderType = new EbayOrderType(); string orderId = orderType.OrderID; DataRow checkDuplidatedDr = Db.Db.CheckDuplicatedOrderID(orderId); if (checkDuplidatedDr!=null) { if(checkDuplidatedDr["OrderStatus"].ToString() == "Completed") { continue; // continue if order already exist } else { Db.Db.DeleteUncompletedEbayOrder(orderId); } } else { EbayOrderHeaderType ebayOrderHeaderType = AddOrderHeader(orderType);//add header info foreach (ExternalTransactionType externalTransactionType in orderType.ExternalTransaction)//add external trasnaction info { EbayOrderPaymentTransactionType ebayOrderPaymentTransactionType = AddOrderPaymentTransaction(orderId, externalTransactionType); ebayOrderType.paymentTransaction.Add(ebayOrderPaymentTransactionType); } ebayOrderType.Header = ebayOrderHeaderType; int lineId = 0; foreach (TransactionType transactionType in orderType.TransactionArray)//add line info { lineId = lineId + 1; EbayOrderLineType ebayOrderLineType = AddOrderLine(orderId, transactionType, lineId); ebayOrderType.Line.Add(ebayOrderLineType); } OrderList.Add(ebayOrderType); } } catch(Exception ex) { ExceptionUtility exceptionUtility = new ExceptionUtility(); exceptionUtility.CatchMethod(ex, accountNum + ": GetOrderCall--foreach ", ex.Message.ToString(), senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum); continue; //continue next single order if current order error } } } else { continue; // continue next account if no order } } else { ExceptionUtility exceptionUtility = new ExceptionUtility(); exceptionUtility.ErrorWarningMethod("AckCodeType Failure: " + accountNum, "AckCodeType Failure: " + accountNum, senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum); continue; // continue next account if ack error } } pageNumber = pageNumber + 1; } catch (Exception ex) { if (errorCount > 4) { ExceptionUtility exceptionUtility = new ExceptionUtility(); exceptionUtility.CatchMethod(ex,accountNum+ ": While ",ex.Message.ToString(),senderEmail,messageFromPassword,messageToEmail,smtpClient,smtpPortNum); break; } else { errorCount = errorCount + 1; continue; // continue try if error less 4 times } } } return OrderList; }
public static DataSet ListAmazonOrderHeader(string accountName, string merchantId, string marketplaceId, string accessKeyId, string secretAccessKey) { DataSet amazonOrderHeaderListDs = new DataSet(); const string applicationName = "<Your Application Name>"; const string applicationVersion = "<Your Application Version>"; ListOrdersRequest request = new ListOrdersRequest(); string sellerId = merchantId; request.SellerId = sellerId; DateTime createdAfter = System.DateTime.Now.AddDays(-15); request.CreatedAfter = createdAfter; List <string> orderStatusList = new List <string>(); orderStatusList.Add("Unshipped"); orderStatusList.Add("PartiallyShipped"); //orderStatusList.Add("Shipped"); //orderStatusList.Add("Pending"); //orderStatusList.Add("Canceled"); request.OrderStatus = orderStatusList; List <string> marketplaceIdList = new List <string>(); marketplaceIdList.Add(marketplaceId); request.MarketplaceId = marketplaceIdList; MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig(); config.ServiceURL = "https://mws.amazonservices.com"; MarketplaceWebServiceOrdersClient client = new MarketplaceWebServiceOrdersClient(accessKeyId, secretAccessKey, applicationName, applicationVersion, config); //MarketplaceWebServiceOrdersSample sample = new MarketplaceWebServiceOrdersSample(client); try { IMWSResponse response = null; response = client.ListOrders(request); ResponseHeaderMetadata rhmd = response.ResponseHeaderMetadata; string responseXml = response.ToXML(); System.IO.File.WriteAllText(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\AmazonOrderHeaderList.xml", responseXml); amazonOrderHeaderListDs.ReadXml(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\AmazonOrderHeaderList.xml", XmlReadMode.InferSchema); return(amazonOrderHeaderListDs); } catch (MarketplaceWebServiceOrdersException ex) { ResponseHeaderMetadata rhmd = ex.ResponseHeaderMetadata; //Console.WriteLine("Service Exception:"); //if (rhmd != null) //{ // Console.WriteLine("RequestId: " + rhmd.RequestId); // Console.WriteLine("Timestamp: " + rhmd.Timestamp); //} //Console.WriteLine("Message: " + ex.Message); //Console.WriteLine("StatusCode: " + ex.StatusCode); //Console.WriteLine("ErrorCode: " + ex.ErrorCode); //Console.WriteLine("ErrorType: " + ex.ErrorType); ExceptionUtility exceptionUtility = new ExceptionUtility(); exceptionUtility.ErrorWarningMethod("Amazon List Order Header Service Exception: " + accountName, "Message: " + ex.Message, senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum); return(amazonOrderHeaderListDs); } catch (Exception ex) { ExceptionUtility exceptionUtility = new ExceptionUtility(); exceptionUtility.ErrorWarningMethod("Amazon List Order Header Code General Error: " + accountName, "ex: " + ex.Message, senderEmail, messageFromPassword, messageToEmail, smtpClient, smtpPortNum); return(amazonOrderHeaderListDs); } }