Beispiel #1
0
        /// <summary>
        /// Gets the orders details by order id.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <returns></returns>
        private async Task <IDictionary <string, IList <AmazonOrderItemDetail> > > GetOrdersDetailsByOrderId(AmazonGetOrdersDetails3PartyCommand command)
        {
            Dictionary <string, IList <AmazonOrderItemDetail> > ordersDetails = new Dictionary <string, IList <AmazonOrderItemDetail> >();

            foreach (var request in CreateRequests(command))
            {
                //first request
                var response = await AmazonService.Orders.ListOrderItems(request);

                List <AmazonOrderItemDetail> currentOrderDetails = new List <AmazonOrderItemDetail>();
                if (response.IsSetListOrderItemsResult())
                {
                    //store parsed response data
                    var orderDetails = ParseOrderDetailsResponse(response.ListOrderItemsResult.OrderItems);
                    currentOrderDetails.AddRange(orderDetails);
                }

                //tries to get next details requests (for the same order)
                string nextToken = response.ListOrderItemsResult.NextToken;
                while (!string.IsNullOrEmpty(nextToken))
                {
                    var nextRequest = CreateNextRequest(command, nextToken);
                    //get next response
                    ListOrderItemsByNextTokenResponse nextResponse = await AmazonService.Orders.ListOrderItemsByNextToken(nextRequest);

                    if (nextResponse.IsSetListOrderItemsByNextTokenResult())
                    {
                        //store parsed response data
                        currentOrderDetails.AddRange(ParseOrderDetailsResponse(nextResponse.ListOrderItemsByNextTokenResult.OrderItems));
                        nextToken = nextResponse.ListOrderItemsByNextTokenResult.NextToken;
                    }
                    else
                    {
                        nextToken = null;
                    }
                }

                //store all order details by AmazonOrderId
                ordersDetails.Add(request.AmazonOrderId, currentOrderDetails);
            }

            return(ordersDetails);
        }
