Skip to content

Commit ddede71

Browse files
authored
Merge pull request #91 from CPIGroup/master
Version 1.3 Release Candidate
2 parents ddb7c95 + 9786c28 commit ddede71

File tree

162 files changed

+19412
-1169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+19412
-1169
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: php
2+
php:
3+
- '5.4'
4+
- '5.5'
5+
- '5.6'
6+
- '7'
7+
script: cd test-cases && phpunit --bootstrap bootstrap.php

CHANGELOG.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Change Log
2+
All notable changes to this project will be documented in this file.
3+
This project adheres to [Semantic Versioning](http://semver.org/).
4+
5+
## 1.3.0 - 2016-08-03
6+
### Added
7+
- Travis support
8+
- PHPUnit XML configuration file
9+
- Change log file
10+
- Contribution guidelines file
11+
- Credits file
12+
- Added support for MWS Auth Token, which can be set for each store in the config file.
13+
- Added methods for getting the last response code, error message, and error response.
14+
- Added support for the Merchant Fulfillment API with three new classes.
15+
- Added support for the Recommendations API with one new class.
16+
- Added support for the Subscriptions API with three new classes.
17+
- Added support for the Finance API two new classes.
18+
- Added four new Inbound classes relating to preorders, transport, and item prep instructions.
19+
- The marketplace can now be specified in the Order List class, Fulfillment Order class, and all Product classes.
20+
- New response fields in the Feed class: `StartedProcessingDate` and `CompletedProcessingDate`
21+
- New response fields in the Order class: `IsBusinessOrder`, `PurchaseOrderNumber`, `IsPrime`, and `IsPremiumOrder`
22+
- New response fields in the Order Item List class: `BuyerCustomizedInfo`, `PointsGranted`, and `PriceDesignation`
23+
- Added a method for getting the order ID from the Order Item List class.
24+
- New parameter in the Order List class: `TFMShipmentStatus`
25+
- Added a method for getting the raw report data from the Report class.
26+
- New response field in the Report List class: `AcknowledgedDate`
27+
- New response fields in the Fulfillment Order class: `MarketplaceId`, `DeliveryWindow`, `FulfillmentAction`, `CODSettings`, `PerUnitPrice`, and `PerUnitTax`.
28+
- New parameters in the Fulfillment Order Creator class: `MarketplaceId`, `FulfillmentAction`, `CODSettings`, and `DeliveryWindow`. The method for setting items now also has `PerUnitPrice` and `PerUnitTax`.
29+
- New method in the Fulfillment Order Creator class for updating orders.
30+
- New response fields in the Fulfillment Order List class: `MarketplaceId`, `DeliveryWindow`, `FulfillmentAction`, and `CODSettings`.
31+
- New options in the Fulfillment Preview class: `IncludeCODFulfillmentPreview` and `IncludeDeliveryWindows`.
32+
- New response fields in the Fulfillment Preview class: `ShippingSpeedCategory`, `IsFulfillable`, `IsCODCapable`, `MarketplaceId`, and `ScheduledDeliveryInfo`.
33+
- New method in the Product Info class for getting lowest-priced offers.
34+
- The Product class now keeps the identifier used to search for an item under the key `Request`.
35+
- New methods in the Shipment class for setting parameters previously restricted to use of `usePlan`.
36+
- New parameter in the Shipment class: `ShipmentName`. The method for setting items now also supports `PrepDetailsList` and `ReleaseDate` for each item.
37+
- New response fields in the Shipment Item List class: `PrepDetailsList` and `ReleaseDate`
38+
- New response field in the Shipment List class: `ConfirmedNeedByDate`
39+
- New parameters in the Shipment Planner class: `ShipToCountryCode` and `ShipToCountrySubdivisionCode`. The method for setting items now also supports `ASIN` and `PrepDetailsList` for each item.
40+
- New response field in the Shipment Planner class: `PrepDetailsList`
41+
- Added support for new styles of token responses used by some classes.
42+
43+
### Changed
44+
- Some tests that tried to load the normal configuration file now properly load test configuration.
45+
- Corrected many small mistakes in documentation.
46+
- The `setShowSalesChannel` method in the Report class now properly sets the parameter.
47+
- The Service URL setting now works with or without a slash at the end.
48+
- Changed all private methods and properties to protected.
49+
- Updated the Composer file to allow for newer PHP versions.
50+
- Fixed the spelling of `StateOrProvinceCode` throughout the Outbound and Inbound classes.
51+
- The `genTime` method now supports Unix timestamps, though some methods that use `genTime` still do not.
52+
- Updated the name of the `CompletedProcessingDate` field in the Report Request List class to `CompletedDate`.
53+
- Deprecated `getDateProcessingCompleted` in favor of `getDateCompleted`.
54+
- Updated the name of the `ShipServiceLevelCategory` field in the Order class to `ShipmentServiceLevelCategory`.
55+
- Deprecated `getShipServiceLevelCategory` in favor of `getShipmentServiceLevelCategory`.
56+
- Deprecated `setFulfillmentMethod` in the Fulfillment Order Creator class.
57+
- Deprecated `setMethodFilter` in the Fulfillment Order List class.
58+
- The Product Info class now properly gets all relationships.
59+
- The Shipment class no longer sets the address when using `usePlan` and correctly sets other parameters.
60+
- Fixed a loop caused by an empty response to actions that use tokens.
61+
62+
### Removed
63+
- Removed all of the old leftover test XML files from the mock folder
64+
- Removed old environment config lines from the test config file
65+
66+
## 1.2.0 - 2016-03-10
67+
### Added
68+
- The store name can now be omitted when initiating objects if there is only one store is set in the config file.
69+
- Added support for four relatively-new fields returned for Orders: `CbaDisplayableShippingLabel`, `ShippedByAmazonTFM`, `TFMShipmentStatus`, and `OrderType`.
70+
- Each store in the config file can have its own `serviceUrl`, which will override the normal service URL.
71+
72+
### Changed
73+
- Log messages now display time using the 24 hour format, rather than 12 hour.
74+
75+
### Fixed
76+
- Inventory lists no longer cause an error if detailed information is not given.
77+
- Logging function no longer gives an error when PHP is in strict mode.
78+
- Removed bad include paths from NetBeans project settings.
79+
- Product class no longer gives an error when PHP is in strict mode.
80+
- Product Info class now uses the correct identifier parameters when fetching categories.
81+
- Product Info class now correctly gets child relationship data.
82+
83+
### Removed
84+
- Removed the obsolete `checkResponse` method from the Feed class.
85+
86+
## 1.1.0 - 2014-05-06
87+
### Added
88+
- Raw responses are stored for debugging purposes and can be accessed with getLastResponse() or getRawResponses()
89+
- Created a folder for example scripts and added some examples to the readme
90+
- Updated the Orders API to the 2013-09-01 version, which adds Earliest/Latest Ship Date and Delivery Date to returned order data
91+
92+
### Changed
93+
- Feeds now allow for direct string input rather than relying entirely on files
94+
- Amazon-defined constants, such as API version numbers and throttle times, have been moved to a separate file since users shouldn't have to worry about them. Users who already have a config file should redo them.
95+
96+
### Fixed
97+
- HTTP 100 Continue responses are properly handled
98+
99+
## 1.0.0 - 2014-02-12
100+
### Added
101+
- Core class
102+
- Classes for eight APIs: Feeds, Fulfillment Inbound, Fulfillment Inventory, Fulfillment Outbound, Orders, Products, Reports, and Sellers

CONTRIBUTING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Contributing
2+
##General
3+
All pull requests should target the master branch. Commits should not have different code changes mixed together and should have descriptive messages.
4+
5+
##Project Scope
6+
The goal of this project is to provide a library with which the average merchant can communicate with Amazon's MWS services without needing to learn the complex language of the API. When contributing, think about whether or not the contribution is something that the average Amazon merchant would need to intract with Amazon.
7+
8+
Code for handling the merchant's data, such as for generating feeds or data crunching, falls outside of the library's intended scope and, while useful, is best left to separate projects.
9+
10+
##Code Guidelines
11+
The library is written using a custom style and does not follow any particular standard. For the sake of cohesion, changes to the code should be written in this same style. Please do not make changes to the style of the code.
12+
13+
Any new changes should fit within the previously-mentioned goal of the project. New public methods and classes should have names that are easy to understand and use without needing to consult the API's documentation. Try to follow the trend of similar existing functions, such as how methods that send requests to get information from Amazon usually have names that start with "fetch."
14+
15+
New methods should have phpdocs explaining how to use them and how they will affect the options sent in the next request. New classes should have phpdocs explaining their purpose and the workflow for using them. If the class is one that sends requests to Amazon, the documentation should indicate which Amazon actions it can perform and which of its methods are required before a request can be sent. Check the phpdocs on existing classes for examples.

CREDITS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The phpAmazonMWS library was designed and written by Thomas Hernandez (peardian at gmail) for the CPI Group.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
phpAmazonMWS
22
============
33

4+
[![Build Status](https://travis-ci.org/CPIGroup/phpAmazonMWS.svg?branch=stable)](https://travis-ci.org/CPIGroup/phpAmazonMWS)
5+
46
A library to connect to Amazon's Merchant Web Services (MWS) in an object-oriented manner, with a focus on intuitive usage.
57

68
This is __NOT__ for Amazon Web Services (AWS) - Cloud Computing Services.

amazon-config.default.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
$store['YourAmazonStore']['keyId'] = ''; //Access Key ID
2323
$store['YourAmazonStore']['secretKey'] = ''; //Secret Access Key for this store
2424
$store['YourAmazonStore']['serviceUrl'] = ''; //optional override for Service URL
25+
$store['YourAmazonStore']['MWSAuthToken'] = ''; //token needed for web apps and third-party developers
2526

2627
//Service URL Base
2728
//Current setting is United States

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "Apache-2.0",
66
"keywords": ["API", "Amazon", "PHP"],
77
"require":{
8-
"php": "~5.4",
8+
"php": ">=5.4",
99
"ext-curl": "*"
1010
},
1111
"require-dev": {

environment.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@
2828

2929
//Version numbers for cores
3030
$AMAZON_VERSION_FEEDS = '2009-01-01';
31+
$AMAZON_VERSION_FINANCE = '2015-05-01';
3132
$AMAZON_VERSION_INBOUND = '2010-10-01';
3233
$AMAZON_VERSION_INVENTORY = '2010-10-01';
34+
$AMAZON_VERSION_MERCHANT = '2015-06-01';
3335
$AMAZON_VERSION_ORDERS = '2013-09-01';
3436
$AMAZON_VERSION_OUTBOUND = '2010-10-01';
3537
$AMAZON_VERSION_PRODUCTS = '2011-10-01';
38+
$AMAZON_VERSION_RECOMMEND = '2013-04-01';
3639
$AMAZON_VERSION_REPORTS = '2009-01-01';
3740
$AMAZON_VERSION_SELLERS = '2011-07-01';
41+
$AMAZON_VERSION_SUBSCRIBE = '2013-07-01';
3842

3943
//Amazon Throttle Values in seconds
4044
//Fetching Orders
@@ -82,11 +86,23 @@
8286
//Submitting a Feed
8387
$THROTTLE_LIMIT_FEEDSUBMIT = 15;
8488
$THROTTLE_TIME_FEEDSUBMIT = 120;
85-
//Getting a Feed
89+
//Fetching a Feed List
8690
$THROTTLE_LIMIT_FEEDLIST = 10;
8791
$THROTTLE_TIME_FEEDLIST = 45;
8892
//Getting a Feed
8993
$THROTTLE_LIMIT_FEEDRESULT = 15;
9094
$THROTTLE_TIME_FEEDRESULT = 60;
95+
//Merchant Fulfillments
96+
$THROTTLE_LIMIT_MERCHANT = 10;
97+
$THROTTLE_TIME_MERCHANT = 1;
98+
//Subscriptions
99+
$THROTTLE_LIMIT_SUBSCRIBE = 25;
100+
$THROTTLE_TIME_SUBSCRIBE = 1;
101+
//Recommendations
102+
$THROTTLE_LIMIT_RECOMMEND = 8;
103+
$THROTTLE_TIME_RECOMMEND = 2;
104+
//Recommendations
105+
$THROTTLE_LIMIT_FINANCE = 30;
106+
$THROTTLE_TIME_FINANCE = 2;
91107

92108
?>

includes/classes/AmazonCore.php

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ public function setMock($b = true,$files = null){
190190
* including the name and path of the file involved. For retrieving response
191191
* codes, see <i>fetchMockResponse</i>.
192192
* @param boolean $load [optional] <p>Set this to <b>FALSE</b> to prevent the
193-
* method from loading the file's contents into a SimpleXMLObject. This is
193+
* method from loading the file's contents into a SimpleXMLElement. This is
194194
* for when the contents of the file are not in XML format, or if you simply
195195
* want to retrieve the raw string of the file.</p>
196-
* @return SimpleXMLObject|string|boolean <p>A SimpleXMLObject holding the
196+
* @return SimpleXMLElement|string|boolean <p>A SimpleXMLElement holding the
197197
* contents of the file, or a string of said contents if <i>$load</i> is set to
198198
* <b>FALSE</b>. The return will be <b>FALSE</b> if the file cannot be
199199
* fetched for any reason.</p>
@@ -362,7 +362,7 @@ public function setConfig($path){
362362
$this->config = $path;
363363
$this->setLogPath($logpath);
364364
if (isset($AMAZON_SERVICE_URL)) {
365-
$this->urlbase = $AMAZON_SERVICE_URL;
365+
$this->urlbase = rtrim($AMAZON_SERVICE_URL, '/') . '/';
366366
}
367367
} else {
368368
throw new Exception("Config file does not exist or cannot be read! ($path)");
@@ -431,6 +431,9 @@ public function setStore($s=null){
431431
if (!empty($store[$s]['serviceUrl'])) {
432432
$this->urlbase = $store[$s]['serviceUrl'];
433433
}
434+
if (!empty($store[$s]['MWSAuthToken'])) {
435+
$this->options['MWSAuthToken'] = $store[$s]['MWSAuthToken'];
436+
}
434437

435438
} else {
436439
$this->log("Store $s does not exist!",'Warning');
@@ -543,17 +546,22 @@ public function getOptions(){
543546
* The string given is passed through <i>strtotime</i> before being used. The
544547
* value returned is actually two minutes early, to prevent it from tripping up
545548
* Amazon. If no time is given, the current time is used.
546-
* @param string $time [optional] <p>The time to use. Since this value is
549+
* @param string|int $time [optional] <p>The time to use. Since any string values are
547550
* passed through <i>strtotime</i> first, values such as "-1 hour" are fine.
551+
* Unix timestamps are also allowed. Purely numeric values are treated as unix timestamps.
548552
* Defaults to the current time.</p>
549553
* @return string Unix timestamp of the time, minus 2 minutes.
554+
* @throws InvalidArgumentException
550555
*/
551556
protected function genTime($time=false){
552557
if (!$time){
553558
$time = time();
554-
} else {
559+
} else if (is_numeric($time)) {
560+
$time = (int)$time;
561+
} else if (is_string($time)) {
555562
$time = strtotime($time);
556-
563+
} else {
564+
throw new InvalidArgumentException('Invalid time input given');
557565
}
558566
return date('Y-m-d\TH:i:sO',$time-120);
559567

@@ -646,6 +654,69 @@ public function getRawResponses() {
646654
return false;
647655
}
648656
}
657+
658+
/**
659+
* Gives the response code from the last response.
660+
* This data can also be found in the array given by getLastResponse.
661+
* @return string|int standard REST response code (200, 404, etc.) or <b>NULL</b> if no response
662+
* @see getLastResponse
663+
*/
664+
public function getLastResponseCode() {
665+
$last = $this->getLastResponse();
666+
if (!empty($last['code'])) {
667+
return $last['code'];
668+
}
669+
}
670+
671+
/**
672+
* Gives the last response with an error code.
673+
* This may or may not be the same as the last response if multiple requests were made.
674+
* @return array associative array of HTTP response or <b>NULL</b> if no error response yet
675+
* @see getLastResponse
676+
*/
677+
public function getLastErrorResponse() {
678+
if (!empty($this->rawResponses)) {
679+
foreach (array_reverse($this->rawResponses) as $x) {
680+
if (isset($x['error'])) {
681+
return $x;
682+
}
683+
}
684+
}
685+
}
686+
687+
/**
688+
* Gives the Amazon error code from the last error response.
689+
* The error code uses words rather than numbers. (Ex: "InvalidParameterValue")
690+
* This data can also be found in the XML body given by getLastErrorResponse.
691+
* @return string Amazon error code or <b>NULL</b> if not set yet or no error response yet
692+
* @see getLastErrorResponse
693+
*/
694+
public function getLastErrorCode() {
695+
$last = $this->getLastErrorResponse();
696+
if (!empty($last['body'])) {
697+
$xml = simplexml_load_string($last['body']);
698+
if (isset($xml->Error->Code)) {
699+
return $xml->Error->Code;
700+
}
701+
}
702+
}
703+
704+
/**
705+
* Gives the error message from the last error response.
706+
* Not all error responses will have error messages.
707+
* This data can also be found in the XML body given by getLastErrorResponse.
708+
* @return string Amazon error code or <b>NULL</b> if not set yet or no error response yet
709+
* @see getLastErrorResponse
710+
*/
711+
public function getLastErrorMessage() {
712+
$last = $this->getLastErrorResponse();
713+
if (!empty($last['body'])) {
714+
$xml = simplexml_load_string($last['body']);
715+
if (isset($xml->Error->Message)) {
716+
return $xml->Error->Message;
717+
}
718+
}
719+
}
649720

650721
/**
651722
* Sleeps for the throttle time and records to the log.
@@ -659,14 +730,11 @@ protected function sleep(){
659730

660731
/**
661732
* Checks for a token and changes the proper options
662-
* @param SimpleXMLObject $xml <p>response data</p>
733+
* @param SimpleXMLElement $xml <p>response data</p>
663734
* @return boolean <b>FALSE</b> if no XML data
664735
*/
665736
protected function checkToken($xml){
666-
if (!$xml){
667-
return false;
668-
}
669-
if ($xml->NextToken){
737+
if ($xml && $xml->NextToken && (string)$xml->HasNext != 'false' && (string)$xml->MoreResultsAvailable != 'false'){
670738
$this->tokenFlag = true;
671739
$this->options['NextToken'] = (string)$xml->NextToken;
672740
} else {
@@ -768,7 +836,8 @@ function fetchURL ($url, $param) {
768836
*/
769837
protected function _urlencode($value) {
770838
return rawurlencode($value);
771-
return str_replace('%7E', '~', rawurlencode($value));
839+
//Amazon suggests doing this, but it seems to break things rather than fix them:
840+
//return str_replace('%7E', '~', rawurlencode($value));
772841
}
773842

774843
/**

0 commit comments

Comments
 (0)