Exemplo n.º 1
0
        private ListOrdersResponse InvokeListOrders(PXGraph graph, ServiceCallParameters objParams)
        {
            ListOrdersResponse response = new ListOrdersResponse();

            try
            {
                ListOrdersRequest request = new ListOrdersRequest();
                request.SellerId     = objParams.objSOAmazonSetup.SellerId;
                request.MWSAuthToken = objParams.objSOAmazonSetup.AuthToken;
                List <string> marketplaceId = new List <string>();
                marketplaceId.Add(objParams.objSOAmazonSetup.MarketplaceId);
                request.MarketplaceId = marketplaceId;
                request.CreatedAfter  = Convert.ToDateTime(objParams.fromDate);
                if (objParams.toDate.Value.Date < DateTime.Now.Date)
                {
                    request.CreatedBefore = objParams.toDate.Value.AddDays(1).AddTicks(-1);
                }
                PXTrace.WriteInformation("objParams.fromDate.Value.Date:" + objParams.fromDate.Value.Date.ToString());
                PXTrace.WriteInformation("objParams.toDate.Value.Date:" + objParams.toDate.Value.Date.ToString());
                PXTrace.WriteInformation("request.CreatedAfter:" + request.CreatedAfter.ToString());
                PXTrace.WriteInformation("request.CreatedBefore:" + request.CreatedBefore.ToString());
                List <string> liFulfillmentChannel = null;
                List <string> liOrderStatus        = null;
                SOHelper.GetFilterValues(objParams.objSOAmazonSetup.IntegrationType.Trim(), out liFulfillmentChannel, out liOrderStatus);
                request.FulfillmentChannel = liFulfillmentChannel;
                request.OrderStatus        = liOrderStatus;
                response = this.clientOrder.ListOrders(request);
            }
            catch (Exception ex)
            {
                if (ex is MarketplaceWebServiceOrdersException)
                {
                    MarketplaceWebServiceOrdersException exception = ex as MarketplaceWebServiceOrdersException;
                    if (!string.IsNullOrEmpty(exception.ErrorCode) && exception.ErrorCode.ToLower().Trim() == SOMessages.requestThrottled)
                    {
                        Thread.Sleep(SOHelper.DelayProcess(graph, SOConstants.apiListOrders));
                        response = InvokeListOrders(graph, objParams);
                    }
                    else
                    {
                        throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                              ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                           : SOConstants.exceptionIsEmpty);
                    }
                }
                else
                {
                    throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                          ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                            : SOConstants.exceptionIsEmpty);
                }
            }
            return(response);
        }
        private SubmitFeedResponse InvokeSubmitFeed(SubmitFeedParamaters objParams, string xmlFeedContent)
        {
            SubmitFeedResponse resSubmitFeed = new SubmitFeedResponse();

            try
            {
                UTF8Encoding      encoding   = new UTF8Encoding();
                Stream            streamData = new MemoryStream(encoding.GetBytes(xmlFeedContent));
                SubmitFeedRequest request    = new SubmitFeedRequest();
                request.Merchant             = objParams.objSOAmazonSetup.SellerId;
                request.FeedContent          = streamData;
                request.ContentMD5           = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent);
                request.FeedContent.Position = 0;
                request.PurgeAndReplace      = false;
                request.FeedType             = SOConstants.feedTypePostOrderFulfillment;
                request.MWSAuthToken         = objParams.objSOAmazonSetup.AuthToken;
                resSubmitFeed = clientFeed.SubmitFeed(request);
            }
            catch (Exception ex)
            {
                if (ex is MarketplaceWebServiceException)
                {
                    MarketplaceWebServiceException exception = ex as MarketplaceWebServiceException;
                    if (!string.IsNullOrEmpty(exception.ErrorCode) && exception.ErrorCode.ToLower().Trim() == SOMessages.requestThrottled)
                    {
                        Thread.Sleep(SOHelper.DelayProcess(objParams.objPartialMaint, SOConstants.apiSubmitFeed));
                        resSubmitFeed = InvokeSubmitFeed(objParams, xmlFeedContent);
                    }
                    else
                    {
                        throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                              ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                             : SOConstants.exceptionIsEmpty);
                    }
                }
                else
                {
                    throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                          ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                             : SOConstants.exceptionIsEmpty);
                }
            }
            return(resSubmitFeed);
        }
