简体   繁体   中英

PHP Amazon API OrderFulfillment doesn't work _POST_ORDER_FULFILLMENT_DATA_

I'm trying to build an order updater, to set them shipped. I've used the MarketplaceWebService_Model_SubmitFeedRequest and modified the SubmitFeedSample.php The following code doesn't update the orders to shipped, and the output is not very helpful to fix the error

 <?php error_reporting(E_ALL); // turn on all errors, warnings and notices for easier debugging include_once ('config.php'); if(!isset($_GET['carrier']) or !isset($_GET['tracking']) or !isset($_GET['amazon_id'])) die("parameters not present"); $carrier = $_GET['carrier']; $tracking = $_GET['tracking']; $amazon_id = $_GET['amazon_id']; // United States: $serviceUrl = "https://mws.amazonservices.com"; // United Kingdom //$serviceUrl = "https://mws.amazonservices.co.uk"; $config = array ( 'ServiceURL' => $serviceUrl, 'ProxyHost' => null, 'ProxyPort' => -1, 'ProxyUsername' => null, 'ProxyPassword' => null, 'MaxErrorRetry' => 3, ); $service = new MarketplaceWebService_Client( AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, $config, APPLICATION_NAME, APPLICATION_VERSION); $date = date(DATE_FORMAT); $feed = <<<EOD <?xml version="1.0" encoding="UTF-8"?> <AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Header> <DocumentVersion>1.01</DocumentVersion> <MerchantIdentifier>__removed__</MerchantIdentifier> </Header> <MessageType>OrderFulfillment</MessageType> <Message> <MessageID>1</MessageID> <OperationType>Update</OperationType> <OrderFulfillment> <AmazonOrderID>$amazon_id</AmazonOrderID> <FulfillmentDate>$date</FulfillmentDate> <FulfillmentData> <CarrierName>$carrier</CarrierName> <ShippingMethod>Standard</ShippingMethod> <ShipperTrackingNumber>$tracking</ShipperTrackingNumber> </FulfillmentData> </OrderFulfillment> </Message> </AmazonEnvelope> EOD; echo $feed; $marketplaceIdArray = array("Id" => array('ATVPDKIKX0DER')); $feedHandle = @fopen('php://temp', 'rw+'); fwrite($feedHandle, $feed); rewind($feedHandle); $parameters = array ( 'Merchant' => MERCHANT_ID, 'MarketplaceIdList' => $marketplaceIdArray, 'FeedType' => '_POST_ORDER_FULFILLMENT_DATA_', 'FeedContent' => $feedHandle, 'PurgeAndReplace' => false, 'ContentMd5' => base64_encode(md5(stream_get_contents($feedHandle), true)), 'MWSAuthToken' => AWS_SECRET_ACCESS_KEY ); rewind($feedHandle); $request = new MarketplaceWebService_Model_SubmitFeedRequest($parameters); $feedHandle = @fopen('php://memory', 'rw+'); fwrite($feedHandle, $feed); rewind($feedHandle); $request = new MarketplaceWebService_Model_SubmitFeedRequest(); $request->setMerchant(MERCHANT_ID); $request->setMarketplaceIdList($marketplaceIdArray); $request->setFeedType('_POST_PRODUCT_DATA_'); $request->setContentMd5(base64_encode(md5(stream_get_contents($feedHandle), true))); rewind($feedHandle); $request->setPurgeAndReplace(false); $request->setFeedContent($feedHandle); $request->setMWSAuthToken(AWS_SECRET_ACCESS_KEY); rewind($feedHandle); invokeSubmitFeed($service, $request); @fclose($feedHandle); function invokeSubmitFeed(MarketplaceWebService_Interface $service, $request) { try { $response = $service->submitFeed($request); echo ("Service Response\\n"); echo ("=============================================================================\\n"); echo(" SubmitFeedResponse\\n"); if ($response->isSetSubmitFeedResult()) { echo(" SubmitFeedResult\\n"); $submitFeedResult = $response->getSubmitFeedResult(); if ($submitFeedResult->isSetFeedSubmissionInfo()) { echo(" FeedSubmissionInfo\\n"); $feedSubmissionInfo = $submitFeedResult->getFeedSubmissionInfo(); if ($feedSubmissionInfo->isSetFeedSubmissionId()) { echo(" FeedSubmissionId\\n"); echo(" " . $feedSubmissionInfo->getFeedSubmissionId() . "\\n"); } if ($feedSubmissionInfo->isSetFeedType()) { echo(" FeedType\\n"); echo(" " . $feedSubmissionInfo->getFeedType() . "\\n"); } if ($feedSubmissionInfo->isSetSubmittedDate()) { echo(" SubmittedDate\\n"); echo(" " . $feedSubmissionInfo->getSubmittedDate()->format(DATE_FORMAT) . "\\n"); } if ($feedSubmissionInfo->isSetFeedProcessingStatus()) { echo(" FeedProcessingStatus\\n"); echo(" " . $feedSubmissionInfo->getFeedProcessingStatus() . "\\n"); } if ($feedSubmissionInfo->isSetStartedProcessingDate()) { echo(" StartedProcessingDate\\n"); echo(" " . $feedSubmissionInfo->getStartedProcessingDate()->format(DATE_FORMAT) . "\\n"); } if ($feedSubmissionInfo->isSetCompletedProcessingDate()) { echo(" CompletedProcessingDate\\n"); echo(" " . $feedSubmissionInfo->getCompletedProcessingDate()->format(DATE_FORMAT) . "\\n"); } } } if ($response->isSetResponseMetadata()) { echo(" ResponseMetadata\\n"); $responseMetadata = $response->getResponseMetadata(); if ($responseMetadata->isSetRequestId()) { echo(" RequestId\\n"); echo(" " . $responseMetadata->getRequestId() . "\\n"); } } echo(" ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\\n"); } catch (MarketplaceWebService_Exception $ex) { echo("Caught Exception: " . $ex->getMessage() . "\\n"); echo("Response Status Code: " . $ex->getStatusCode() . "\\n"); echo("Error Code: " . $ex->getErrorCode() . "\\n"); echo("Error Type: " . $ex->getErrorType() . "\\n"); echo("Request ID: " . $ex->getRequestId() . "\\n"); echo("XML: " . $ex->getXML() . "\\n"); echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\\n"); } } 

