예제 #1
0
        public MarketplaceWebServiceOrdersClient GetMWSOrdersClient()
        {
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig();

            //
            // IMPORTANT: Uncomment out the appropriate line for the country you wish
            // to sell in:
            //
            // United States:
            config.ServiceURL = "https://mws.amazonservices.com/Orders/2011-01-01";
            //
            // Canada:
            // config.ServiceURL = "https://mws.amazonservices.ca/Orders/2011-01-01";
            //
            // Europe:
            // config.ServiceURL = "https://mws-eu.amazonservices.com/Orders/2011-01-01";
            //
            // Japan:
            // config.ServiceURL = "https://mws.amazonservices.jp/Orders/2011-01-01";
            //
            // China:
            // config.ServiceURL = "https://mws.amazonservices.com.cn/Orders/2011-01-01";
            //

            /************************************************************************
             * Instantiate  Implementation of Marketplace Web Service Orders
             ***********************************************************************/

            MarketplaceWebServiceOrdersClient service = new MarketplaceWebServiceOrdersClient(
                "SyncManager", "N/A", this.AccessKeyId, this.SecretAccessKey, config);

            return(service);
        }
예제 #2
0
        public ListOrderItemsResponse AmazonOrderItemResponse(string AmazonOrderid)
        {
            ListOrderItemsResponse            _objListOrderItem = new ListOrderItemsResponse();
            MarketplaceWebServiceOrdersConfig config            = new MarketplaceWebServiceOrdersConfig();

            config.ServiceURL = CommonValue.strServiceURL;

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

            ListOrderItemsRequest _req           = new ListOrderItemsRequest();
            List <string>         _marketPlaceId = new List <string>();

            _marketPlaceId.Add(MarketplaceId);



            _req.SellerId      = SellerId;
            _req.MWSAuthToken  = MWSAuthToken;
            _req.AmazonOrderId = AmazonOrderid;

            return(_objListOrderItem = client.ListOrderItems(_req));
        }
예제 #3
0
        public ListOrdersResponse AmazonOrderResponse()
        {
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig();

            config.ServiceURL = CommonValue.strServiceURL;

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

            ListOrdersRequest _req           = new ListOrdersRequest();
            List <string>     _marketPlaceId = new List <string>();

            _marketPlaceId.Add(MarketplaceId);
            _req.MarketplaceId = _marketPlaceId;
            _req.CreatedAfter  = DateTime.Now.AddDays(-1);

            _req.SellerId     = SellerId;
            _req.MWSAuthToken = MWSAuthToken;

            return(listorders = client.ListOrders(_req));
        }
예제 #4
0
        public AmazonService(PlatformServiceFactory platformServiceFactory, string company, string connectionString)
        {
            m_platformServiceFactory = platformServiceFactory;
            m_company          = company;
            m_connectionString = connectionString;
            using (ERPContext context = new ERPContext(m_connectionString))
            {
                var q = from amazonAccount in context.AmazonAccount
                        select amazonAccount;
                foreach (var row in q)
                {
                    sellerIdDictionary[row.AccountName]     = row.SellerId;
                    mwsAuthTokenDictionary[row.AccountName] = row.MWSAuthToken;
                }
            }

            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig();

            config.ServiceURL = serviceURL;
            client            = new MarketplaceWebServiceOrdersClient(accessKey, secretKey, appName, appVersion, config);

            MarketplaceWebServiceConfig mwsConfig = new MarketplaceWebServiceConfig();

            mwsConfig.ServiceURL = serviceURL;
            mwsClient            = new MarketplaceWebServiceClient(accessKey, secretKey, appName, appVersion, mwsConfig);
        }
예제 #5
0
        protected override void RegisterServices(IKernel kernel)
        {
            kernel.Bind <MarketplaceWebServiceOrders.MarketplaceWebServiceOrders>().ToMethod(context =>
            {
                var amazonAppSettings = context.Kernel.Get <AmazonAppSettings>();
                var config            = new MarketplaceWebServiceOrdersConfig {
                    ServiceURL = amazonAppSettings.OrdersApiEndpoint
                };
                return(new MarketplaceWebServiceOrdersClient
                           ("MrCMS", MrCMSApplication.AssemblyVersion, amazonAppSettings.AWSAccessKeyId, amazonAppSettings.SecretKey, config));
            }).InRequestScope();

            kernel.Bind <MarketplaceWebServiceProducts.MarketplaceWebServiceProducts>().ToMethod(context =>
            {
                var amazonAppSettings = context.Kernel.Get <AmazonAppSettings>();
                var config            = new MarketplaceWebServiceProductsConfig {
                    ServiceURL = amazonAppSettings.ProductsApiEndpoint
                };
                return(new MarketplaceWebServiceProductsClient
                           ("MrCMS", MrCMSApplication.AssemblyVersion, amazonAppSettings.AWSAccessKeyId, amazonAppSettings.SecretKey, config));
            }).InRequestScope();
            kernel.Bind <MarketplaceWebService.MarketplaceWebService>().ToMethod(context =>
            {
                var amazonAppSettings = context.Kernel.Get <AmazonAppSettings>();
                var config            = new MarketplaceWebServiceConfig {
                    ServiceURL = amazonAppSettings.ProductsApiEndpoint
                };
                return(new MarketplaceWebServiceClient(amazonAppSettings.AWSAccessKeyId, amazonAppSettings.SecretKey, "MrCMS", MrCMSApplication.AssemblyVersion, config));
            }).InRequestScope();
        }
        private MarketplaceWebServiceOrders CreateService()
        {
            /************************************************************************
             * Access Key ID and Secret Access Key ID
             ***********************************************************************/
            string accessKeyId     = base.AccessInfo.KeyId;
            string secretAccessKey = base.AccessInfo.SecretKeyId;

            /************************************************************************
             * The application name and version are included in each MWS call's
             * HTTP User-Agent field. These are required fields.
             ***********************************************************************/
            string applicationName    = base.ApplicationInfo.Name;
            string applicationVersion = base.ApplicationInfo.Version;

            /************************************************************************
             * Uncomment to try advanced configuration options. Available options are:
             *
             *  - Proxy Host and Proxy Port
             *  - MWS Service endpoint URL
             *  - User Agent String to be sent to FBA Inventory Service MWS  service
             *
             ***********************************************************************/

            var config = new MarketplaceWebServiceOrdersConfig
            {
                ServiceURL = base.ServiceUrl.Value
            };

            /************************************************************************
             * Instantiate  Implementation of Marketplace Web Service Orders
             ***********************************************************************/
            return(new MarketplaceWebServiceOrdersClient(accessKeyId, secretAccessKey, applicationName, applicationVersion, config));
        }
