public static List<EbayTransactionType> GetAllOrders(AccountType account, TimeFilter timeFilter, StringCollection orderIds) { List<EbayTransactionType> transList = new List<EbayTransactionType>(); GetOrdersCall getOrdersApiCall = new GetOrdersCall(account.SellerApiContext); getOrdersApiCall.IncludeFinalValueFee = true; DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnAll }; getOrdersApiCall.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels); if (orderIds != null) getOrdersApiCall.OrderIDList = orderIds; try { OrderTypeCollection orders = getOrdersApiCall.GetOrders(timeFilter, TradingRoleCodeType.Seller, OrderStatusCodeType.All); foreach (OrderType order in orders) { AddressType addressType = order.ShippingAddress; String shippingAddress = GetShippingAddressString(addressType); String shippingAddressCompact = GetShippingAddressCompactString(addressType); bool completed = order.OrderStatus == OrderStatusCodeType.Completed; foreach (TransactionType trans in order.TransactionArray) { #region Process each ebay transaction // Check if this transaction has already be recorded in system. String transId = trans.TransactionID; if (transId == null || transId == "") { Logger.WriteSystemLog("GetAllOrders: Invalid transaction id, skip and continue."); continue; } EbayTransactionType ebayTrans = new EbayTransactionType(); ebayTrans.SellerName = account.ebayAccount; ebayTrans.OrderId = order.OrderID; ebayTrans.OrderLineItemId = trans.OrderLineItemID; ebayTrans.EbayTransactionId = trans.TransactionID; ebayTrans.EbayRecordId = order.ShippingDetails.SellingManagerSalesRecordNumberSpecified ? order.ShippingDetails.SellingManagerSalesRecordNumber : -1; ebayTrans.BuyerId = order.BuyerUserID; GetUserCall getUserApiCall = new GetUserCall(account.SellerApiContext); getUserApiCall.UserID = order.BuyerUserID; UserType user = getUserApiCall.GetUser(); // BuyerRating if (user.FeedbackScoreSpecified) ebayTrans.BuyerRating = user.FeedbackScore; else ebayTrans.BuyerRating = -1; // BuyerCountryEbayCode ebayTrans.BuyerCountryEbayCode = addressType.Country.ToString(); // BuyerCountry4PXCode ebayTrans.BuyerCountry4PXCode = ""; // BuyerCountry ebayTrans.BuyerCountry = addressType.CountryName; // BuyerCompanyName ebayTrans.BuyerCompanyName = StringUtil.GetSafeString(addressType.CompanyName); // BuyerName ebayTrans.BuyerName = addressType.Name; // BuyerStateOrProvince ebayTrans.BuyerStateOrProvince = addressType.StateOrProvince; // BuyerCity ebayTrans.BuyerCity = addressType.CityName; // BuyerTel ebayTrans.BuyerTel = addressType.Phone; // BuyerMail ebayTrans.BuyerMail = trans.Buyer.Email; // BuyerPostalCode ebayTrans.BuyerPostalCode = addressType.PostalCode; // BuyerAddress ebayTrans.BuyerAddress = shippingAddress; // BuyerAddressCompact ebayTrans.BuyerAddressCompact = shippingAddressCompact; // BuyerAddressLine1 ebayTrans.BuyerAddressLine1 = addressType.Street1; // BuyerAddressLine2 ebayTrans.BuyerAddressLine2 = addressType.Street2; // BuyerPayPal ebayTrans.BuyerPayPal = trans.Buyer.Email; // ItemId ebayTrans.ItemId = trans.Item.ItemID; // What is the valid way to determine if there is a variation. if (trans.Variation != null && trans.Variation.VariationTitle != null && trans.Variation.VariationTitle.Trim() != "") { // ItemTitle ebayTrans.ItemTitle = trans.Variation.VariationTitle; // ItemSKU ebayTrans.ItemSKU = trans.Variation.SKU; } else { // ItemTitle ebayTrans.ItemTitle = trans.Item.Title; // ItemSKU ebayTrans.ItemSKU = trans.Item.SKU; } // ItemPrice if (trans.TransactionPrice != null) ebayTrans.ItemPrice = trans.TransactionPrice.Value; // SaleQuantity ebayTrans.SaleQuantity = trans.QuantityPurchased; if (trans.TransactionPrice != null) { // SalePrice ebayTrans.SalePrice = trans.TransactionPrice.Value * trans.QuantityPurchased; // TotalPrice ebayTrans.TotalPrice = trans.TransactionPrice.Value * trans.QuantityPurchased; } // TODO: there may be multiple transactions in one order. if (order.Total != null) { ebayTrans.TotalPrice = order.Total.Value; ebayTrans.CurrencyId = order.Total.currencyID.ToString(); } else { // Set a default value. ebayTrans.TotalPrice = 0.0; ebayTrans.CurrencyId = ""; } // SaleDate ebayTrans.SaleDate = order.CreatedTime; // SaleDateCN ebayTrans.SaleDateCN = order.CreatedTime.ToLocalTime(); // IsPaid ebayTrans.IsPaid = order.PaidTimeSpecified; // order.AmountPaid // order.CheckoutStatus // ebayPaymentStatus // Status // orderStatus if (ebayTrans.IsPaid == false) { // Some payment is paid using credit card, and while PayPal is processing the payment, // the transaction is marked as unpaid. we should view it as paid. if (order.OrderStatusSpecified && order.OrderStatus == OrderStatusCodeType.Completed) ebayTrans.IsPaid = true; } if (ebayTrans.IsPaid == false) { if (order.CheckoutStatus.StatusSpecified && order.CheckoutStatus.Status == CompleteStatusCodeType.Complete) ebayTrans.IsPaid = true; } // PaidDate ebayTrans.PaidDate = StringUtil.GetSafeDateTime(order.PaidTime); // IsShipped ebayTrans.IsShipped = order.ShippedTimeSpecified; if (order.ShippedTimeSpecified) ebayTrans.ShippedDate = StringUtil.GetSafeDateTime(order.ShippedTime); else ebayTrans.ShippedDate = DateTime.Now.AddYears(-10); // Store the shippedDate as the local date time. ebayTrans.ShippedDate = ebayTrans.ShippedDate.ToLocalTime(); // ShippingServiceCode ebayTrans.ShippingServiceCode = ""; // ShippingService ebayTrans.ShippingService = ""; // ShippingTrackingNo ebayTrans.ShippingTrackingNo = ""; // ShippingCost ebayTrans.ShippingCost = 0.0; // FinalValueFee if (trans.FinalValueFee != null) ebayTrans.FinalValueFee = trans.FinalValueFee.Value; else ebayTrans.FinalValueFee = 0.0; // PayPalFee ebayTrans.PayPalFee = 0.034 * ebayTrans.TotalPrice + 0.3; // IsReceived ebayTrans.IsReceived = false; ebayTrans.IsBuyerLeftFeedback = false; ebayTrans.IsSellerLeftFeedback = false; ebayTrans.IsNeedAttention = false; ebayTrans.MessageStatus = TransactionMessageStatus.NoMessage; ebayTrans.IsContactedBuyer = false; ebayTrans.LastContactedBuyerDate = DateTime.Now.AddYears(-10); ebayTrans.IsResendReplacement = false; ebayTrans.UserComment = ""; GetFeedbackCall getFeedbackApiCall = new GetFeedbackCall(account.SellerApiContext); //DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnAll }; getFeedbackApiCall.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels); getFeedbackApiCall.OrderLineItemID = trans.OrderLineItemID; FeedbackDetailTypeCollection feedbacks = getFeedbackApiCall.GetFeedback(); foreach (FeedbackDetailType feedback in feedbacks) { if (feedback.CommentingUser == account.ebayAccount) ebayTrans.IsSellerLeftFeedback = true; if (feedback.CommentingUser == ebayTrans.BuyerId) ebayTrans.IsBuyerLeftFeedback = true; } if (trans.ShippingDetails != null) { if (trans.ShippingDetails.ShipmentTrackingDetails.Count == 1) { ShipmentTrackingDetailsType shipmentDetails = trans.ShippingDetails.ShipmentTrackingDetails[0]; ebayTrans.ShippingTrackingNo = shipmentDetails.ShipmentTrackingNumber; } } transList.Add(ebayTrans); #endregion } } } catch (Exception ex) { Logger.WriteSystemLog(string.Format("Unexpected expection : {0}", ex.Message)); } return transList; }
public void GetOrders() { Assert.IsNotNull(TestData.NewItem, "Failed because no item available -- requires successful AddItem test"); // GetOrdersCall api = new GetOrdersCall(this.apiContext); api.OrderRole = TradingRoleCodeType.Seller; api.OrderStatus = OrderStatusCodeType.Active; System.DateTime calTo = System.DateTime.Now; System.DateTime calFrom = calTo.AddHours(-1); api.CreateTimeFrom = calFrom; api.CreateTimeTo = calTo; // Make API call. OrderTypeCollection orders = api.GetOrders(calFrom, calTo, api.OrderRole, api.OrderStatus); }
private void BtnGetOrders_Click(object sender, EventArgs e) { try { LstOrders.Items.Clear(); GetOrdersCall apicall = new GetOrdersCall(apiContext); TimeFilter fltr = new TimeFilter(); if (ChkStartFrom.Checked) { fltr.TimeFrom = DatePickStartFrom.Value; } if (ChkStartTo.Checked) { fltr.TimeTo = DatePickStartTo.Value; } OrderTypeCollection orders = apicall.GetOrders(fltr, (TradingRoleCodeType)Enum.Parse(typeof(TradingRoleCodeType), CboRole.SelectedItem.ToString()), (OrderStatusCodeType)Enum.Parse(typeof(OrderStatusCodeType), CboStatus.SelectedItem.ToString())); foreach (OrderType order in orders) { string[] listparams = new string[5]; listparams[0] = order.OrderID; listparams[1] = order.OrderStatus.ToString(); listparams[2] = order.CreatingUserRole.ToString(); listparams[3] = order.AmountSaved.Value.ToString(); string[] itemids = new string[order.TransactionArray.Count]; int index = 0; foreach (TransactionType trans in order.TransactionArray) { itemids[index] = trans.Item.ItemID; index++; } listparams[4] = string.Join(", ", itemids); ListViewItem vi = new ListViewItem(listparams); LstOrders.Items.Add(vi); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// Given a time period specified by startDate and endDate, returns all the order ids created in that period. public static StringCollection GetAllOrderIds(AccountType account, DateTime startDate, DateTime endDate) { if (account.SellerApiContext == null) return null; TimeFilter timeFilter = new TimeFilter(); timeFilter.TimeFrom = startDate; timeFilter.TimeTo = endDate; GetOrdersCall getOrdersApiCall = new GetOrdersCall(account.SellerApiContext); DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnSummary }; getOrdersApiCall.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels); getOrdersApiCall.GetOrders(timeFilter, TradingRoleCodeType.Seller, OrderStatusCodeType.All); StringCollection orderIds = new StringCollection(); foreach (OrderType order in getOrdersApiCall.OrderList) { orderIds.Add(order.OrderID); } return orderIds; }
public static void EbayUploadTrackCode(string account, KeWeiOMS.Domain.OrderType orderType) { ISession NSession = NhbHelper.OpenSession(); Dictionary<string, int> sendNum = new Dictionary<string, int>(); IList<AccountType> accounts = NSession.CreateQuery("from AccountType where AccountName='" + account + "'").SetMaxResults(1). List<AccountType>(); if (accounts.Count > 0) { IList<KeWeiOMS.Domain.OrderType> orderList = new List<KeWeiOMS.Domain.OrderType>(); if (orderType.IsMerger == 1 || orderType.OrderExNo.IndexOf("|") != -1) { orderList = NSession.CreateQuery("from OrderType where MId='" + orderType.Id + "' Or Id ='" + orderType.Id + "'").List<KeWeiOMS.Domain.OrderType>(); } else { orderList.Add(orderType); } ApiContext context = GetGenericApiContext("US"); context.ApiCredential.eBayToken = accounts[0].ApiToken; eBay.Service.Call.CompleteSaleCall call = null; string CarrierUsed = ""; // IList<logisticsSetupType> setups = NSession.CreateQuery("from logisticsSetupType where LId in (select ParentID from LogisticsModeType where LogisticsCode='" + orderType.LogisticMode + "')").List<logisticsSetupType>(); //if (setups != null) //{ // CarrierUsed = setups[0].SetupName; //} CarrierUsed = "China Post"; call = new eBay.Service.Call.CompleteSaleCall(context); foreach (KeWeiOMS.Domain.OrderType order in orderList) { string orderid = ""; string itemid = ""; if (order.OrderExNo.IndexOf("-") == -1) { orderid = order.OrderExNo; GetOrdersCall apicall = new GetOrdersCall(context); OrderTypeCollection orders = null; try { orders = apicall.GetOrders(new StringCollection { order.OrderExNo }); } catch (Exception) { orders = new OrderTypeCollection(); } if (orders.Count > 0) { foreach (TransactionType trans in orders[0].TransactionArray) { itemid = trans.Item.ItemID; orderid = trans.TransactionID; call.Shipment = new ShipmentType(); call.Shipment.DeliveryStatus = eBay.Service.Core.Soap.ShipmentDeliveryStatusCodeType.Delivered; call.Shipment.ShipmentTrackingDetails = new ShipmentTrackingDetailsTypeCollection(); if (orderType.OrderNo == order.TrackCode || order.TrackCode == "" || order.TrackCode == null) { //call.Shipment.ShipmentTrackingNumber = ""; } else { call.Shipment.ShippingCarrierUsed = CarrierUsed; call.Shipment.ShipmentTrackingNumber = orderType.TrackCode.ToString(); } call.Shipment.DeliveryDate = DateTime.Now; call.Shipment.DeliveryDateSpecified = true; call.Shipment.DeliveryStatus = ShipmentDeliveryStatusCodeType.Delivered; try { call.CompleteSale(itemid, orderid, true, true); } catch (Exception ex) { break; } break; } } } else { itemid = order.OrderExNo.Substring(0, order.OrderExNo.IndexOf("-")); orderid = order.OrderExNo.Substring(order.OrderExNo.IndexOf("-") + 1); call.Shipment = new ShipmentType(); call.Shipment.DeliveryStatus = eBay.Service.Core.Soap.ShipmentDeliveryStatusCodeType.Delivered; call.Shipment.ShipmentTrackingDetails = new ShipmentTrackingDetailsTypeCollection(); if (orderType.OrderNo == order.TrackCode || order.TrackCode == "" || order.TrackCode == null) { //call.Shipment.ShipmentTrackingNumber = ""; } else { call.Shipment.ShippingCarrierUsed = CarrierUsed; call.Shipment.ShipmentTrackingNumber = orderType.TrackCode.ToString(); } call.Shipment.DeliveryDate = DateTime.Now; call.Shipment.DeliveryDateSpecified = true; call.Shipment.DeliveryStatus = ShipmentDeliveryStatusCodeType.Delivered; try { call.CompleteSale(itemid, orderid, true, true); } catch (Exception) { continue; } finally { } } } } }