/** * Submit the generated XML file to Amazon. */ public function submit() { /** @var Edgecom_MarketplaceWebService_Helper_Data $helper */ $helper = Mage::helper('edgecom_marketplacewebservice'); $awsAccessKeyId = $helper->getAwsAccessKeyId(); $secretKey = $helper->getSecretKey(); $applicationName = $helper->getApplicationName(); $applicationVersion = $helper->getApplicationVersion(); $service = new MarketplaceWebService_Client($awsAccessKeyId, $secretKey, array('ServiceURL' => 'https://mws.amazonservices.com', 'ProxyHost' => null, 'ProxyPort' => -1, 'MaxErrorRetry' => 3), $applicationName, $applicationVersion); $merchantId = $helper->getSellerId(); $marketplaceIdArray = array('Id' => array($helper->getMarketplaceId())); $request = new MarketplaceWebService_Model_SubmitFeedRequest(); $request->setMerchant($merchantId); $request->setMarketplaceIdList($marketplaceIdArray); $request->setFeedType($this->feed->getType()); $request->setPurgeAndReplace(false); if ($stream = fopen($this->feed->getLocation(), 'r')) { $request->setContentMd5(base64_encode(md5(stream_get_contents($stream), true))); rewind($stream); $request->setFeedContent($stream); rewind($stream); } $response = $service->submitFeed($request); fclose($stream); $feedSubmissionId = $response->getSubmitFeedResult()->getFeedSubmissionInfo()->getFeedSubmissionId(); Mage::log('Feed #' . $feedSubmissionId . ' has been submitted to Amazon', null, 'amazon.log'); }
protected function configureCurlOptions($action, array $converted, $streamHandle = null, $contentMd5 = null) { $curlOptions = parent::configureCurlOptions($action, $converted, $streamHandle, $contentMd5); if (RequestType::getRequestType($action) == RequestType::POST_DOWNLOAD) { $this->responseBodyContents = $streamHandle; $curlOptions[CURLOPT_WRITEFUNCTION] = array($this, 'responseCallback'); } return $curlOptions; }
/** * @param ReportListItem $report * @return string */ public function getReport(ReportListItem $report) { $request = new \MarketplaceWebService_Model_GetReportRequest(); $request->setReport(@fopen('php://memory', 'rw+')); $request->setReportId($report->getReportId()); $request->setMerchant($this->config->getMerchantId()); $request->setMarketplace($this->config->getMarketPlaceId()); $this->service->getReport($request); $reportData = stream_get_contents($request->getReport()); return $reportData; }
function getAmazonNewOrders($with_header_message = true) { global $files; use_class('jng_sp_download'); $class_jd = new jng_sp_download(); $ready_path = SP_AMAZONEDE_DECRYPT_PATH; $archived_path = SP_AMAZONEDE_ARCHIVE_PATH; use_class('amazon/MarketplaceWebService/Client'); //MANDATORY CLASS use_class('amazon/MarketplaceWebService/Model/ErrorResponse'); //MANDATORY CLASS use_class('amazon/MarketplaceWebService/Model/GetReportRequest'); //FEED USED CLASS use_class('amazon/MarketplaceWebService/Model/GetReportResponse'); //FEED USED CLASS use_class('amazon/MarketplaceWebService/Model/GetReportListRequest'); //FEED USED CLASS use_class('amazon/MarketplaceWebService/Model/GetReportListResponse'); //FEED USED CLASS use_class('amazon/MarketplaceWebService/Model/TypeList'); //TYPE LIST CLASS $serviceUrl = "https://mws.amazonservices.de"; $aws_config = array('ServiceURL' => $serviceUrl, 'ProxyHost' => null, 'ProxyPort' => -1, 'MaxErrorRetry' => 3); $service = new MarketplaceWebService_Client(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, $aws_config, APPLICATION_NAME, APPLICATION_VERSION); $list = new MarketplaceWebService_Model_TypeList(); $list->setType('_GET_ORDERS_DATA_'); $report_from_date = new DateTime('-3 months', new DateTimeZone('UTC')); $report_to_date = new DateTime('now', new DateTimeZone('UTC')); $request = new MarketplaceWebService_Model_GetReportListRequest(); $request->setMerchant(MERCHANT_ID); $request->setMarketplace(MARKETPLACE_ID); $request->setAvailableToDate($report_to_date); $request->setAvailableFromDate($report_from_date); $request->setReportTypeList($list); $request->setAcknowledged(false); // echo"<pre>";var_dump($request);die(); $response = $service->getReportList($request); // echo"<pre>";var_dump($response);die(); if ($response->isSetGetReportListResult()) { if ($with_header_message) { echo "START DOWNLOADING NEW ORDERS FROM AMAZON PERIODE " . $report_from_date->format(DATE_ISO8601) . " TO " . $report_to_date->format(DATE_ISO8601) . "<br/>"; } $getReportListResult = $response->getGetReportListResult(); $reportInfoList = $getReportListResult->getReportInfoList(); if (count($reportInfoList) > 0) { $download_message = ' --- NO NEW ORDERS AVAILABLE ---<br/>'; foreach ($reportInfoList as $reportInfo) { if ($reportInfo->isSetReportId()) { $report_id = $reportInfo->getReportId(); $filename = date('Ymd') . '-' . $report_id . '.XML'; if (!$class_jd->isAlreadyDownloaded("jng_sp_id = 4 AND SUBSTRING_INDEX(filename, '-',-1) = '{$report_id}.XML'")) { $download_message = ''; echo " >> DOWNLOADING REPORT_ID: {$report_id} ... "; $fullpath_ready = $ready_path . $filename; $handle = fopen($fullpath_ready, 'w'); $request_report = new MarketplaceWebService_Model_GetReportRequest(); $request_report->setMarketplace(MARKETPLACE_ID); $request_report->setMerchant(MERCHANT_ID); $request_report->setReport($handle); $request_report->setReportId($report_id); $response_report = $service->getReport($request_report); echo "STREAMING XML {$filename} ... "; $archive_path_raw = $archived_path . 'raw/' . date('Y') . '/'; if (!file_exists($archive_path_raw)) { mkdir($archive_path_raw); } $fullpath_archive = $archive_path_raw . $filename; $class_jd->addDownload('4', 'ORDERS', $filename, 'R'); $files[] = $filename; fclose($handle); echo "PROCESS DONE<br/>"; } } } echo $download_message; } else { echo ' --- NO NEW ORDERS AVAILABLE ---<br/>'; } //LOOP MORE IF HAS NEXT NEW ORDERS if ($getReportListResult->isSetHasNext() && $getReportListResult->getHasNext()) { getAmazonNewOrders(false); } else { echo "DONE DOWNLOADING NEW ORDERS FROM AMAZON <br/>"; } } }
/** * Function to get the status of the feed submitted through MWS identified by * ReferenceID returned when feed was submitted. * @param referenceId string * @returns true: if the feed's processing was successful * false: if the feed's processing was pending/unsuccessful with errors * Added for checking the status of the submitted requests (used by polling) */ public function getRequestStatus($referenceId) { $country = Mage::getStoreConfig('payment/amazonpayments_cba/country'); if ($country == "US") { $serviceUrl = Mage::getStoreConfig('payment/amazonpayments_cba/mws_service_url_US'); $marketplace_id = Mage::getStoreConfig('payment/amazonpayments_cba/marketplace_id_US'); } elseif ($country == "UK") { $serviceUrl = Mage::getStoreConfig('payment/amazonpayments_cba/mws_service_url_UK'); $marketplace_id = Mage::getStoreConfig('payment/amazonpayments_cba/marketplace_id_UK'); } elseif ($country == "DE") { $serviceUrl = Mage::getStoreConfig('payment/amazonpayments_cba/mws_service_url_DE'); $marketplace_id = Mage::getStoreConfig('payment/amazonpayments_cba/marketplace_id_DE'); } Mage::log("In getStatusRequest:"); $application_name = 'Magento CBA Plugin'; $application_version = Mage::getVersion(); $merchant_id = Mage::getStoreConfig('payment/amazonpayments_cba/merchant_id'); $config = array('ServiceURL' => $serviceUrl, 'ProxyHost' => null, 'ProxyPort' => -1, 'MaxErrorRetry' => 3); /************************************************************************ * Instantiate Implementation of MarketplaceWebService * * AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY constants * are defined in the .config.inc.php located in the same * directory as this sample ***********************************************************************/ $service = new MarketplaceWebService_Client($this->getMwsAccessKey(), $this->getMwsSecretKey(), $config, $application_name, $application_version); $feedHandle = @fopen('php://memory', 'rw+'); $parameters = array('Marketplace' => $marketplace_id, 'Merchant' => $merchant_id, 'FeedSubmissionId' => $referenceId, 'FeedSubmissionResult' => $feedHandle); $request = new MarketplaceWebService_Model_GetFeedSubmissionResultRequest($parameters); $processingStatus = false; try { $response = $service->getFeedSubmissionResult($request); } catch (MarketplaceWebService_Exception $ex) { Mage::log("Caught Exception: " . $ex->getMessage() . "\n"); Mage::log("Response Status Code: " . $ex->getStatusCode() . "\n"); Mage::log("Error Code: " . $ex->getErrorCode() . "\n"); Mage::log("Error Type: " . $ex->getErrorType() . "\n"); Mage::log("Request ID: " . $ex->getRequestId() . "\n"); Mage::log("XML: " . $ex->getXML() . "\n"); @fclose($feedHandle); return $processingStatus; //returns false in case of request still in pending status } rewind($feedHandle); $xml = simplexml_load_string(stream_get_contents($feedHandle), 'Varien_Simplexml_Element'); if ($xml->descend('Message/ProcessingReport/ProcessingSummary/MessagesSuccessful') == "1") { Mage::log("Success"); $processingStatus = true; //Sets status to true if and only if the feed was successfully processed } if ($processingStatus) { Mage::log("Returning the state of " . $referenceId . " !"); } @fclose($feedHandle); return $processingStatus; }