예제 #7
0
        private MarketplaceWebServiceOrders.MarketplaceWebServiceOrders Configurations(string intergrationType, string accessKey, string secretKey)
        {
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig();

            config.ServiceURL = SOHelper.GetIntegrationType(intergrationType.Trim(), SOConstants.serviceUrl);
            MarketplaceWebServiceOrders.MarketplaceWebServiceOrders serviceOrder = new MarketplaceWebServiceOrdersClient(accessKey, secretKey, SOConstants.appName, SOConstants.version, config);
            return(serviceOrder);
        }
예제 #8
0
        public void SetUp()
        {
            var config = new MarketplaceWebServiceOrdersConfig
            {
                ServiceURL = "https://mws.amazonservices.co.uk/Orders/2013-09-01"
            };

            _client = new MarketplaceWebServiceOrdersClient("AKIAJXUDX6A3XIMZLWFA", "4yQzxltFZjlytmkKmlHhkAAcZTTZUbHpJekTOFj2", "C#", "4.0", config);
        }
예제 #9
0
        public void synOrder(Shop shop)
        {
            if (shop.OrderLastUpDatedAfter == null)
            {
                shop.OrderLastUpDatedAfter = AppConstant.lastUpdatedAfter;
            }
            if (lastUpdatedAfter == null)
            {
                this.lastUpdatedAfter = shop.OrderLastUpDatedAfter.Value;
            }
            this.sellerId     = shop.SellerId;
            this.mwsAuthToken = shop.MwsAuthToken;
            shopId            = shop.Id;
            shopMarketplaceId = shop.ShopMarketplaceId;
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig();

            config.ServiceURL = serviceURL;
            client            = new MarketplaceWebServiceOrdersClient(accessKey, secretKey, appName, appVersion, config);

            ListOrdersResponse listOrdersResponse = getListOrders();

            if (listOrdersResponse == null)
            {
                return;
            }
            foreach (Order order in listOrdersResponse.ListOrdersResult.Orders)
            {
                dealOrder(shopId, order);
            }
            if (String.IsNullOrEmpty(listOrdersResponse.ListOrdersResult.NextToken))
            {
                return;
            }
            ListOrdersByNextTokenResponse listOrdersByNextTokenResponse = getListOrdersByNextToken(listOrdersResponse.ListOrdersResult.NextToken);

            if (listOrdersByNextTokenResponse == null)
            {
                return;
            }
            while (true)
            {
                foreach (Order order in listOrdersByNextTokenResponse.ListOrdersByNextTokenResult.Orders)
                {
                    dealOrder(shopId, order);
                }
                if (String.IsNullOrEmpty(listOrdersByNextTokenResponse.ListOrdersByNextTokenResult.NextToken))
                {
                    return;
                }
                listOrdersByNextTokenResponse = getListOrdersByNextToken(listOrdersByNextTokenResponse.ListOrdersByNextTokenResult.NextToken);
                if (listOrdersByNextTokenResponse == null)
                {
                    return;
                }
            }
        }
        private MarketplaceWebServiceOrdersClient GetOrdersApiService()
        {
            var config = new MarketplaceWebServiceOrdersConfig()
            {
                ServiceURL = _amazonAppSettings.OrdersApiEndpoint
            };

            return(new MarketplaceWebServiceOrdersClient("MrCMS", MrCMSApplication.AssemblyVersion, MrCMSApplication.Get <AmazonAppSettings>().AWSAccessKeyId,
                                                         MrCMSApplication.Get <AmazonAppSettings>().SecretKey,
                                                         config));
        }
예제 #11
0
        /// <summary>
        /// Implement the Begin step for PowerShell Cmdlets
        /// </summary>
        protected override void BeginProcessing()
        {
            base.BeginProcessing();
            var config = new MarketplaceWebServiceOrdersConfig
            {
                ServiceURL = "https://mws.amazonservices.com/Orders/2011-01-01"
            };

            this.marketplaceWebServiceOrdersClient = new MarketplaceWebServiceOrdersClient(
                ApplicationName, ApplicationVersion, AccessKeyId, SecretAccessKey, config);
        }
예제 #12
0
        public void LeerLineasPedido(Order order, int pagina, int numero)
        {
            ListOrderItemsRequest request = new ListOrderItemsRequest();

            request.SellerId      = MERCHANT_ID;
            request.AmazonOrderId = order.AmazonOrderId;
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig
            {
                ServiceURL = "https://mws.amazonservices.es/Orders/2013-09-01"
            };
            MarketplaceWebServiceOrdersClient client = new MarketplaceWebServiceOrdersClient(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, "AppName", "0.0", config);
            bool retryRequest = true;

            while (retryRequest == true)
            {
                retryRequest = false;
                try
                {
                    //                   Debug.WriteLine(string.Format("{0} Leyendo Linea {1} de la pagina {2} ", DateTime.Now.ToString("f"),numero,pagina));
                    eventAntesLinea?.Invoke(new EventosAmazon {
                        pagina = pagina, linea = numero, retardo = 0
                    });
                    var a = client.ListOrderItems(request);
                    System.Threading.Thread.Sleep(2000);
                    //                   Debug.WriteLine(string.Format("{0} Linea Leida {1} de la pagina {2} ", DateTime.Now.ToString("f"), numero, pagina));
                    GrabarOrderItems(a.ListOrderItemsResult.OrderItems, order);
                    //                   eventDespuesLinea?.Invoke(new EventosAmazon { pagina = pagina, linea = numero, retardo = 0 });
                }
                catch (MarketplaceWebServiceOrdersException ex)
                {
                    if (ex.ErrorCode.Contains("RequestThrottled"))
                    {
                        int retardo = 60000;
                        retryRequest = true;
                        //                      Debug.WriteLine(string.Format("{0} Inicio Troleado {1} de la pagina {2} ", DateTime.Now.ToString("f"), numero, pagina));
                        eventAntesRetardoTroleoLinea?.Invoke(new EventosAmazon {
                            pagina = pagina, linea = numero, retardo = retardo
                        });
                        System.Threading.Thread.Sleep(retardo);
                        eventDespuesRetardoTroleoLinea?.Invoke(new EventosAmazon {
                            pagina = pagina, linea = numero, retardo = retardo
                        });
                        //                       Debug.WriteLine(string.Format("{0} Fin Troleado {1} de la pagina {2} ", DateTime.Now.ToString("f"), numero, pagina));
                    }
                    else
                    {
                        eventError?.Invoke(new EventosAmazon {
                            pagina = pagina, linea = numero, retardo = 0, error = ex.Detail
                        });
                    }
                }
            }
        }