Output:

 <?xml version="1.0" encoding="UTF-8"?> <AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Header> <DocumentVersion>1.01</DocumentVersion> <MerchantIdentifier>__removed__</MerchantIdentifier> </Header> <MessageType>OrderFulfillment</MessageType> <Message> <MessageID>1</MessageID> <OperationType>Update</OperationType> <OrderFulfillment> <AmazonOrderID>__removed__</AmazonOrderID> <FulfillmentDate>2015-10-21T05:31:42Z</FulfillmentDate> <FulfillmentData> <CarrierName>USPS</CarrierName> <ShippingMethod>Standard</ShippingMethod> <ShipperTrackingNumber>__removed__</ShipperTrackingNumber> </FulfillmentData> </OrderFulfillment> </Message> </AmazonEnvelope>Service Response ============================================================================= SubmitFeedResponse SubmitFeedResult FeedSubmissionInfo FeedSubmissionId 50021016729 FeedType _POST_PRODUCT_DATA_ SubmittedDate 2015-10-21T10:31:43Z FeedProcessingStatus _SUBMITTED_ ResponseMetadata RequestId eb4319ef-edb4-4cf0-a164-9da01296ce2e ResponseHeaderMetadata: RequestId: eb4319ef-edb4-4cf0-a164-9da01296ce2e, ResponseContext: bPNioZ3TY8tyIH72RFRXCx3QD/bDztb0+EgK2VXrIYMkqS0Gfr/QIBe/jInWTsxipz84AiRukcII S5iwcdqjcFDPGtZKbFhC,KkCctQH4ZBZdtAAY1kox95v8pbq2e48qbK3WLh364tfY7qkCUIZEZgPgF6GE1VGsYNdMVK+JAIbR L/G1jOETXQ==, Timestamp: 2015-10-21T10:31:42.823Z 

Ok I've found it. $request->setFeedType('_POST_PRODUCT_DATA_'); was wrong, it have to be replaced with _POST_ORDER_FULFILLMENT_DATA_

Great samples... :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM