Example #1
0
        public virtual InvokeReporstServicesCallResponse InvokeReportsServiceCalls(PXGraph graph, SOAmazonSetup objSOAmazonSetup, DateTime?fromDate, DateTime?toDate)
        {
            InvokeReporstServicesCallResponse objShipInfo = new InvokeReporstServicesCallResponse();

            MarketplaceWebService.MarketplaceWebService serviceConfig = this.Configurations(objSOAmazonSetup.IntegrationType.Trim(), objSOAmazonSetup.AccessKey, objSOAmazonSetup.SecretKey);
            if (serviceConfig == null)
            {
                return(objShipInfo);
            }
            ReportRequestInfo          reportInfo     = new ReportRequestInfo();
            List <ShipmentInformarion> liShipmentInfo = new List <ShipmentInformarion>();

            reportParams = new ReportParameters();
            reportParams.objSOAmazonSetup = objSOAmazonSetup;
            reportParams.reportRequestId  = string.Empty;
            reportParams.reportInfo       = reportInfo;
            reportParams.liShipmentInfo   = liShipmentInfo;
            reportParams.serviceConfig    = serviceConfig;
            reportInfo            = new AMShipmentTrackingNumberServiceCall(reportParams.serviceConfig).InvokeGetReportRequestList(graph, reportParams);
            reportParams.fromDate = fromDate;
            reportParams.toDate   = toDate;

            try
            {
                if (reportInfo != null && reportInfo.GeneratedReportId != null)
                {
                    if (Convert.ToInt32((TimeZoneInfo.ConvertTimeToUtc(DateTime.Now) - TimeZoneInfo.ConvertTimeToUtc(reportInfo.CompletedDate)).TotalMinutes) <= SOConstants.limitForReports)
                    {
                        throw new PXException(SOMessages.errorReportInfo);
                    }
                    else
                    {
                        liShipmentInfo = RequestAndGetReportData(graph, reportParams);
                    }
                    objShipInfo.objShipmentResponse = liShipmentInfo;
                }
                else
                {
                    liShipmentInfo = RequestAndGetReportData(graph, reportParams);
                }
            }
            catch (Exception ex)
            {
                throw new PXException(!string.IsNullOrEmpty(ex.Message) ? ex.Message :
                                      ex.InnerException != null && ex.InnerException.InnerException != null ? ex.InnerException.InnerException.Message : SOConstants.exceptionIsEmpty);
            }
            return(objShipInfo);
        }
        public ReportHandler(ServiceContext serviceContext, ILogger nLogger)
        {
            this.serviceContext = serviceContext;
            this.nLogger        = nLogger;


            config            = new MarketplaceWebServiceConfig();
            config.ServiceURL = serviceContext.MwsServiceUrl;

            service = new MarketplaceWebServiceClient(
                serviceContext.AccessKey,
                serviceContext.SecretKey,
                serviceContext.ApplicationName,
                serviceContext.AppVersion,
                config);
        }
Example #3
0
        /// <summary>
        /// The GetReport operation returns the contents of a report. Reports can potentially be
        /// very large (>100MB) which is why we only return one report at a time, and in a
        /// streaming fashion.
        ///
        /// </summary>
        /// <param name="service">Instance of MarketplaceWebService service</param>
        /// <param name="request">GetReportRequest request</param>
        private static void invokeGetReport(MarketplaceWebService.MarketplaceWebService service, GetReportRequest request)
        {
            try
            {
                Console.WriteLine("Downloading report...");

                GetReportResponse response = service.GetReport(request);

                Console.WriteLine("Downloaded!");
            }
            catch (MarketplaceWebServiceException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Please try again in a couple of minutes.");  //Exception might be because of Amazon's limit of downloading a report once a minute. Try in a couple of min.
            }
        }
        public AmazonEnvelope InvokeServicesCalls(SubmitFeedParamaters objParams, string xmlFeedContent)
        {
            AmazonEnvelope resultEnvelope = null;

            try
            {
                MarketplaceWebService.MarketplaceWebService serviceConfig = this.Configurations(objParams.objSOAmazonSetup.IntegrationType.Trim(), objParams.objSOAmazonSetup.AccessKey, objParams.objSOAmazonSetup.SecretKey);
                if (serviceConfig != null)
                {
                    SubmitFeedResponse feedresponse = null;
                    feedresponse = new AMSubmitFeedServiceCall(serviceConfig).InvokeSubmitFeed(objParams, xmlFeedContent);
                    if (feedresponse != null && feedresponse.SubmitFeedResult != null && feedresponse.SubmitFeedResult.FeedSubmissionInfo != null &&
                        !string.IsNullOrEmpty(feedresponse.SubmitFeedResult.FeedSubmissionInfo.FeedProcessingStatus) &&
                        feedresponse.SubmitFeedResult.FeedSubmissionInfo.FeedProcessingStatus.ToUpper().Trim('_') == SOConstants.Submitted)
                    {
                        string submissionFeedId = feedresponse.SubmitFeedResult.FeedSubmissionInfo.FeedSubmissionId;
                        using (MemoryStream ms = new MemoryStream())
                        {
                            new AMSubmitFeedServiceCall(serviceConfig).GetSubmitFeedResult(objParams, submissionFeedId, ms);
                            XmlDocument xDocument = new XmlDocument();
                            xDocument.Load(ms);
                            string        xmlResultContent = SOHelper.ObjectToXMLConversion(xDocument, string.Empty, true);
                            XmlSerializer deserializer     = new XmlSerializer(typeof(AmazonEnvelope), new XmlRootAttribute(SOConstants.amazonEnvelope));
                            using (TextReader reader = new StringReader(xmlResultContent))
                            {
                                resultEnvelope = (AmazonEnvelope)deserializer.Deserialize(reader);
                            }
                            return(resultEnvelope);
                        }
                    }
                }
                else
                {
                    throw new PXException(SOConstants.credentialsinvalid);
                }
            }
            catch (Exception ex)
            {
                throw new PXException(ex.Message);
            }
            return(resultEnvelope);
        }
        public FeedHandler(SellerInfo sellerInfo, ILogger nLogger)
        {
            this.sellerInfo = sellerInfo;
            this.nLogger    = nLogger;

            var            chain = new CredentialProfileStoreChain();
            AWSCredentials awsCredentials;

            chain.TryGetAWSCredentials("DD MWS", out awsCredentials);
            ImmutableCredentials creds = awsCredentials.GetCredentials();

            config            = new MarketplaceWebServiceConfig();
            config.ServiceURL = sellerInfo.MwsServiceUrl;

            service = new MarketplaceWebServiceClient(
                creds.AccessKey,
                creds.SecretKey,
                "RC",
                sellerInfo.AppVersion,
                config);
        }
        protected override void SetupAccountSettings()
        {
            base.SetupAccountSettings();

            string accessKey;
            string secretKey;
            string marketPlaceId;

            switch (Account)
            {
                case AccountEnum.AmzJk529:
                    accessKey = AccountSettingsConfigSection.Jk529_accessKey.Value;
                    secretKey = AccountSettingsConfigSection.Jk529_secretKey.Value;
                    _merchant = AccountSettingsConfigSection.Jk529_sellerId.Value;
                    marketPlaceId = AccountSettingsConfigSection.Jk529_marketplaceId.Value;
                    break;
                case AccountEnum.AmzRst:
                    accessKey = AccountSettingsConfigSection.Rst_accessKey.Value;
                    secretKey = AccountSettingsConfigSection.Rst_secretKey.Value;
                    _merchant = AccountSettingsConfigSection.Rst_sellerId.Value;
                    marketPlaceId = AccountSettingsConfigSection.Rst_marketplaceId.Value;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(Account.ToString());
            }

            _marketplaceWebService = new MarketplaceWebServiceClient(
                    accessKey,
                    secretKey,
                    AppName,
                    AppVersion,
                    new MarketplaceWebServiceConfig { ServiceURL = AmzServiceUrl });

            _requestReportRequest = new RequestReportRequest
            {
                Merchant = _merchant,
                ReportType = _reportTypeToGet,
                MarketplaceIdList = new IdList
                {
                    Id = new List<string>(new[] { marketPlaceId })
                }
            };
        }
Example #7
0
 public AMShipmentTrackingNumberServiceCall(MarketplaceWebService.MarketplaceWebService reports)
 {
     this.clientReports = reports;
 }