예제 #13
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);
            }
        }
예제 #14
0
        /// <summary>
        /// Default public contructor. All properties are set via the config file
        /// </summary>
        public AmazonIntegration()
        {
            // Verify that the settings in the config file are setup correctly.
            if (string.IsNullOrWhiteSpace(_AccessKeyId))
            {
                throw new InvalidOperationException("AWSAccessKeyId setting in the config file can't be whitespace, blank or null");
            }
            if (string.IsNullOrWhiteSpace(_SecretAccessKey))
            {
                throw new InvalidOperationException("AWSSecretAccessKey setting in the config file can't be whitespace, blank or null");
            }
            if (string.IsNullOrWhiteSpace(_ApplicationName))
            {
                throw new InvalidOperationException("AWSApplicationName setting in the config file can't be whitespace, blank or null");
            }
            if (string.IsNullOrWhiteSpace(_ApplicationVersion))
            {
                throw new InvalidOperationException("AWSApplicationVersion setting in the config file can't be whitespace, blank or null");
            }
            if (string.IsNullOrWhiteSpace(_MerchantId))
            {
                throw new InvalidOperationException("AWSMerchantId setting in the config file can't be whitespace, blank or null");
            }
            if (string.IsNullOrWhiteSpace(_MarketplaceId))
            {
                throw new InvalidOperationException("AWSMarketplaceId setting in the config file can't be whitespace, blank or null");
            }
            if (string.IsNullOrWhiteSpace(_TemporaryFileDirectory))
            {
                throw new InvalidOperationException("TempFileDirectory setting in the config file can't be whitespace, blank or null");
            }

            var config = new MarketplaceWebServiceConfig();

            // Set configuration to use US marketplace
            config.ServiceURL = "https://mws.amazonservices.com";
            // Set the HTTP Header for user agent for the application.
            config.SetUserAgentHeader(
                _ApplicationName,
                _ApplicationVersion,
                "C#");
            _AmazonClient = new MarketplaceWebServiceClient(_AccessKeyId, _SecretAccessKey, config);

            // Setup the orders service client
            var ordersConfig = new MarketplaceWebServiceOrdersConfig();

            ordersConfig.ServiceURL = "https://mws.amazonservices.com/Orders/2011-01-01";
            ordersConfig.SetUserAgent(_ApplicationName, _ApplicationVersion);
            _AmazonOrdersClient = new MarketplaceWebServiceOrdersClient(
                _ApplicationName, _ApplicationVersion, _AccessKeyId, _SecretAccessKey, ordersConfig);
        }
예제 #15
0
        public static DataSet ListAmazonOrderLine(string amazonOrderid, string merchantId, string marketplaceId, string accessKeyId, string secretAccessKey)
        {
            DataSet               amazonOrderLineDs  = new DataSet();
            const string          applicationName    = "<Your Application Name>";
            const string          applicationVersion = "<Your Application Version>";
            ListOrderItemsRequest request            = new ListOrderItemsRequest();
            string sellerId = merchantId;

            request.SellerId      = sellerId;
            request.AmazonOrderId = amazonOrderid;
            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.ListOrderItems(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);
                amazonOrderLineDs.ReadXml(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\AmazonOrderLineList.xml", XmlReadMode.InferSchema);
                return(amazonOrderLineDs);
            }
            catch (MarketplaceWebServiceOrdersException ex)
            {
                // Exception properties are important for diagnostics.
                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);
                throw ex;
            }
        }
예제 #16
0
        private List <MarketplaceOrder> getMarketplaceOrdersData(List <string> orderIds)
        {
            // init the Amazon web service
            var config = new MarketplaceWebServiceOrdersConfig {
                ServiceURL = "https://mws.amazonservices.com"
            };

            config.SetUserAgent(_ApplicationName, _Version);
            _ordersClient = new MarketplaceWebServiceOrdersClient(_credential.AccessKeyId, _credential.SecretKey, config);
            var results = new List <MarketplaceOrder>();

            try
            {
                // create the request object
                var request = new GetOrderRequest
                {
                    AmazonOrderId = orderIds,
                    SellerId      = _credential.MerchantId
                };

                // send the request
                var orderResponse = _ordersClient.GetOrder(request);
                var ordersResult  = orderResponse.GetOrderResult.Orders;
                if (!ordersResult.Any())
                {
                    return(null);
                }

                foreach (var item in ordersResult)
                {
                    results.Add(convertOrderResponseToMarketplaceOrder(item));
                }

                return(results);
            }
            catch (Exception ex)
            {
                _logger.LogError(LogEntryType.AmazonOrdersProvider,
                                 string.Format("{0} - Error in getting latest order data for Order Id: {1}. Error Message: {2}", ChannelName, string.Join(",", orderIds), EisHelper.GetExceptionMessage(ex)),
                                 ex.StackTrace);
                return(null);
            }
        }
