Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts the response object into MarketplaceOrder object.
        /// Also makes the call to get the items for the order.
        /// </summary>
        /// <param name="order">The given Amazon order objecdt.</param>
        /// <returns>A MarketplaceOrder object</returns>
        private MarketplaceOrder convertOrderResponseToMarketplaceOrder(MarketplaceWebServiceOrders.Model.Order order)
        {
            var orderStatus = (Inventory.Shared.Models.OrderStatus)Enum.Parse(typeof(Inventory.Shared.Models.OrderStatus), order.OrderStatus, true);

            var marketplaceOrder = new MarketplaceOrder()
            {
                BuyerEmail              = order.BuyerEmail,
                BuyerName               = order.BuyerName,
                OrderTotal              = order.IsSetOrderTotal() ? decimal.Parse(order.OrderTotal.Amount) : 0,
                OrderId                 = order.AmazonOrderId,
                Marketplace             = ChannelName,
                ShipServiceLevel        = order.ShipServiceLevel,
                ShipmentServiceCategory = order.ShipmentServiceLevelCategory,
                NumOfItemsShipped       = order.NumberOfItemsShipped,
                NumOfItemsUnshipped     = order.NumberOfItemsUnshipped,
                PurchaseDate            = order.PurchaseDate,
                LastUpdateDate          = order.LastUpdateDate,
                PaymentMethod           = order.PaymentMethod,
                OrderStatus             = orderStatus,
                OrderType               = order.OrderType,
                EarliestShipDate        = order.EarliestShipDate,
                LatestShipDate          = order.LatestShipDate,
                EarliestDeliveryDate    = order.EarliestDeliveryDate,
                LatestDeliveryDate      = order.LatestDeliveryDate,
                MarketplaceId           = order.MarketplaceId,
                PurchaseOrderNumber     = order.PurchaseOrderNumber,
                SalesChannel            = order.SalesChannel,
                SellerOrderId           = order.SellerOrderId,
            };

            if (order.IsSetShippingAddress())
            {
                marketplaceOrder.ShippingAddressLine1  = order.ShippingAddress.AddressLine1;
                marketplaceOrder.ShippingAddressLine2  = order.ShippingAddress.AddressLine2;
                marketplaceOrder.ShippingAddressLine3  = order.ShippingAddress.AddressLine3;
                marketplaceOrder.ShippingCity          = order.ShippingAddress.City;
                marketplaceOrder.ShippingStateOrRegion = order.ShippingAddress.StateOrRegion;
                marketplaceOrder.ShippingPostalCode    = order.ShippingAddress.PostalCode;
                marketplaceOrder.ShippingAddressName   = order.ShippingAddress.Name;
                marketplaceOrder.ShippingAddressPhone  = order.ShippingAddress.Phone;
            }

            // do the request for the list of items for this order
            var listOrderRequest = new ListOrderItemsRequest {
                SellerId = _credential.MerchantId, AmazonOrderId = order.AmazonOrderId
            };
            var listItemsResponse = _ordersClient.ListOrderItems(listOrderRequest);
            var nextToken         = listItemsResponse.ListOrderItemsResult.NextToken;
            var items             = new List <MarketplaceOrderItem>();
            ListOrderItemsByNextTokenResponse nextTokenResponse = null;

            // convert the item responses to marketplace order item objects.
            var orderItems = listItemsResponse.ListOrderItemsResult.OrderItems;

            do
            {
                if (nextTokenResponse != null)
                {
                    orderItems = nextTokenResponse.ListOrderItemsByNextTokenResult.OrderItems;
                    nextToken  = nextTokenResponse.ListOrderItemsByNextTokenResult.NextToken;
                }

                // iterate and convert the marketplace order item into local object
                for (var i = 0; i < orderItems.Count; i++)
                {
                    var orderItem = orderItems[i];
                    var item      = new MarketplaceOrderItem
                    {
                        OrderId           = order.AmazonOrderId,
                        MarketplaceItemId = orderItem.ASIN,
                        OrderItemId       = orderItem.OrderItemId,
                        SKU           = orderItem.SellerSKU,
                        Title         = orderItem.Title,
                        QtyOrdered    = Convert.ToInt32(orderItem.QuantityOrdered),
                        QtyShipped    = Convert.ToInt32(orderItem.QuantityShipped),
                        ConditionNote = orderItem.ConditionNote
                    };

                    item.Price             = orderItem.IsSetItemPrice() ? decimal.Parse(orderItem.ItemPrice.Amount) : 0;
                    item.ShippingPrice     = orderItem.IsSetShippingPrice() ? decimal.Parse(orderItem.ShippingPrice.Amount) : 0;
                    item.GiftWrapPrice     = orderItem.IsSetGiftWrapPrice() ? decimal.Parse(orderItem.GiftWrapPrice.Amount) : 0;
                    item.Tax               = orderItem.IsSetItemTax() ? decimal.Parse(orderItem.ItemTax.Amount) : 0;
                    item.ShippingTax       = orderItem.IsSetShippingTax() ? decimal.Parse(orderItem.ShippingTax.Amount) : 0;
                    item.GiftWrapTax       = orderItem.IsSetGiftWrapTax() ? decimal.Parse(orderItem.GiftWrapTax.Amount) : 0;
                    item.ShippingDiscount  = orderItem.IsSetShippingDiscount() ? decimal.Parse(orderItem.ShippingDiscount.Amount) : 0;
                    item.PromotionDiscount = orderItem.IsSetPromotionDiscount() ? decimal.Parse(orderItem.PromotionDiscount.Amount) : 0;

                    items.Add(item);
                }

                // get the page order items if the next token not null
                if (!string.IsNullOrWhiteSpace(nextToken))
                {
                    // pause for 2 seconds, this is the restore reate for the ListOrderItemsByNextToken for every 30 quota
                    Thread.Sleep(2000);

                    var nextRequest = new ListOrderItemsByNextTokenRequest {
                        SellerId = _credential.MerchantId, NextToken = nextToken
                    };
                    nextTokenResponse = _ordersClient.ListOrderItemsByNextToken(nextRequest);
                }
            } while (!string.IsNullOrWhiteSpace(nextToken));

            // set the order items to the local object
            marketplaceOrder.OrderItems = items;

            return(marketplaceOrder);
        }
Ejemplo n.º 3
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)
            //{

            //}
        }