Exemplo n.º 3
0
        private GetOrderResponse InvokeGetOrder(PXGraph graph, ServiceCallParameters objParams)
        {
            GetOrderResponse getOrderRes = new GetOrderResponse();

            try
            {
                GetOrderRequest request = new GetOrderRequest();
                request.SellerId     = objParams.objSOAmazonSetup.SellerId;
                request.MWSAuthToken = objParams.objSOAmazonSetup.AuthToken;
                List <string> liAmazonOrderId = new List <string>();
                if (!string.IsNullOrEmpty(objParams.amwOrderID))
                {
                    liAmazonOrderId.Add(objParams.amwOrderID);
                }
                request.AmazonOrderId = liAmazonOrderId;
                getOrderRes           = this.clientOrder.GetOrder(request);
            }
            catch (Exception ex)
            {
                if (ex is MarketplaceWebServiceOrdersException)
                {
                    MarketplaceWebServiceOrdersException exception = ex as MarketplaceWebServiceOrdersException;
                    if (!string.IsNullOrEmpty(exception.ErrorCode) && exception.ErrorCode.ToLower().Trim() == SOMessages.requestThrottled)
                    {
                        Thread.Sleep(SOHelper.DelayProcess(graph, SOConstants.apiGetOrder));
                        getOrderRes = InvokeGetOrder(graph, objParams);
                    }
                    else
                    {
                        throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                              ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                            : SOConstants.exceptionIsEmpty);
                    }
                }
                else
                {
                    throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                          ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                           : SOConstants.exceptionIsEmpty);
                }
            }
            return(getOrderRes);
        }
Exemplo n.º 4
0
        private RequestReportResponse InvokeRequestReport(PXGraph graph, ReportParameters reportParams)
        {
            RequestReportResponse reqReportResponse = new RequestReportResponse();

            try
            {
                RequestReportRequest request          = new RequestReportRequest();
                DateTime?            businessDateTime = PX.Common.PXTimeZoneInfo.Now;
                request.Merchant     = reportParams.objSOAmazonSetup.SellerId;
                request.MWSAuthToken = reportParams.objSOAmazonSetup.AuthToken;
                request.ReportType   = SOConstants.amazonFulfilledShipmentData;
                request.StartDate    = Convert.ToDateTime(reportParams.fromDate);
                request.EndDate      = Convert.ToDateTime(reportParams.toDate).Date >= businessDateTime.Value.Date ? businessDateTime.Value.AddMinutes(-2) : Convert.ToDateTime(reportParams.toDate).AddDays(1);
                reqReportResponse    = clientReports.RequestReport(request);
            }
            catch (Exception ex)
            {
                if (ex is MarketplaceWebServiceException)
                {
                    MarketplaceWebServiceException exception = ex as MarketplaceWebServiceException;
                    if (!string.IsNullOrEmpty(exception.ErrorCode) && exception.ErrorCode.ToLower().Trim() == SOMessages.requestThrottled)
                    {
                        Thread.Sleep(SOHelper.DelayProcess(graph, SOConstants.apiRequestReport));
                        reqReportResponse = InvokeRequestReport(graph, reportParams);
                    }
                    else
                    {
                        throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                              ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                             : SOConstants.exceptionIsEmpty);
                    }
                }
                else
                {
                    throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                          ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                             : SOConstants.exceptionIsEmpty);
                }
            }
            return(reqReportResponse);
        }