예제 #17
0
        public void ListOrders()
        {
            ame = new Amazon__Entity();
            aml = new Amazon__BL();

            ame = aml.MAPI_DRequest();
            //string SellerId = CommonValue.strMerchantId;
            //string MarketplaceId = CommonValue.strMarketplaceId;
            //string AccessKeyId = CommonValue.strAccessKeyId;
            //string SecretKeyId = CommonValue.strSecretKeyId;
            //string ApplicationVersion = CommonValue.strApplicationVersion;
            //string ApplicationName = CommonValue.strApplicationName;
            //string MWSAuthToken = CommonValue.strMWSAuthToken;
            //string strbuff = string.Empty;
            SellerId      = ame.strMerchantId;
            MarketplaceId = ame.strMarketplaceId;
            AccessKeyId   = ame.strAccessKeyId;
            MWSAuthToken  = ame.strMWSAuthToken;
            SecretKeyId   = ame.strSecretKeyId;
            APIKey        = ame.APIKey;
            StoreCD       = ame.StoreCD;
            string ApplicationVersion = CommonValue.strApplicationVersion;
            string ApplicationName    = CommonValue.strApplicationName;

            DataTable strbuff = new DataTable();

            var LastUpdatedBefore = aml.Amazon_DRequest();

            if (LastUpdatedBefore != null)
            {
                UpdatedTimeBefore = Convert.ToDateTime(LastUpdatedBefore).AddDays(-1);
            }
            else
            {
                UpdatedTimeBefore = DateTime.Now;;
            }
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig();

            config.ServiceURL = CommonValue.strServiceURL;
            MarketplaceWebServiceOrders.MarketplaceWebServiceOrders client = new MarketplaceWebServiceOrdersClient(
                AccessKeyId,
                SecretKeyId,
                ApplicationName,
                ApplicationVersion,
                config);
            ListOrdersRequest request = new ListOrdersRequest();

            request.SellerId         = SellerId;
            request.LastUpdatedAfter = UpdatedTimeBefore;

            List <string> lstMarketplace = new List <string>();

            lstMarketplace.Add(MarketplaceId);
            request.MarketplaceId     = lstMarketplace;
            request.MWSAuthToken      = MWSAuthToken;
            request.MaxResultsPerPage = 40;
            ListOrdersResponse response         = client.ListOrders(request);
            ListOrdersResult   listOrdersResult = new ListOrdersResult();

            if (response.IsSetListOrdersResult())
            {
                listOrdersResult = response.ListOrdersResult;
                if (listOrdersResult.IsSetOrders())
                {
                    List <Order> orders = listOrdersResult.Orders;
                    strbuff.Columns.Add("StoreCD");
                    strbuff.Columns.Add("APIKey");
                    strbuff.Columns.Add("SEQ");
                    strbuff.Columns.Add("OrderId");
                    int i = 0;
                    Amazon_Juchuu = D_AmazonJuchuu();
                    foreach (Order o in orders)
                    {
                        i++;
                        strbuff.Rows.Add(StoreCD, APIKey, i, o.AmazonOrderId);
                        GetListOrderdata(o, i);
                    }
                }
                // txtListOrders.Text = strbuff;
            }
            Base_BL bbl = new Base_BL();
            string  OrderDetails = ""; string AmazonOrderId = "";

            OrderDetails  = bbl.DataTableToXml(Amazon_Juchuu);
            AmazonOrderId = bbl.DataTableToXml(strbuff);
            TokenNo       = TokenNo + 1;
            Insert_FirstToken(listOrdersResult, OrderDetails, AmazonOrderId);

            if (listOrdersResult.NextToken != null)
            {
                Insert_NextToken(response.ListOrdersResult.NextToken);
            }

            Insert_Items(client);

            Console.Read();


            //
            //else
            //{
            //    Console.Write("Order Inserted Successfully!!!");
            //    Console.Read();
            //}
        }
예제 #18
0
        // GET: Amazon
        public ActionResult Index()
        {
            // Developer AWS access key
            string accessKey = "AKIAJO3IC7VKEKZOPUZQ";

            // Developer AWS secret key
            string secretKey = "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";

            // The client application name
            string appName = "CSharpSampleCode";

            // The client application version
            string appVersion = "1.0";

            // The endpoint for region service and version (see developer guide)
            // ex: https://mws.amazonservices.com
            string serviceURL = "https://mws-eu.amazonservices.com";

            // Create a configuration object
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig();

            config.ServiceURL = serviceURL;
            // Set other client connection configurations here if needed
            // Create the client itself
            MarketplaceWebServiceOrdersClient client = new MarketplaceWebServiceOrdersClient(accessKey, secretKey, appName, appVersion, config);

            MarketplaceWebServiceOrdersSample sample = new MarketplaceWebServiceOrdersSample(client);

            // Uncomment the operation you'd like to test here
            // TODO: Modify the request created in the Invoke method to be valid

            try
            {
                IMWSResponse response = null;
                // response = sample.InvokeGetOrder();
                // response = sample.InvokeGetServiceStatus();
                // response = sample.InvokeListOrderItems();
                // response = sample.InvokeListOrderItemsByNextToken();
                response = sample.InvokeListOrders();
                // response = sample.InvokeListOrdersByNextToken();
                Console.WriteLine("Response:");
                ResponseHeaderMetadata rhmd = response.ResponseHeaderMetadata;
                // We recommend logging the request id and timestamp of every call.
                Console.WriteLine("RequestId: " + rhmd.RequestId);
                Console.WriteLine("Timestamp: " + rhmd.Timestamp);
                string responseXml = response.ToXML();
                Console.WriteLine(responseXml);
            }
            catch (MarketplaceWebServiceOrdersException ex)
            {
                // Exception properties are important for diagnostics.
                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);
                throw ex;
            }

            return(View());
        }
예제 #19
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)
            //{

            //}
        }