Beispiel #2
0
        public static void GetOrderList()
        {
            dt = new DataTable();
            dt.Columns.Add("OrderId");
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig();
            string SellerId           = "A3U1G59YKB47LS";
            string MarketplaceId      = "A1VC38T7YXB528";
            string AccessKeyId        = "AKIAJFRPIMOTC4CJGHLQ";
            string SecretKeyId        = "4KI9yuXr7Ni64iFpdjnW1dw3LNdNXIn4rgOnNrZQ";
            string ApplicationVersion = "1.0";
            string ApplicationName    = "ラスタスポーツ";
            string MWSAuthToken       = "amzn.mws.fea748c0-bfe0-4039-0cc0-88b6ce5c0058";
            string serviceURL         = "https://mws.amazonservices.jp";
            string strbuff            = string.Empty;

            config.ServiceURL = serviceURL;
            MarketplaceWebServiceOrders.MarketplaceWebServiceOrders client = new MarketplaceWebServiceOrdersClient(
                AccessKeyId,
                SecretKeyId,
                ApplicationName,
                ApplicationVersion,
                config);


            //ListOrder
            try
            {
                ListOrdersRequest request = new ListOrdersRequest();
                request.SellerId     = SellerId;
                request.CreatedAfter = DateTime.Now.AddDays(-1);
                List <string> lstMarketplace = new List <string>();
                lstMarketplace.Add(MarketplaceId);
                request.MarketplaceId = lstMarketplace;
                request.MWSAuthToken  = MWSAuthToken;
                ListOrdersResponse response = client.ListOrders(request);
                if (response.IsSetListOrdersResult())
                {
                    ListOrdersResult listOrdersResult = response.ListOrdersResult;
                    if (listOrdersResult.IsSetOrders())
                    {
                        List <Order> orders = listOrdersResult.Orders;
                        foreach (Order order in orders)
                        {
                            dt.Rows.Add(order.AmazonOrderId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var msge = ex.Message;
            }
            //// ListOrderByNextToken
            try
            {
                ListOrdersRequest request = new ListOrdersRequest();
                request.SellerId     = SellerId;
                request.CreatedAfter = DateTime.Now.AddDays(-1);
                List <string> lstMarketplace = new List <string>();
                lstMarketplace.Add(MarketplaceId);
                request.MarketplaceId     = lstMarketplace;
                request.MaxResultsPerPage = 14;
                request.MWSAuthToken      = MWSAuthToken;
                ListOrdersResponse response = client.ListOrders(request);
                if (response.IsSetListOrdersResult())
                {
                    ListOrdersResult listOrdersResult = response.ListOrdersResult;
                    if (listOrdersResult.IsSetOrders())
                    {
                        if (listOrdersResult.NextToken != null)
                        {
                            ListOrdersByNextTokenRequest request1 = new ListOrdersByNextTokenRequest();

                            request1.SellerId     = SellerId;
                            request1.MWSAuthToken = MWSAuthToken;
                            request1.NextToken    = listOrdersResult.NextToken;
                            ListOrdersByNextTokenResponse response1 = client.ListOrdersByNextToken(request1);
                            if (response1.IsSetListOrdersByNextTokenResult())
                            {
                                ListOrdersByNextTokenResult listOrdersByNextResult = response1.ListOrdersByNextTokenResult;
                                if (listOrdersByNextResult.IsSetOrders())
                                {
                                    List <Order> orders = listOrdersByNextResult.Orders;
                                    foreach (Order order in orders)
                                    {
                                        dt.Rows.Add(order.AmazonOrderId);
                                        //   strbuff += order.AmazonOrderId + System.Environment.NewLine;
                                    }
                                }
                            }
                        }
                    }
                    var val = strbuff;
                }
                Environment.Exit(0);
            }
            catch (Exception ex)
            {
            }

            // //List Order Item
            //try
            //{
            //    foreach (DataRow dr in dt.Rows)
            //    {
            //        ListOrderItemsRequest request = new ListOrderItemsRequest();
            //        request.SellerId = SellerId;
            //        request.AmazonOrderId = dr["OrderId"].ToString();
            //        request.MWSAuthToken = MWSAuthToken;
            //        ListOrderItemsResponse response = client.ListOrderItems(request);
            //        if (response.IsSetListOrderItemsResult())
            //        {
            //            ListOrderItemsResult listOrderItemsResult = response.ListOrderItemsResult;
            //            if (listOrderItemsResult.IsSetOrderItems())
            //            {
            //                List<OrderItem> orderItems = listOrderItemsResult.OrderItems;
            //                foreach (OrderItem orderItem in orderItems)
            //                {
            //                    strbuff += "商品名:" + orderItem.Title + System.Environment.NewLine;
            //                }
            //            }
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{

            //}
            //// ListOrderItem_byNextToken
            try
            {
                foreach (DataRow dr in dt.Rows)
                {
                    ListOrderItemsRequest request = new ListOrderItemsRequest();
                    request.SellerId      = SellerId;
                    request.AmazonOrderId = dr["OrderId"].ToString();
                    request.MWSAuthToken  = MWSAuthToken;

                    ListOrderItemsResponse response = client.ListOrderItems(request);
                    if (response.IsSetListOrderItemsResult())
                    {
                        ListOrderItemsResult listOrderItemsResult = response.ListOrderItemsResult;
                        if (listOrderItemsResult.NextToken != null)
                        {
                            ListOrderItemsByNextTokenRequest request1 = new ListOrderItemsByNextTokenRequest();
                            request1.SellerId     = SellerId;
                            request1.MWSAuthToken = MWSAuthToken;
                            request1.NextToken    = listOrderItemsResult.NextToken;

                            ListOrderItemsByNextTokenResponse response1 = client.ListOrderItemsByNextToken(request1);
                            if (response1.IsSetListOrderItemsByNextTokenResult())
                            {
                                ListOrderItemsByNextTokenResult listOrderByNextItemsResult = response1.ListOrderItemsByNextTokenResult;
                                if (listOrderByNextItemsResult.IsSetOrderItems())
                                {
                                    List <OrderItem> orderItems = listOrderItemsResult.OrderItems;
                                    foreach (OrderItem orderItem in orderItems)
                                    {
                                        if (orderItem.IsSetOrderItemId())
                                        {
                                            strbuff += "商品名:" + orderItem.Title + System.Environment.NewLine;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            //// GetOrder
            //try
            //{
            //    foreach (DataRow dr in dt.Rows)
            //    {
            //        GetOrderRequest request = new GetOrderRequest();
            //        request.SellerId = SellerId;
            //        request.MWSAuthToken = MWSAuthToken;
            //        List<string> amazonorderId = new List<string>();
            //        amazonorderId.Add(dr["OrderId"].ToString());
            //        request.AmazonOrderId = amazonorderId;

            //        GetOrderResponse response = client.GetOrder(request);
            //        if (response.IsSetGetOrderResult())
            //        {
            //            List<Order> orders = response.GetOrderResult.Orders;
            //            foreach (Order order in orders)
            //            {
            //                strbuff += "購入者:" + order.AmazonOrderId + ","+ order.OrderStatus + System.Environment.NewLine;
            //            }
            //        }
            //    }
            //}

            //catch (Exception ex)
            //{

            //}

            //// GetService Status
            //try
            //{
            //    MarketplaceWebServiceOrdersConfig config1 = new MarketplaceWebServiceOrdersConfig();
            //    config1.ServiceURL = serviceURL;
            //    MarketplaceWebServiceOrders.MarketplaceWebServiceOrders client1 = new MarketplaceWebServiceOrdersClient(
            //                                                                            AccessKeyId,
            //                                                                            SecretKeyId,
            //                                                                            ApplicationName,
            //                                                                            ApplicationVersion,
            //                                                                            config1);
            //    MarketplaceWebServiceOrders.Model.GetServiceStatusRequest  request = new MarketplaceWebServiceOrders.Model.GetServiceStatusRequest();
            //    request.SellerId = SellerId;
            //    request.MWSAuthToken = MWSAuthToken;
            //    // MarketplaceWebServiceOrders.Model.GetServiceStatusRequest
            //    var response = client1.GetServiceStatus(request);
            //    if (response.IsSetGetServiceStatusResult())
            //    {
            //        strbuff = "処理状況:" + response.GetServiceStatusResult.Status;
            //    }
            //}
            //catch (Exception ex)
            //{

            //}
        }
        /// <summary>
        /// If ListOrderItems cannot return all the order items in one go, it will
        /// provide a nextToken. That nextToken can be used with this operation to
        /// retrive the next batch of items for that order.
        ///
        /// </summary>
        /// <param name="service">Instance of MarketplaceWebServiceOrders service</param>
        /// <param name="request">ListOrderItemsByNextTokenRequest request</param>
        public static void InvokeListOrderItemsByNextToken(MarketplaceWebServiceOrders service, ListOrderItemsByNextTokenRequest request)
        {
            try
            {
                ListOrderItemsByNextTokenResponse response = service.ListOrderItemsByNextToken(request);


                Console.WriteLine("Service Response");
                Console.WriteLine("=============================================================================");
                Console.WriteLine();

                Console.WriteLine("        ListOrderItemsByNextTokenResponse");
                if (response.IsSetListOrderItemsByNextTokenResult())
                {
                    Console.WriteLine("            ListOrderItemsByNextTokenResult");
                    ListOrderItemsByNextTokenResult listOrderItemsByNextTokenResult = response.ListOrderItemsByNextTokenResult;
                    if (listOrderItemsByNextTokenResult.IsSetNextToken())
                    {
                        Console.WriteLine("                NextToken");
                        Console.WriteLine("                    {0}", listOrderItemsByNextTokenResult.NextToken);
                    }
                    if (listOrderItemsByNextTokenResult.IsSetAmazonOrderId())
                    {
                        Console.WriteLine("                AmazonOrderId");
                        Console.WriteLine("                    {0}", listOrderItemsByNextTokenResult.AmazonOrderId);
                    }
                    if (listOrderItemsByNextTokenResult.IsSetOrderItems())
                    {
                        Console.WriteLine("                OrderItems");
                        OrderItemList    orderItems    = listOrderItemsByNextTokenResult.OrderItems;
                        List <OrderItem> orderItemList = orderItems.OrderItem;
                        foreach (OrderItem orderItem in orderItemList)
                        {
                            Console.WriteLine("                    OrderItem");
                            if (orderItem.IsSetASIN())
                            {
                                Console.WriteLine("                        ASIN");
                                Console.WriteLine("                            {0}", orderItem.ASIN);
                            }
                            if (orderItem.IsSetSellerSKU())
                            {
                                Console.WriteLine("                        SellerSKU");
                                Console.WriteLine("                            {0}", orderItem.SellerSKU);
                            }
                            if (orderItem.IsSetOrderItemId())
                            {
                                Console.WriteLine("                        OrderItemId");
                                Console.WriteLine("                            {0}", orderItem.OrderItemId);
                            }
                            if (orderItem.IsSetTitle())
                            {
                                Console.WriteLine("                        Title");
                                Console.WriteLine("                            {0}", orderItem.Title);
                            }
                            if (orderItem.IsSetQuantityOrdered())
                            {
                                Console.WriteLine("                        QuantityOrdered");
                                Console.WriteLine("                            {0}", orderItem.QuantityOrdered);
                            }
                            if (orderItem.IsSetQuantityShipped())
                            {
                                Console.WriteLine("                        QuantityShipped");
                                Console.WriteLine("                            {0}", orderItem.QuantityShipped);
                            }
                            if (orderItem.IsSetItemPrice())
                            {
                                Console.WriteLine("                        ItemPrice");
                                Money itemPrice = orderItem.ItemPrice;
                                if (itemPrice.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", itemPrice.CurrencyCode);
                                }
                                if (itemPrice.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", itemPrice.Amount);
                                }
                            }
                            if (orderItem.IsSetShippingPrice())
                            {
                                Console.WriteLine("                        ShippingPrice");
                                Money shippingPrice = orderItem.ShippingPrice;
                                if (shippingPrice.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", shippingPrice.CurrencyCode);
                                }
                                if (shippingPrice.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", shippingPrice.Amount);
                                }
                            }
                            if (orderItem.IsSetGiftWrapPrice())
                            {
                                Console.WriteLine("                        GiftWrapPrice");
                                Money giftWrapPrice = orderItem.GiftWrapPrice;
                                if (giftWrapPrice.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", giftWrapPrice.CurrencyCode);
                                }
                                if (giftWrapPrice.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", giftWrapPrice.Amount);
                                }
                            }
                            if (orderItem.IsSetItemTax())
                            {
                                Console.WriteLine("                        ItemTax");
                                Money itemTax = orderItem.ItemTax;
                                if (itemTax.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", itemTax.CurrencyCode);
                                }
                                if (itemTax.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", itemTax.Amount);
                                }
                            }
                            if (orderItem.IsSetShippingTax())
                            {
                                Console.WriteLine("                        ShippingTax");
                                Money shippingTax = orderItem.ShippingTax;
                                if (shippingTax.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", shippingTax.CurrencyCode);
                                }
                                if (shippingTax.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", shippingTax.Amount);
                                }
                            }
                            if (orderItem.IsSetGiftWrapTax())
                            {
                                Console.WriteLine("                        GiftWrapTax");
                                Money giftWrapTax = orderItem.GiftWrapTax;
                                if (giftWrapTax.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", giftWrapTax.CurrencyCode);
                                }
                                if (giftWrapTax.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", giftWrapTax.Amount);
                                }
                            }
                            if (orderItem.IsSetShippingDiscount())
                            {
                                Console.WriteLine("                        ShippingDiscount");
                                Money shippingDiscount = orderItem.ShippingDiscount;
                                if (shippingDiscount.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", shippingDiscount.CurrencyCode);
                                }
                                if (shippingDiscount.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", shippingDiscount.Amount);
                                }
                            }
                            if (orderItem.IsSetPromotionDiscount())
                            {
                                Console.WriteLine("                        PromotionDiscount");
                                Money promotionDiscount = orderItem.PromotionDiscount;
                                if (promotionDiscount.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", promotionDiscount.CurrencyCode);
                                }
                                if (promotionDiscount.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", promotionDiscount.Amount);
                                }
                            }
                            if (orderItem.IsSetPromotionIds())
                            {
                                Console.WriteLine("                        PromotionIds");
                                PromotionIdList promotionIds    = orderItem.PromotionIds;
                                List <String>   promotionIdList = promotionIds.PromotionId;
                                foreach (String promotionId in promotionIdList)
                                {
                                    Console.WriteLine("                            PromotionId");
                                    Console.WriteLine("                                {0}", promotionId);
                                }
                            }
                            if (orderItem.IsSetCODFee())
                            {
                                Console.WriteLine("                        CODFee");
                                Money CODFee = orderItem.CODFee;
                                if (CODFee.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", CODFee.CurrencyCode);
                                }
                                if (CODFee.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", CODFee.Amount);
                                }
                            }
                            if (orderItem.IsSetCODFeeDiscount())
                            {
                                Console.WriteLine("                        CODFeeDiscount");
                                Money CODFeeDiscount = orderItem.CODFeeDiscount;
                                if (CODFeeDiscount.IsSetCurrencyCode())
                                {
                                    Console.WriteLine("                            CurrencyCode");
                                    Console.WriteLine("                                {0}", CODFeeDiscount.CurrencyCode);
                                }
                                if (CODFeeDiscount.IsSetAmount())
                                {
                                    Console.WriteLine("                            Amount");
                                    Console.WriteLine("                                {0}", CODFeeDiscount.Amount);
                                }
                            }
                            if (orderItem.IsSetGiftMessageText())
                            {
                                Console.WriteLine("                        GiftMessageText");
                                Console.WriteLine("                            {0}", orderItem.GiftMessageText);
                            }
                            if (orderItem.IsSetGiftWrapLevel())
                            {
                                Console.WriteLine("                        GiftWrapLevel");
                                Console.WriteLine("                            {0}", orderItem.GiftWrapLevel);
                            }
                            if (orderItem.IsSetInvoiceData())
                            {
                                Console.WriteLine("                        InvoiceData");
                                InvoiceData invoiceData = orderItem.InvoiceData;
                                if (invoiceData.IsSetInvoiceRequirement())
                                {
                                    Console.WriteLine("                            InvoiceRequirement");
                                    Console.WriteLine("                                {0}", invoiceData.InvoiceRequirement);
                                }
                                if (invoiceData.IsSetBuyerSelectedInvoiceCategory())
                                {
                                    Console.WriteLine("                            BuyerSelectedInvoiceCategory");
                                    Console.WriteLine("                                {0}", invoiceData.BuyerSelectedInvoiceCategory);
                                }
                                if (invoiceData.IsSetInvoiceTitle())
                                {
                                    Console.WriteLine("                            InvoiceTitle");
                                    Console.WriteLine("                                {0}", invoiceData.InvoiceTitle);
                                }
                                if (invoiceData.IsSetInvoiceInformation())
                                {
                                    Console.WriteLine("                            InvoiceInformation");
                                    Console.WriteLine("                                {0}", invoiceData.InvoiceInformation);
                                }
                            }
                        }
                    }
                }
                if (response.IsSetResponseMetadata())
                {
                    Console.WriteLine("            ResponseMetadata");
                    ResponseMetadata responseMetadata = response.ResponseMetadata;
                    if (responseMetadata.IsSetRequestId())
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", responseMetadata.RequestId);
                    }
                }
                Console.WriteLine("            ResponseHeaderMetadata");
                Console.WriteLine("                RequestId");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.RequestId);
                Console.WriteLine("                ResponseContext");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.ResponseContext);
                Console.WriteLine("                Timestamp");
                Console.WriteLine("                    " + response.ResponseHeaderMetadata.Timestamp);
                Console.WriteLine();
            }
            catch (MarketplaceWebServiceOrdersException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
                Console.WriteLine("ResponseHeaderMetadata: " + ex.ResponseHeaderMetadata);
            }
        }