Exemplo n.º 5
0
        private ListOrderItemsResponse GetSalesOrderLineItems(PXGraph graph, ServiceCallParameters objParams)
        {
            ListOrderItemsResponse lineItemsRes = new ListOrderItemsResponse();

            try
            {
                ListOrderItemsRequest request = new ListOrderItemsRequest();
                request.SellerId      = objParams.objSOAmazonSetup.SellerId;
                request.MWSAuthToken  = objParams.objSOAmazonSetup.AuthToken;
                request.AmazonOrderId = objParams.amwOrderID;
                lineItemsRes          = this.clientOrder.ListOrderItems(request);
            }
            catch (Exception ex)
            {
                if (ex is MarketplaceWebServiceOrdersException)
                {
                    MarketplaceWebServiceOrdersException exception = ex as MarketplaceWebServiceOrdersException;
                    if (!string.IsNullOrEmpty(exception.ErrorCode) && exception.ErrorCode.ToLower().Trim() == SOMessages.requestThrottled)
                    {
                        Thread.Sleep(SOHelper.DelayProcess(graph, SOConstants.apiGetListOrderItems));
                        lineItemsRes = GetSalesOrderLineItems(graph, objParams);
                    }
                    else
                    {
                        throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                              ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                            : SOConstants.exceptionIsEmpty);
                    }
                }
                else
                {
                    throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                          ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                            : SOConstants.exceptionIsEmpty);
                }
            }
            return(lineItemsRes);

            #endregion
        }
Exemplo n.º 6
0
        public ListOrdersByNextTokenResponse InvokeListOrdersByNextToken(PXGraph graph, ServiceCallParameters objParams)
        {
            ListOrdersByNextTokenRequest  request = new ListOrdersByNextTokenRequest();
            ListOrdersByNextTokenResponse responseOrderByNextToken = new ListOrdersByNextTokenResponse();

            try
            {
                request.SellerId         = objParams.objSOAmazonSetup.SellerId;
                request.MWSAuthToken     = objParams.objSOAmazonSetup.AuthToken;
                request.NextToken        = objParams.nextToken;
                responseOrderByNextToken = this.clientOrder.ListOrdersByNextToken(request);
            }
            catch (Exception ex)
            {
                if (ex is MarketplaceWebServiceOrdersException)
                {
                    MarketplaceWebServiceOrdersException exception = ex as MarketplaceWebServiceOrdersException;
                    if (!string.IsNullOrEmpty(exception.ErrorCode) && exception.ErrorCode.ToLower().Trim() == SOMessages.requestThrottled)
                    {
                        Thread.Sleep(SOHelper.DelayProcess(graph, SOConstants.apiListOrdersByNextToken));
                        responseOrderByNextToken = InvokeListOrdersByNextToken(graph, objParams);
                    }
                    else
                    {
                        throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                              ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                            : SOConstants.exceptionIsEmpty);
                    }
                }
                else
                {
                    throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                          ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                            : SOConstants.exceptionIsEmpty);
                }
            }
            return(responseOrderByNextToken);
        }
Exemplo n.º 7
0
 public void InvokeGetReport(PXGraph graph, ReportParameters reportParams, MemoryStream ms)
 {
     try
     {
         GetReportRequest request = new GetReportRequest();
         request.Merchant     = reportParams.objSOAmazonSetup.SellerId;
         request.MWSAuthToken = reportParams.objSOAmazonSetup.AuthToken;
         request.ReportId     = reportParams.generatedReportId;
         request.Report       = ms;
         clientReports.GetReport(request);
     }
     catch (Exception ex)
     {
         if (ex is MarketplaceWebServiceException)
         {
             MarketplaceWebServiceException exception = ex as MarketplaceWebServiceException;
             if (!string.IsNullOrEmpty(exception.ErrorCode) && exception.ErrorCode.ToLower().Trim() == SOMessages.requestThrottled)
             {
                 Thread.Sleep(SOHelper.DelayProcess(graph, SOConstants.apiGetReport));
                 InvokeGetReport(graph, reportParams, ms);
             }
             else
             {
                 throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                       ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                      : SOConstants.exceptionIsEmpty);
             }
         }
         else
         {
             throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                   ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                      : SOConstants.exceptionIsEmpty);
         }
     }
 }
 private void GetSubmitFeedResult(SubmitFeedParamaters objParams, string submissionFeedId, MemoryStream ms)
 {
     try
     {
         GetFeedSubmissionResultRequest request = new GetFeedSubmissionResultRequest();
         request.FeedSubmissionId     = submissionFeedId;
         request.Merchant             = objParams.objSOAmazonSetup.SellerId;
         request.MWSAuthToken         = objParams.objSOAmazonSetup.AuthToken;
         request.FeedSubmissionResult = ms;
         clientFeed.GetFeedSubmissionResult(request);
     }
     catch (Exception ex)
     {
         if (ex is MarketplaceWebServiceException)
         {
             MarketplaceWebServiceException exception = ex as MarketplaceWebServiceException;
             if (!string.IsNullOrEmpty(exception.ErrorCode) && exception.ErrorCode.ToLower().Trim() == SOConstants.feedProcessingResultNotReady)
             {
                 Thread.Sleep(SOHelper.DelayProcess(objParams.objPartialMaint, SOConstants.apiFeedResultWaiting));
                 GetSubmitFeedResult(objParams, submissionFeedId, ms);
             }
             else
             {
                 throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                       ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                     : SOConstants.exceptionIsEmpty);
             }
         }
         else
         {
             throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                   ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                     : SOConstants.exceptionIsEmpty);
         }
     }
 }