예제 #20
0
        public IEnumerable <MarketplaceOrder> GetMarketplaceOrders(DateTime createdAfter)
        {
            var marketplaceOrders = new List <MarketplaceOrder>();

            try
            {
                // init the Amazon web service
                var config = new MarketplaceWebServiceOrdersConfig {
                    ServiceURL = "https://mws.amazonservices.com"
                };
                config.SetUserAgent(_ApplicationName, _Version);
                _ordersClient = new MarketplaceWebServiceOrdersClient(_credential.AccessKeyId, _credential.SecretKey, config);

                Console.WriteLine("{0} fetching orders for {1}...", ChannelName, createdAfter);

                // create ListOrdersRequest object
                var listOrdersRequest = new ListOrdersRequest
                {
                    SellerId      = _credential.MerchantId,
                    MarketplaceId = new List <string> {
                        { _credential.MarketplaceId }
                    },
                    LastUpdatedAfter = createdAfter.Date
                };
                var listOrdersResponse = _ordersClient.ListOrders(listOrdersRequest);
                var ordersResult       = listOrdersResponse.ListOrdersResult.Orders;
                var nextToken          = listOrdersResponse.ListOrdersResult.NextToken;
                ListOrdersByNextTokenResponse nextOrderResponse = null;

                Console.WriteLine("{0} retrieved {1} orders and {2} next results page.", ChannelName, listOrdersResponse.ListOrdersResult.Orders.Count, !string.IsNullOrWhiteSpace(nextToken) ? "HAS" : "NO");

                do
                {
                    if (nextOrderResponse != null)
                    {
                        ordersResult = nextOrderResponse.ListOrdersByNextTokenResult.Orders;
                        nextToken    = nextOrderResponse.ListOrdersByNextTokenResult.NextToken;
                        Console.WriteLine("{0} retrieved {1} next orders and {2} next results page.", ChannelName, ordersResult.Count, !string.IsNullOrWhiteSpace(nextToken) ? "HAS" : "NO");
                    }

                    // Convert the orders to the marketplace contracts and get the items.
                    for (int i = 0; i < ordersResult.Count; ++i)
                    {
                        // The maximum request quota for ListOrderItems is 30 after that it restores at 2 per second.
                        // So if the order's that are being pulled exceed 30, then sleep for 2 seconds each one.
                        if (i > 30)
                        {
                            Thread.Sleep(2000);
                        }

                        marketplaceOrders.Add(convertOrderResponseToMarketplaceOrder(ordersResult[i]));
                    }

                    // do a rquest for the next page result of orders if next token is not null
                    if (!string.IsNullOrWhiteSpace(nextToken))
                    {
                        // pause at least 1 minute, this is the restore rate for ListOrdersByNextToken for every 6 quota
                        Thread.Sleep(61000);

                        var nextTokenRequest = new ListOrdersByNextTokenRequest {
                            SellerId = _credential.MerchantId, NextToken = nextToken
                        };
                        nextOrderResponse = _ordersClient.ListOrdersByNextToken(nextTokenRequest);
                    }
                } while (!string.IsNullOrWhiteSpace(nextToken));

                Console.WriteLine("{0} done fetching orders: {1} items", ChannelName, marketplaceOrders.Count);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error in getting orders for {0}! Error message: {1}", ChannelName, ex.Message);
                _logger.LogError(LogEntryType.AmazonOrdersProvider,
                                 string.Format("Error in retrieving orders for Amazon. Error message: {0}", ex.Message),
                                 ex.StackTrace);

                _emailService.SendEmailAdminException(subject: "Amazon - Get Marketplace Orders Error",
                                                      exParam: ex,
                                                      useDefaultTemplate: true,
                                                      url: "GetMarketplaceOrders Method",
                                                      userName: "******");
            }

            return(marketplaceOrders);
        }
예제 #21
0
        public JsonResult CreateOrder()
        {
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig();

            config.ServiceURL = CommonValue.strServiceURL;


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

            ListOrdersRequest _req           = new ListOrdersRequest();
            List <string>     _marketPlaceId = new List <string>();

            _marketPlaceId.Add(MarketplaceId);
            _req.MarketplaceId = _marketPlaceId;
            _req.CreatedAfter  = DateTime.Now.AddDays(-1);
            //_req.CreatedBefore = Convert.ToDateTime("2017-01-01");
            //_req.CreatedAfter = Convert.ToDateTime("2017-01-01");
            _req.SellerId     = SellerId;
            _req.MWSAuthToken = MWSAuthToken;

            ListOrdersResponse listorders = client.ListOrders(_req);

            ProductWarehouseInventory product;
            bool shippingRequired        = false;
            var  _objAmazonOrderResponse = AmazonOrderResponse();
            List <AmazonOrderItemModel> _objAmazonOrderItem = new List <AmazonOrderItemModel>();
            ListOrderItemsResponse      _objOrderitem       = new ListOrderItemsResponse();

            foreach (var item in _objAmazonOrderResponse.ListOrdersResult.Orders)
            {
                _objOrderitem = AmazonOrderItemResponse(item.AmazonOrderId);
                var orderitem = _objOrderitem.ListOrderItemsResult.OrderItems;

                foreach (var _orderitem in orderitem)
                {
                    AmazonOrderItemModel _objSku = new AmazonOrderItemModel();
                    _objSku.AmazonSKU = _orderitem.SellerSKU;
                    _objAmazonOrderItem.Add(_objSku);
                }
            }



            Customer customer = _customerService.GetCustomerByEmail("*****@*****.**");

            AddOrderItemsToCart(_objAmazonOrderItem, customer, 1);



            if (customer == null)
            {
                ErrorNotification("Customer Not Found Order Api");
            }
            OrderModel model = new OrderModel();



            //if (shippingRequired)
            //{
            //    bool isValid = true;

            //    isValid &= SetShippingOption(orderDelta.Dto.ShippingRateComputationMethodSystemName,
            //                                orderDelta.Dto.ShippingMethod,
            //                                orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id,
            //                                customer,
            //                                BuildShoppingCartItemsFromOrderItemDtos(orderDelta.Dto.OrderItemDtos.ToList(),
            //                                                                        customer.Id,
            //                                                                        orderDelta.Dto.StoreId ?? _storeContext.CurrentStore.Id));

            //    isValid &= ValidateAddress(orderDelta.Dto.ShippingAddress, "shipping_address");

            //    if (!isValid)
            //    {
            //        return Error(HttpStatusCode.BadRequest);
            //    }
            //}

            //if (!OrderSettings.DisableBillingAddressCheckoutStep)
            //{
            //    bool isValid = ValidateAddress(orderDelta.Dto.BillingAddress, "billing_address");

            //    if (!isValid)
            //    {
            //        return Error(HttpStatusCode.BadRequest);
            //    }
            //}

            //   Order newOrder = _factory.Initialize();
            //  orderDelta.Merge(newOrder);
            ////  Order newOrder = new Order();
            //// _orderService.InsertOrder(newOrder);
            ////  customer.BillingAddress = newOrder.BillingAddress;
            ////  customer.ShippingAddress = newOrder.ShippingAddress;
            ////  // If the customer has something in the cart it will be added too. Should we clear the cart first?
            //////  newOrder.Customer = customer;

            ////  // The default value will be the currentStore.id, but if it isn't passed in the json we need to set it by hand.
            ////  if (!orderDelta.Dto.StoreId.HasValue)
            ////  {
            ////      newOrder.StoreId = _storeContext.CurrentStore.Id;
            ////  }

            //  PlaceOrderResult placeOrderResult = PlaceOrder(newOrder, customer);

            //if (!placeOrderResult.Success)
            //{
            //    foreach (var error in placeOrderResult.Errors)
            //    {
            //        ModelState.AddModelError("order placement", error);
            //    }

            //    return Error(HttpStatusCode.BadRequest);
            //}

            //ICustomerActivityService.InsertActivity("AddNewOrder",
            //     _localizationService.GetResource("ActivityLog.AddNewOrder"), newOrder.Id);

            //var ordersRootObject = new OrdersRootObject();

            //OrderDto placedOrderDto = placeOrderResult.PlacedOrder.ToDto();

            //ordersRootObject.Orders.Add(placedOrderDto);

            //var json = _jsonFieldsSerializer.Serialize(newOrder, string.Empty);

            return(Json("result"));
        }
