Home
Find the answer to your question
This sample demonstrates how to go about Sales order processing using GetOrders with order creation time filter described in the KB Order management using Trading API - GetOrders. The sample has been written in C# using .NET SDK.
Below is the code. Corresponding GetOrders SOAP request is attached with this article.
using eBay.Service.Call; using eBay.Service.Core.Sdk; using eBay.Service.Util; using eBay.Service.Core.Soap; namespace Trading_Samples { public class OrderManagement { //GetOrders private void GetOrders() { //create the context ApiContext context = new ApiContext(); //set the User token context.ApiCredential.eBayToken = "Your token"; //set the server url context.SoapApiServerUrl = "https://api.sandbox.ebay.com/wsapi"; //enable logging context.ApiLogManager = new ApiLogManager(); context.ApiLogManager.ApiLoggerList.Add(new FileLogger("log.txt", true, true, true)); context.ApiLogManager.EnableLogging = true; //set the version context.Version = "727"; context.Site = SiteCodeType.Australia; bool blnHasMore = true; DateTime CreateTimeFromPrev, CreateTimeFrom, CreateTimeTo; GetOrdersCall getOrders = new GetOrdersCall(context); getOrders.DetailLevelList = new DetailLevelCodeTypeCollection(); getOrders.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); //CreateTimeTo set to the current time CreateTimeTo = DateTime.Now.ToUniversalTime(); //Assumption call is made every 15 sec. So CreateTimeFrom of last call was 15 mins //prior to now TimeSpan ts1 = new TimeSpan(9000000000); CreateTimeFromPrev = CreateTimeTo.Subtract(ts1); //Set the CreateTimeFrom the last time you made the call minus 2 minutes TimeSpan ts2 = new TimeSpan(1200000000); CreateTimeFrom = CreateTimeFromPrev.Subtract(ts2); getOrders.CreateTimeFrom = CreateTimeFrom; getOrders.CreateTimeTo = CreateTimeTo; getOrders.Execute(); if (getOrders.ApiResponse.Ack != AckCodeType.Failure) { //Check if any orders are returned if (getOrders.ApiResponse.OrderArray.Count != 0) { foreach (OrderType order in getOrders.ApiResponse.OrderArray) { //Update your system with the order information. Console.WriteLine("Order Number: " + order.OrderID); Console.WriteLine("OrderStatus: " + order.OrderStatus); Console.WriteLine("Order Created On: " + order.CreatedTime); //Get Order Details TransactionTypeCollection orderTrans = order.TransactionArray; //Order could be comprised of one or more items foreach (TransactionType transaction in orderTrans) { Console.WriteLine("Order for: " + transaction.Item.ItemID + ", " + transaction.Item.SKU + ", " + transaction.Item.Title); //If you are listing variation items, you will need to retrieve the variation //details as chosen by the buyer if (transaction.Variation.SKU != null) { Console.WriteLine("Variation: " + transaction.Variation.SKU); } Console.WriteLine("OrderLineItemID: " + transaction.OrderLineItemID); Console.WriteLine("Qty Purchased: " + transaction.QuantityPurchased); Console.WriteLine("Buyer Info: " + order.BuyerUserID + ", " + transaction.Buyer.Email); } if (order.CheckoutStatus.Status == CompleteStatusCodeType.Complete) { //Get Payment Details Console.WriteLine("Order Adjustment Amount: " + order.AdjustmentAmount.Value); Console.WriteLine("Order Amount Paid: " + order.AmountPaid.Value); Console.WriteLine("Payment Method: " + order.CheckoutStatus.PaymentMethod); ExternalTransactionTypeCollection extTrans = order.ExternalTransaction; foreach(ExternalTransactionType extTran in extTrans) { Console.WriteLine("External TransactionID: " + extTran.ExternalTransactionID); Console.WriteLine("External Transaction Time: " + extTran.ExternalTransactionTime); Console.WriteLine("Payment/Refund Amount: " + extTran.PaymentOrRefundAmount.Value); } //Get shipping information ShippingServiceOptionsType shipping; shipping = order.ShippingServiceSelected; Console.WriteLine("Shipping Service Selected: " + order.ShippingServiceSelected.ShippingService); //Get Shipping Address - Address subject to change if the buyer has not completed checkout AddressType address = order.ShippingAddress; StringBuilder sAdd = new StringBuilder(); sAdd = sAdd.Append(address.Name); if (address.Street != null && address.Street != "") sAdd.Append(", " + address.Street); if (address.Street1 != null && address.Street1 != "") sAdd.Append(", " + address.Street1); if (address.Street2 != null && address.Street2 != "") sAdd.Append(", " + address.Street2); if (address.CityName != null && address.CityName != "") sAdd.Append(", " + address.CityName); if (address.StateOrProvince != null && address.StateOrProvince != "") sAdd.Append(", " + address.StateOrProvince); if (address.PostalCode != null && address.PostalCode != "") sAdd.Append(", " + address.PostalCode); if (address.CountryName != null && address.CountryName != "") sAdd.Append(", " + address.CountryName); if (address.Phone != null && address.Phone != "") sAdd.Append(": Phone" + address.Phone); Console.WriteLine("Shipping Address: " + sAdd); double salesTax; //Get the sales tax if (order.ShippingDetails.SalesTax.SalesTaxAmount == null) salesTax = 0.00; else salesTax = order.ShippingDetails.SalesTax.SalesTaxAmount.Value; Console.WriteLine("Sales Tax: " + salesTax); if (order.BuyerCheckoutMessage != null) { Console.WriteLine("Buyer Checkout Message: " + order.BuyerCheckoutMessage); } } Console.WriteLine("********************************************************"); } } } } } } |