Exemplo n.º 9
0
        private ReportRequestInfo InvokeGetReportRequestList(PXGraph graph, ReportParameters reportParams)
        {
            GetReportRequestListResponse reqReportListResponse = new GetReportRequestListResponse();

            reportParams.reportInfo = new ReportRequestInfo();
            try
            {
                GetReportRequestListRequest request = new GetReportRequestListRequest();
                request.Merchant     = reportParams.objSOAmazonSetup.SellerId;
                request.MWSAuthToken = reportParams.objSOAmazonSetup.AuthToken;
                request.MaxCount     = 1;
                if (!string.IsNullOrEmpty(reportParams.reportRequestId))
                {
                    IdList liReportIds = new IdList();
                    liReportIds.Id.Add(reportParams.reportRequestId);
                    request.ReportRequestIdList = liReportIds;
                }
                TypeList liReportTypes = new TypeList();
                liReportTypes.Type.Add(SOConstants.amazonFulfilledShipmentData);
                request.ReportTypeList = liReportTypes;
                StatusList liReportStatus = new StatusList();
                liReportStatus.Status.Add(SOConstants.statusDone);
                request.ReportProcessingStatusList = liReportStatus;
                reqReportListResponse = clientReports.GetReportRequestList(request);

                if (reqReportListResponse != null && reqReportListResponse.GetReportRequestListResult != null && reqReportListResponse.GetReportRequestListResult.ReportRequestInfo != null && reqReportListResponse.GetReportRequestListResult.ReportRequestInfo.Count > 0)
                {
                    liReportRequestInfo = reqReportListResponse.GetReportRequestListResult.ReportRequestInfo;
                    foreach (ReportRequestInfo reportRequestInfoItem in liReportRequestInfo)
                    {
                        if (reportRequestInfoItem.GeneratedReportId == null && string.IsNullOrEmpty(reportRequestInfoItem.GeneratedReportId) && reportRequestInfoItem.ReportProcessingStatus == SOConstants.statusInProgress || reportRequestInfoItem.ReportProcessingStatus == SOConstants.statusSubmitted)
                        {
                            Thread.Sleep(SOHelper.DelayProcess(graph, SOConstants.getGeneratedReportID));
                            reportParams.reportInfo = InvokeGetReportRequestList(graph, reportParams);
                        }
                        else if (reportRequestInfoItem.GeneratedReportId != null && !string.IsNullOrEmpty(reportRequestInfoItem.GeneratedReportId) && reportRequestInfoItem.ReportProcessingStatus == SOConstants.statusDone)
                        {
                            reportParams.reportInfo = reportRequestInfoItem;
                            break;
                        }
                    }
                }
                else
                {
                    RequestAndGetReportData(graph, reportParams);
                }
            }
            catch (Exception ex)
            {
                if (ex is MarketplaceWebServiceException)
                {
                    MarketplaceWebServiceException exception = ex as MarketplaceWebServiceException;
                    if (!string.IsNullOrEmpty(exception.ErrorCode) && exception.ErrorCode.ToLower().Trim() == SOMessages.requestThrottled)
                    {
                        Thread.Sleep(SOHelper.DelayProcess(graph, SOConstants.apiGetRequestReportList));
                        reportParams.reportInfo = InvokeGetReportRequestList(graph, reportParams);
                    }
                    else
                    {
                        throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                              ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                             : SOConstants.exceptionIsEmpty);
                    }
                }
                else
                {
                    throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                          ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message
                             : SOConstants.exceptionIsEmpty);
                }
            }
            return(reportParams.reportInfo);
        }