예제 #22
0
        public static void Main(string[] args)
        {
            // TODO: Set the below configuration variables before attempting to run

            // Developer AWS access key
            var accessKey = "replaceWithAccessKey";

            // Developer AWS secret key
            var secretKey = "replaceWithSecretKey";

            // The client application name
            var appName = "CSharpSampleCode";

            // The client application version
            var appVersion = "1.0";

            // The endpoint for region service and version (see developer guide)
            // ex: https://mws.amazonservices.com
            var serviceURL = "replaceWithServiceURL";

            // Create a configuration object
            var config = new MarketplaceWebServiceOrdersConfig();

            config.ServiceURL = serviceURL;

            // Set other client connection configurations here if needed
            // Create the client itself
            IMarketplaceWebServiceOrders client = new MarketplaceWebServiceOrdersClient(accessKey, secretKey, appName, appVersion, config);

            var sample = new Program(client);

            // Uncomment the operation you'd like to test here
            // TODO: Modify the request created in the Invoke method to be valid

            try
            {
                IMWSResponse response = null;

                // response = sample.InvokeGetOrder();
                // response = sample.InvokeGetServiceStatus();
                // response = sample.InvokeListOrderItems();
                // response = sample.InvokeListOrderItemsByNextToken();
                // response = sample.InvokeListOrders();
                // response = sample.InvokeListOrdersByNextToken();
                Console.WriteLine("Response:");
                var rhmd = response.ResponseHeaderMetadata;

                // We recommend logging the request id and timestamp of every call.
                Console.WriteLine("RequestId: " + rhmd.RequestId);
                Console.WriteLine("Timestamp: " + rhmd.Timestamp);
                var responseXml = response.ToXML();
                Console.WriteLine(responseXml);
            }
            catch (MarketplaceWebServiceOrdersException ex)
            {
                // Exception properties are important for diagnostics.
                var 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);
                throw ex;
            }
        }
예제 #23
0
        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);
            }
        }
예제 #24
0
        public void Insert_NextToken(string token = null)
        {
            Amazon_Juchuu_NextToken = D_AmazonJuchuu();
            Base_BL   bbl     = new Base_BL();
            DataTable strbuff = new DataTable();

            strbuff.Columns.Add("StoreCD");
            strbuff.Columns.Add("APIKey");
            strbuff.Columns.Add("SEQ");
            strbuff.Columns.Add("OrderId");
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig();

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

            if (token != null)
            {
                ListOrdersByNextTokenRequest request1 = new ListOrdersByNextTokenRequest();
                ListOrdersByNextTokenResult  listOrdersByNextResult = new ListOrdersByNextTokenResult();
                request1.SellerId     = SellerId;
                request1.MWSAuthToken = MWSAuthToken;
                request1.NextToken    = token;
                ListOrdersByNextTokenResponse response1 = client.ListOrdersByNextToken(request1);
                if (response1.IsSetListOrdersByNextTokenResult())
                {
                    listOrdersByNextResult = response1.ListOrdersByNextTokenResult;
                    if (listOrdersByNextResult.IsSetOrders())
                    {
                        List <Order> orders = listOrdersByNextResult.Orders;
                        int          i      = 0;
                        foreach (Order o in orders)
                        {
                            i++;
                            strbuff.Rows.Add(StoreCD, APIKey, i, o.AmazonOrderId);
                            GetListOrderdata(o, i, false);
                        }
                    }
                }
                Amazon__Entity ameDetails = new Amazon__Entity();
                ameDetails.StoreCD           = StoreCD;
                ameDetails.APIKey            = APIKey;
                ameDetails.LastUpdatedAfter  = UpdatedTimeBefore.ToString();
                ameDetails.LastUpdatedBefore = listOrdersByNextResult.LastUpdatedBefore.ToString();
                ameDetails.Xmldetails        = bbl.DataTableToXml(Amazon_Juchuu_NextToken);
                ameDetails.XmlOrder          = bbl.DataTableToXml(strbuff);

                TokenNo = TokenNo + 1;
                if (aml.AmazonAPI_Insert_NextToken(ameDetails))
                {
                    Console.WriteLine("Successfully Inserted Token " + (TokenNo).ToString() + "Times");
                }
                else
                {
                    Console.WriteLine("Unfortunately Inserted Failed Token " + (TokenNo).ToString() + "Times");
                }
                Insert_NextToken(listOrdersByNextResult.NextToken);
            }
            else/// To be Continued. . . Insert
            {
                Console.Write("Order inserted Successfully!!!");
                Console.Read();
            }
        }