Example #8
0
        public static void DownloadSettlementReport(MarketplaceWebService.MarketplaceWebService service, string merchantId, bool getOnlyMostRecent = false)
        {
            GetReportListRequest request = new GetReportListRequest();

            request.Merchant = merchantId;

            TypeList reportTypes = new TypeList();

            reportTypes.Type = new List <string>()
            {
                "_GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2_"
            };

            request.ReportTypeList = reportTypes;

            List <Tuple <string, DateTime, DateTime> > settlemementReportsInfo = getReportsIds(service, request);

            if (settlemementReportsInfo.Count() == 0)
            {
                Console.WriteLine("No reports downloaded. Exiting.");
                return;
            }

            int selectedReport = 0;

            if (!getOnlyMostRecent)
            {
                Console.WriteLine("List of available reports:");
                for (int i = 0; i < 3; i++)
                {
                    int index = i + 1;
                    Console.WriteLine(index + ". " + settlemementReportsInfo[i].Item2.ToShortDateString() + " - " + settlemementReportsInfo[i].Item3.ToShortDateString());
                }

                Console.WriteLine("Select option:");
                char userInput = (char)Console.Read();
                Console.ReadLine();
                if (userInput == '1' || userInput == '2' || userInput == '3')
                {
                    switch (userInput)
                    {
                    case '2':
                        selectedReport = 1;
                        break;

                    case '3':
                        selectedReport = 2;
                        break;

                    case '1':
                    default:
                        selectedReport = 0;
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Invalid option detected. Selecting most recent report as default."); //At this point selectedReport = 0;
                }
            }

            string reportId = settlemementReportsInfo[selectedReport].Item1;

            #region Downloading report

            GetReportRequest requestReport = new GetReportRequest();
            requestReport.Merchant = merchantId;
            requestReport.ReportId = reportId;

            string amzSettlementReportPath = ConfigurationManager.AppSettings["Amz.SettlementReport.DownloadPath"];                                //File path directory. Example: "C:/"
            string amzSettlementReportFile = amzSettlementReportPath + "amzSettlementReport-" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + ".txt"; //NOTE: The invokeGetReport needs to get all the time a different file name to avoid having an MD5 error. (Problem found while developing. Solution found here: https://sellercentral.amazon.com/forums/thread.jspa?threadID=12563)

            requestReport.Report = File.Open(amzSettlementReportFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            invokeGetReport(service, requestReport); //Added timestamp to the report filename to avoid the MD5 problem from Amazon's side.

            Console.WriteLine("File was downloaded to: " + amzSettlementReportFile);

            #endregion
        }
Example #9
0
        /// <summary>
        /// Gets the last 3 settlement reports from Amazon API
        /// </summary>
        /// <param name="service"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        private static List <Tuple <string, DateTime, DateTime> > getReportsIds(MarketplaceWebService.MarketplaceWebService service, GetReportListRequest request)
        {
            List <Tuple <string, DateTime, DateTime> > reports = new List <Tuple <string, DateTime, DateTime> >(); //Includes the reportId, dateFrom and dateTo for a settlement report.

            if ((service == null) || (request == null))
            {
                return(reports);
            }

            try
            {
                List <string>   reportIds      = new List <string>();
                List <DateTime> availableDates = new List <DateTime>();

                GetReportListResponse response = service.GetReportList(request);

                if (response.IsSetGetReportListResult())
                {
                    GetReportListResult getReportListResult = response.GetReportListResult;
                    List <ReportInfo>   reportInfoList      = getReportListResult.ReportInfo;
                    foreach (ReportInfo reportInfo in reportInfoList)
                    {
                        reportIds.Add(reportInfo.ReportId);
                        availableDates.Add(reportInfo.AvailableDate);
                    }
                }

                if (availableDates.Count < 4)
                {
                    //We were not able to get the last 3 reports. We will try then to return the most recent one.
                    string   reportId = reportIds[0];
                    DateTime dateFrom = availableDates[1].AddDays(-1); //Settlement reports are available only until the next day of their period.
                    DateTime dateTo   = availableDates[0].AddDays(-1);

                    Tuple <string, DateTime, DateTime> reportInfo = Tuple.Create(reportId, dateFrom, dateTo);
                    reports.Add(reportInfo);
                }
                else
                {
                    //We have more than 3 reports.
                    for (int i = 0; i < 4; i++)
                    {
                        if (DateTime.Now.Subtract(availableDates[i]).Days > 2)  //We exclude the last report if it is still open (open = haven't finished the actual period).
                        {
                            string   reportId = reportIds[i];
                            DateTime dateFrom = availableDates[i + 1].AddDays(-1); //Settlement reports are available only until the next day of their period.
                            DateTime dateTo   = availableDates[i].AddDays(-1);

                            Tuple <string, DateTime, DateTime> reportInfo = Tuple.Create(reportId, dateFrom, dateTo);
                            reports.Add(reportInfo);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Cannot download the list of settlement reports. Exception: " + e.Message);
            }

            return(reports);
        }
 protected override void SetupAccountSettings()
 {
     base.SetupAccountSettings();
     Account = AccountEnum.AmzJk529;
     _marketplaceWebService = new MarketplaceWebServiceClient(
             AccountSettingsConfigSection.Jk529_accessKey.Value,
             AccountSettingsConfigSection.Jk529_secretKey.Value,
             AppName,
             AppVersion,
             new MarketplaceWebServiceConfig { ServiceURL = AmzServiceUrl });
 }
 public AMSubmitFeedServiceCall(MarketplaceWebService.MarketplaceWebService Feeds)
 {
     this.clientFeed = Feeds;
 }