예제 #25
0
        public void LeerPedidos(DateTime FechInicial, string cuenta, string OrderStatus)
        {
            int pagina = 1;

            this.Cuenta = cuenta;
            ListOrdersRequest request = new ListOrdersRequest();

            request.SellerId = MERCHANT_ID;

            string      format       = "MMM d, yyyy h:mm:ss tt PDT";
            CultureInfo provider     = CultureInfo.InvariantCulture;
            DateTime    now          = DateTime.Now.Add(new TimeSpan(0, -10, 0));
            DateTime    createdAfter = DateTime.ParseExact("Aug 10, 2017 2:42:18 PM PDT", format, provider);

            request.CreatedAfter  = createdAfter;
            request.CreatedBefore = now;


            List <string> orderStatus = new List <string>();

            orderStatus.Add(OrderStatus);
            request.OrderStatus = orderStatus;


            List <string> marketplaceId = new List <string>();

            marketplaceId.Add(MARKETPLACE_ID);
            request.MarketplaceId = marketplaceId;

            //List<string> fulfillmentChannel = new List<string>();
            //request.FulfillmentChannel = fulfillmentChannel;
            //List<string> paymentMethod = new List<string>();
            //request.PaymentMethod = paymentMethod;
            //string buyerEmail = "example";
            //request.BuyerEmail = buyerEmail;
            //string sellerOrderId = "example";
            //request.SellerOrderId = sellerOrderId;
            //decimal maxResultsPerPage = 1;
            //request.MaxResultsPerPage = maxResultsPerPage;
            //List<string> tfmShipmentStatus = new List<string>();
            //request.TFMShipmentStatus = tfmShipmentStatus;
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig
            {
                ServiceURL = "https://mws.amazonservices.es/Orders/2013-09-01"
            };
            MarketplaceWebServiceOrdersClient client = new MarketplaceWebServiceOrdersClient(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, "AppName", "0.0", config);
            ListOrdersResponse a = new ListOrdersResponse();
            bool retryRequest    = true;

            while (retryRequest == true)
            {
                retryRequest = false;
                try
                {
                    eventAntesPagina(new EventosAmazon {
                        pagina = pagina, linea = 0, retardo = 0
                    });
                    a = client.ListOrders(request);
                    eventDespuesPagina(new EventosAmazon {
                        pagina = pagina, linea = 0, retardo = 0
                    });
                }
                catch (MarketplaceWebServiceOrdersException ex)
                {
                    if (ex.ErrorCode.Contains("RequestThrottled"))
                    {
                        int retardo = 60000;
                        retryRequest = true;
                        eventAntesRetardoTroleo(new EventosAmazon {
                            pagina = pagina, linea = 0, retardo = retardo
                        });
                        System.Threading.Thread.Sleep(retardo);
                        eventDespuesRetardoTroleo?.Invoke(new EventosAmazon {
                            pagina = pagina, linea = 0, retardo = retardo
                        });
                    }
                    else
                    {
                        eventError?.Invoke(new EventosAmazon {
                            pagina = pagina, linea = 0, retardo = 0, error = ex.Detail
                        });
                    }
                }
            }


            //            foreach (Order order in a.ListOrdersResult.Orders)
            //                GrabarOrder(order, cuenta);
            Task t = new Task(
                () =>
            {
                Parallel.ForEach(a.ListOrdersResult.Orders, new ParallelOptions {
                    MaxDegreeOfParallelism = 2
                },
                                 order =>
                {
                    int numero = a.ListOrdersResult.Orders.IndexOf(order);
                    LeerLineasPedido(order, pagina, numero);
                    GrabarOrder(order, cuenta);
                });
            });

            t.Start();
            while (!t.IsCompleted)
            {
                Application.DoEvents();
            }
            string NextToken = a.ListOrdersResult.NextToken;

//            return;
            while (!string.IsNullOrEmpty(NextToken))
            {
                pagina++;
                ListOrdersByNextTokenRequest nextRequest = new ListOrdersByNextTokenRequest();
                nextRequest.NextToken = NextToken;
                nextRequest.SellerId  = request.SellerId;
                retryRequest          = true;
                ListOrdersByNextTokenResponse b = new ListOrdersByNextTokenResponse();
                while (retryRequest == true)
                {
                    retryRequest = false;
                    try
                    {
                        eventAntesPagina(new EventosAmazon {
                            pagina = pagina, linea = 0, retardo = 0
                        });
                        b = client.ListOrdersByNextToken(nextRequest);
                        eventDespuesPagina(new EventosAmazon {
                            pagina = pagina, linea = 0, retardo = 0
                        });
                        Task tn = new Task(
                            () =>
                        {
                            Parallel.ForEach(b.ListOrdersByNextTokenResult.Orders, new ParallelOptions {
                                MaxDegreeOfParallelism = 2
                            }, order =>
                            {
                                int numero = b.ListOrdersByNextTokenResult.Orders.IndexOf(order);
                                LeerLineasPedido(order, pagina, numero);
                                GrabarOrder(order, cuenta);
                            });
                        });
                        tn.Start();
                        while (!tn.IsCompleted)
                        {
                            Application.DoEvents();
                        }
                    }
                    catch (MarketplaceWebServiceOrdersException ex)
                    {
                        //The ListOrders and ListOrdersByNextToken operations together share a maximum request quota of six and a restore rate of one request every minute.
                        //                  Request quota
                        //                          The number of requests that you can submit at one time without throttling.The request quota decreases with every request you submit.The request quota increases at the restore rate.
                        //                  Restore rate
                        //                          The rate at which your request quota increases over time, up to the maximum request quota.
                        //                  Maximum request quota
                        //                          The maximum size that the request quota can reach.
                        if (ex.ErrorCode.Contains("RequestThrottled"))
                        {
                            int retardo = 60000;
                            retryRequest = true;
                            eventAntesRetardoTroleo(new EventosAmazon {
                                pagina = pagina, linea = 0, retardo = retardo
                            });
                            System.Threading.Thread.Sleep(retardo);
                            eventDespuesRetardoTroleo?.Invoke(new EventosAmazon {
                                pagina = pagina, linea = 0, retardo = retardo
                            });
                        }
                    }
                    if (b.IsSetListOrdersByNextTokenResult())
                    {
                        NextToken = b.ListOrdersByNextTokenResult.NextToken;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
예제 #26
0
        public static void Main(string[] args)
        {
            // The client application name
            const string appName = "OrderHistoryApp";

            // The client application version
            const string appVersion = "1.0";

            // The endpoint for region service and version (see developer guide)
            // ex: https://mws.amazonservices.com
            const string serviceUrl = "https://mws.amazonservices.com/Orders/2011-01-01";

            // Create a configuration object
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig {
                ServiceURL = serviceUrl
            };

            // Set other client connection configurations here if needed
            // Create the client itself
            MarketplaceWebServiceOrders.MarketplaceWebServiceOrders client = new MarketplaceWebServiceOrdersClient(AccessKey, SecretKey, appName, appVersion, config);

            OrdersMonitorApp ordersMonitorApp = new OrdersMonitorApp(client);

            try
            {
                // response = sample.InvokeGetOrder();
                // response = sample.InvokeGetServiceStatus();
                // response = sample.InvokeListOrderItems();
                // response = sample.InvokeListOrderItemsByNextToken();

                DateTime updatedAfterDefault  = new DateTime(2014, 7, 20);
                DateTime updatedBeforeDefault = DateTime.Now.AddMinutes(-5);

                using (var db = new OrderContext())
                {
                    // is this the first time ?
                    var query = from o in db.Orders orderby o.LastUpdateDate descending select o;

                    if (query.Any())
                    {
                        Console.WriteLine("Results exist in database: " + query.Count());

                        // although we are using a nullable type, there is no way that we will get a record that has a
                        // null PurchaseDate. So we are safe here.
                        DateTime?tempDate   = query.First().LastUpdateDate;
                        DateTime lastUpdate = DateTimeBegin;  // silly assignment so we cover the else case.
                        if (tempDate != null)
                        {
                            lastUpdate = (DateTime)tempDate;
                        }

                        Console.WriteLine("Last update date is : " + lastUpdate);

                        GetOrdersForTimeWindow(ordersMonitorApp, lastUpdate, updatedBeforeDefault);
                    }
                    else
                    {
                        Console.WriteLine("No results exist. Fresh Database.");

                        // get orders for the time window and save to the database
                        GetOrdersForTimeWindow(ordersMonitorApp, updatedAfterDefault, updatedBeforeDefault);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
예제 #27
0
        /**
         * Samples for Marketplace Web Service Orders functionality
         */
        public static void Main(string [] args)
        {
            Console.WriteLine("===========================================");
            Console.WriteLine("Welcome to Marketplace Web Service Orders Samples!");
            Console.WriteLine("===========================================");

            Console.WriteLine("To get started:");
            Console.WriteLine("===========================================");
            Console.WriteLine("  - Fill in your MWS credentials");
            Console.WriteLine("  - Uncomment sample you're interested in trying");
            Console.WriteLine("  - Set request with desired parameters");
            Console.WriteLine("  - Hit F5 to run!");
            Console.WriteLine();

            Console.WriteLine("===========================================");
            Console.WriteLine("Samples Output");
            Console.WriteLine("===========================================");
            Console.WriteLine();

            /************************************************************************
             * Access Key ID and Secret Access Key ID
             ***********************************************************************/
            String accessKeyId     = "<Your Access Key Id>";
            String secretAccessKey = "<Your Secret Access Key>";
            String merchantId      = "<Your Merchant Id>";
            String marketplaceId   = "<Your Marketplace Id>";

            /************************************************************************
             * The application name and version are included in each MWS call's
             * HTTP User-Agent field.
             ***********************************************************************/
            const string applicationName    = "<Your Application Name>";
            const string applicationVersion = "<Your Application Version>";

            /************************************************************************
             * Uncomment to try advanced configuration options. Available options are:
             *
             *  - Signature Version
             *  - Proxy Host and Proxy Port
             *  - Service URL
             *  - User Agent String to be sent to Marketplace Web Service Orders  service
             *
             ***********************************************************************/
            MarketplaceWebServiceOrdersConfig config = new MarketplaceWebServiceOrdersConfig();
            //
            // IMPORTANT: Uncomment out the appropriate line for the country you wish
            // to sell in:
            //
            // United States:
            // config.ServiceURL = "https://mws.amazonservices.com/Orders/2011-01-01";
            //
            // Canada:
            // config.ServiceURL = "https://mws.amazonservices.ca/Orders/2011-01-01";
            //
            // Europe:
            // config.ServiceURL = "https://mws-eu.amazonservices.com/Orders/2011-01-01";
            //
            // Japan:
            // config.ServiceURL = "https://mws.amazonservices.jp/Orders/2011-01-01";
            //
            // China:
            // config.ServiceURL = "https://mws.amazonservices.com.cn/Orders/2011-01-01";
            //

            /************************************************************************
             * Instantiate  Implementation of Marketplace Web Service Orders
             ***********************************************************************/
            MarketplaceWebServiceOrdersClient service = new MarketplaceWebServiceOrdersClient(
                applicationName, applicationVersion, accessKeyId, secretAccessKey, config);

            /************************************************************************
             * Uncomment to try out Mock Service that simulates Marketplace Web Service Orders
             * responses without calling Marketplace Web Service Orders  service.
             *
             * Responses are loaded from local XML files. You can tweak XML files to
             * experiment with various outputs during development
             *
             * XML files available under MarketplaceWebServiceOrders\Mock tree
             *
             ***********************************************************************/
            // MarketplaceWebServiceOrders service = new MarketplaceWebServiceOrdersMock();


            /************************************************************************
             * Uncomment to invoke List Orders By Next Token Action
             ***********************************************************************/
            // ListOrdersByNextTokenRequest request = new ListOrdersByNextTokenRequest();
            // @TODO: set request parameters here
            // request.SellerId = merchantId;

            // ListOrdersByNextTokenSample.InvokeListOrdersByNextToken(service, request);

            /************************************************************************
             * Uncomment to invoke List Order Items By Next Token Action
             ***********************************************************************/
            // ListOrderItemsByNextTokenRequest request = new ListOrderItemsByNextTokenRequest();
            // @TODO: set request parameters here
            // request.SellerId = merchantId;

            // ListOrderItemsByNextTokenSample.InvokeListOrderItemsByNextToken(service, request);

            /************************************************************************
             * Uncomment to invoke Get Order Action
             ***********************************************************************/
            // GetOrderRequest request = new GetOrderRequest();
            // @TODO: set request parameters here
            // request.SellerId = merchantId;

            // GetOrderSample.InvokeGetOrder(service, request);

            /************************************************************************
             * Uncomment to invoke List Order Items Action
             ***********************************************************************/
            // ListOrderItemsRequest request = new ListOrderItemsRequest();
            // @TODO: set request parameters here
            // request.SellerId = merchantId;

            // ListOrderItemsSample.InvokeListOrderItems(service, request);

            /************************************************************************
             * Uncomment to invoke List Orders Action
             ***********************************************************************/
            // ListOrdersRequest request = new ListOrdersRequest();
            // @TODO: set request parameters here
            // request.SellerId = merchantId;

            // ListOrdersSample.InvokeListOrders(service, request);

            /************************************************************************
             * Uncomment to invoke Get Service Status Action
             ***********************************************************************/
            // GetServiceStatusRequest request = new GetServiceStatusRequest();
            // @TODO: set request parameters here
            // request.SellerId = merchantId;

            // GetServiceStatusSample.InvokeGetServiceStatus(service, request);

            /************************************************************************
             * Uncomment to invoke OrderFetcher Sample
             ***********************************************************************/
            // OrderFetcherSample.InvokeOrderFetcherSample(service, merchantId, new string [] { marketplaceId } );

            /************************************************************************
             * Uncomment to invoke FetchNewOrdersJob Sample
             ***********************************************************************/
            // FetchNewOrdersJob.InvokeOrderFetcherSample(service, merchantId, new string[] { marketplaceId });

            Console.WriteLine();
            Console.WriteLine("===========================================");
            Console.WriteLine("End of output. You can close this window");
            Console.WriteLine("===========================================");

            System.Threading.Thread.Sleep(50000);
        }