Skip to content

Commit 7ab8701

Browse files
authored
Merge pull request #140 from CPIGroup/master
Version 1.4 Release Candidate
2 parents ddede71 + b3e6b0c commit 7ab8701

25 files changed

+1619
-49
lines changed

.travis.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
language: php
22
php:
3-
- '5.4'
4-
- '5.5'
5-
- '5.6'
6-
- '7'
7-
script: cd test-cases && phpunit --bootstrap bootstrap.php
3+
- 5.4
4+
- 5.5
5+
- 5.6
6+
- 7
7+
- 7.1
8+
- 7.2
9+
10+
matrix:
11+
allow_failures:
12+
php: 7.1
13+
php: 7.2
14+
15+
# install packages explicitly
16+
install:
17+
- composer self-update && composer install
18+
19+
# show me what phpunit version we are running
20+
before_script:
21+
- vendor/bin/phpunit --version
22+
23+
# run the test suite
24+
script: cd test-cases && php ../vendor/bin/phpunit --bootstrap bootstrap.php

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 1.4.0 - 2017-11-17
6+
### Added
7+
- Travis support for PHP 7.1 and 7.2
8+
- Option to disable SSL verification (not recommended outside of testing)
9+
- New response fields in Financial Event List class for SAFE-T Reimbursement events
10+
- New response fields in the Fulfillment Order class: `ReturnItems` and `ReturnAuthorizations`
11+
- New response field in the Merchant Service List class: `AvailableLabelFormats`
12+
- New response fields in the Merchant Shipment class: `CustomTextForLabel`, `LabelFormat`, and `StandardIdForLabel`
13+
- New parameters for the Merchant Shipment Creator class: `CustomTextForLabel`, `LabelFormat`, `StandardIdForLabel`, and `HazmatType`
14+
- New response fields in the Order class: `PaymentMethodDetails`, `IsReplacementOrder`, `ReplacedOrderId`, `BuyerCounty`, and `BuyerTaxInfo`
15+
- New product class for getting Product Fee Estimates
16+
### Changed
17+
- Composer now allows PHPUnit versions 4 and 5
18+
- Tries to create the log file specified in config if it does not exist
19+
- Fixed undefined index error when processing an empty or invalid response from cURL
20+
521
## 1.3.0 - 2016-08-03
622
### Added
723
- Travis support

composer.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33
"type": "library",
44
"description": "An open-source library to connect to Amazon's MWS web services in an object-oriented manner, with a focus on intuitive usage.",
55
"license": "Apache-2.0",
6-
"keywords": ["API", "Amazon", "PHP"],
7-
"require":{
8-
"php": ">=5.4",
9-
"ext-curl": "*"
6+
"keywords": [
7+
"API",
8+
"Amazon",
9+
"PHP"
10+
],
11+
"require": {
12+
"php": ">=5.4",
13+
"ext-curl": "*"
1014
},
1115
"require-dev": {
12-
"phpunit/phpunit": "3.7.*"
13-
},
16+
"phpunit/phpunit": ">=4.0.0, <6.0.0"
17+
},
1418
"autoload": {
15-
"classmap": ["includes/classes/"]
19+
"classmap": [
20+
"includes/classes/"
21+
]
1622
}
1723
}

environment.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
$THROTTLE_TIME_PRODUCTMATCH = 1;
6666
$THROTTLE_TIME_PRODUCTID = 4;
6767
$THROTTLE_TIME_PRODUCTPRICE = 2;
68+
$THROTTLE_TIME_PRODUCTFEE = 10;
6869
//Requesting a Report
6970
$THROTTLE_LIMIT_REPORTREQUEST = 15;
7071
$THROTTLE_TIME_REPORTREQUEST = 60;

includes/classes/AmazonCore.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ abstract class AmazonCore{
106106
protected $logpath;
107107
protected $env;
108108
protected $rawResponses = array();
109-
109+
protected $disableSslVerify = false;
110+
110111
/**
111112
* AmazonCore constructor sets up key information used in all Amazon requests.
112113
*
@@ -378,6 +379,10 @@ public function setConfig($path){
378379
* @throws Exception If the file cannot be found or read.
379380
*/
380381
public function setLogPath($path){
382+
if (!file_exists($path)){
383+
touch($path);
384+
}
385+
381386
if (file_exists($path) && is_readable($path)){
382387
$this->logpath = $path;
383388
} else {
@@ -607,7 +612,7 @@ protected function sendRequest($url,$param){
607612
$this->log("Making request to Amazon: ".$this->options['Action']);
608613
$response = $this->fetchURL($url,$param);
609614

610-
while ($response['code'] == '503' && $this->throttleStop==false){
615+
while (isset($response['code']) && $response['code'] == '503' && $this->throttleStop==false){
611616
$this->sleep();
612617
$response = $this->fetchURL($url,$param);
613618
}
@@ -742,7 +747,24 @@ protected function checkToken($xml){
742747
$this->tokenFlag = false;
743748
}
744749
}
745-
750+
751+
/**
752+
* Disables or enables the use of SSL verification when sending requests to Amazon.
753+
*
754+
* This is <b>not recommended</b> for a production environment,
755+
* as it is a <b>security risk</b> and can put merchant credentials in danger.
756+
* However, this option is still available in case it is needed.
757+
*
758+
* Use at your own risk.
759+
* @param boolean $b [optional] <p>Defaults to <b>TRUE</b>.</p>
760+
*/
761+
public function setDisableSslVerify($b = true) {
762+
$this->disableSslVerify = $b;
763+
if ($b) {
764+
$this->log('Caution: Disabling SSL verification.', 'Warning');
765+
}
766+
}
767+
746768
//Functions from Athena:
747769
/**
748770
* Get url or send POST data
@@ -765,6 +787,11 @@ function fetchURL ($url, $param) {
765787
curl_setopt($ch,CURLOPT_FRESH_CONNECT, 1);
766788
curl_setopt($ch,CURLOPT_HEADER, 1);
767789
curl_setopt($ch,CURLOPT_URL,$url);
790+
if ($this->disableSslVerify) {
791+
$this->log('Caution: Request being sent without SSL verification.', 'Warning');
792+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
793+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
794+
}
768795
if (!empty($param)){
769796
if (!empty($param['Header'])){
770797
curl_setopt($ch,CURLOPT_HTTPHEADER, $param['Header']);

includes/classes/AmazonFinancialEventList.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,29 @@ protected function parseXml($xml) {
426426
$this->list['Adjustment'][] = $temp;
427427
}
428428
}
429+
if (isset($xml->SAFETReimbursementEventList)) {
430+
foreach($xml->SAFETReimbursementEventList->children() as $x) {
431+
$temp = array();
432+
$temp['PostedDate'] = (string)$x->PostedDate;
433+
$temp['SAFETClaimId'] = (string)$x->SAFETClaimId;
434+
$temp['Amount'] = (string)$x->ReimbursedAmount->CurrencyAmount;
435+
$temp['CurrencyCode'] = (string)$x->ReimbursedAmount->CurrencyCode;
436+
$temp['SAFETReimbursementItemList'] = array();
437+
if (isset($x->SAFETReimbursementItemList)) {
438+
foreach($x->SAFETReimbursementItemList->children() as $y) {
439+
if (!isset($y->ItemChargeList)) {
440+
continue;
441+
}
442+
$ztemp = array();
443+
foreach($y->ItemChargeList->children() as $z) {
444+
$ztemp['ItemChargeList'][] = $this->parseCharge($z);
445+
}
446+
$temp['SAFETReimbursementItemList'][] = $ztemp;
447+
}
448+
}
449+
$this->list['SAFET'][] = $temp;
450+
}
451+
}
429452
}
430453

431454
/**
@@ -542,8 +565,8 @@ protected function parseShipmentEvent($xml) {
542565
/**
543566
* Parses XML for a single charge into an array.
544567
* This structure is used many times throughout shipment events.
545-
* @param SimpleXMLElement $xml <p>The XML response from Amazon.</p>
546-
* @return array parsed structure from XML
568+
* @param SimpleXMLElement $xml <p>Charge node of the XML response from Amazon.</p>
569+
* @return array Parsed structure from XML
547570
*/
548571
protected function parseCharge($xml) {
549572
$r = array();
@@ -585,6 +608,7 @@ protected function parseFee($xml) {
585608
* <li><b>DebtRecovery</b> - see <i>getDebtRecoveryEvents</i></li>
586609
* <li><b>LoanServicing</b> - see <i>getLoanServicingEvents</i></li>
587610
* <li><b>Adjustment</b> - see <i>getAdjustmentEvents</i></li>
611+
* <li><b>SAFET</b> - see <i>getSafetEvents</i></li>
588612
* </ul>
589613
* @return array|boolean multi-dimensional array, or <b>FALSE</b> if list not filled yet
590614
* @see getShipmentEvents
@@ -600,6 +624,7 @@ protected function parseFee($xml) {
600624
* @see getDebtRecoveryEvents
601625
* @see getLoanServicingEvents
602626
* @see getAdjustmentEvents
627+
* @see getSafetEvents
603628
*/
604629
public function getEvents(){
605630
if (isset($this->list)){
@@ -991,4 +1016,33 @@ public function getAdjustmentEvents(){
9911016
}
9921017
}
9931018

1019+
/**
1020+
* Returns all SAFE-T reimbursement events.
1021+
*
1022+
* Each event array will have the following keys:
1023+
* <ul>
1024+
* <li><b>PostedDate</b> - ISO 8601 date format</li>
1025+
* <li><b>Amount</b> - number</li>
1026+
* <li><b>CurrencyCode</b> - ISO 4217 currency code</li>
1027+
* <li><b>SAFETClaimId</b></li>
1028+
* <li><b>SAFETReimbursementItemList</b> - multi-dimensional array, each array has the following keys:</li>
1029+
* <ul>
1030+
* <li><b>ItemChargeList</b> - multi-dimensional array, each array has the following keys:</li>
1031+
* <ul>
1032+
* <li><b>ChargeType</b></li>
1033+
* <li><b>Amount</b> - number</li>
1034+
* <li><b>CurrencyCode</b> - ISO 4217 currency code</li>
1035+
* </ul>
1036+
* </ul>
1037+
* </ul>
1038+
* @return array|boolean multi-dimensional array, or <b>FALSE</b> if list not filled yet
1039+
*/
1040+
public function getSafetEvents(){
1041+
if (isset($this->list['SAFET'])){
1042+
return $this->list['SAFET'];
1043+
} else {
1044+
return false;
1045+
}
1046+
}
1047+
9941048
}

includes/classes/AmazonFulfillmentOrder.php

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -135,28 +135,7 @@ protected function parseXML($xml) {
135135
$this->order['Details']['DeliveryWindow']['StartDateTime'] = (string)$d->DeliveryWindow->StartDateTime;
136136
$this->order['Details']['DeliveryWindow']['EndDateTime'] = (string)$d->DeliveryWindow->EndDateTime;
137137
}
138-
//Address
139-
$this->order['Details']['DestinationAddress']['Name'] = (string)$d->DestinationAddress->Name;
140-
$this->order['Details']['DestinationAddress']['Line1'] = (string)$d->DestinationAddress->Line1;
141-
if (isset($d->DestinationAddress->Line2)){
142-
$this->order['Details']['DestinationAddress']['Line2'] = (string)$d->DestinationAddress->Line2;
143-
}
144-
if (isset($d->DestinationAddress->Line3)){
145-
$this->order['Details']['DestinationAddress']['Line3'] = (string)$d->DestinationAddress->Line3;
146-
}
147-
if (isset($d->DestinationAddress->DistrictOrCounty)){
148-
$this->order['Details']['DestinationAddress']['DistrictOrCounty'] = (string)$d->DestinationAddress->DistrictOrCounty;
149-
}
150-
$this->order['Details']['DestinationAddress']['City'] = (string)$d->DestinationAddress->City;
151-
$this->order['Details']['DestinationAddress']['StateOrProvinceCode'] = (string)$d->DestinationAddress->StateOrProvinceCode;
152-
$this->order['Details']['DestinationAddress']['CountryCode'] = (string)$d->DestinationAddress->CountryCode;
153-
if (isset($d->DestinationAddress->PostalCode)){
154-
$this->order['Details']['DestinationAddress']['PostalCode'] = (string)$d->DestinationAddress->PostalCode;
155-
}
156-
if (isset($d->DestinationAddress->PhoneNumber)){
157-
$this->order['Details']['DestinationAddress']['PhoneNumber'] = (string)$d->DestinationAddress->PhoneNumber;
158-
}
159-
//End of Address
138+
$this->order['Details']['DestinationAddress'] = $this->parseAddress($d->DestinationAddress);
160139
if (isset($d->FulfillmentAction)){
161140
$this->order['Details']['FulfillmentAction'] = (string)$d->FulfillmentAction;
162141
}
@@ -279,6 +258,78 @@ protected function parseXML($xml) {
279258

280259
$i++;
281260
}
261+
262+
//Section 4: Return Items
263+
if (isset($xml->ReturnItemList)) {
264+
foreach ($xml->ReturnItemList->children() as $x) {
265+
$temp = array();
266+
$temp['SellerReturnItemId'] = (string)$x->SellerReturnItemId;
267+
$temp['SellerFulfillmentOrderItemId'] = (string)$x->SellerFulfillmentOrderItemId;
268+
$temp['AmazonShipmentId'] = (string)$x->AmazonShipmentId;
269+
$temp['SellerReturnReasonCode'] = (string)$x->SellerReturnReasonCode;
270+
if (isset($x->ReturnComment)) {
271+
$temp['ReturnComment'] = (string)$x->ReturnComment;
272+
}
273+
if (isset($x->AmazonReturnReasonCode)) {
274+
$temp['AmazonReturnReasonCode'] = (string)$x->AmazonReturnReasonCode;
275+
}
276+
$temp['Status'] = (string)$x->Status;
277+
$temp['StatusChangedDate'] = (string)$x->StatusChangedDate;
278+
if (isset($x->ReturnAuthorizationId)) {
279+
$temp['ReturnAuthorizationId'] = (string)$x->ReturnAuthorizationId;
280+
}
281+
if (isset($x->ReturnReceivedCondition)) {
282+
$temp['ReturnReceivedCondition'] = (string)$x->ReturnReceivedCondition;
283+
}
284+
if (isset($x->FulfillmentCenterId)) {
285+
$temp['FulfillmentCenterId'] = (string)$x->FulfillmentCenterId;
286+
}
287+
$this->order['ReturnItems'][] = $temp;
288+
}
289+
}
290+
291+
//Section 5: Return Authorizations
292+
if (isset($xml->ReturnAuthorizationList)) {
293+
foreach ($xml->ReturnAuthorizationList->children() as $x) {
294+
$temp = array();
295+
$temp['ReturnAuthorizationId'] = (string)$x->ReturnAuthorizationId;
296+
$temp['FulfillmentCenterId'] = (string)$x->FulfillmentCenterId;
297+
$temp['ReturnToAddress'] = $this->parseAddress($x->ReturnToAddress);
298+
$temp['AmazonRmaId'] = (string)$x->AmazonRmaId;
299+
$temp['RmaPageURL'] = (string)$x->RmaPageURL;
300+
$this->order['ReturnAuthorizations'][] = $temp;
301+
}
302+
}
303+
}
304+
305+
/**
306+
* Parses XML for an address into an array.
307+
* @param SimpleXMLElement $xml <p>Address node of the XML response from Amazon.</p>
308+
* @return array Parsed structure from XML
309+
*/
310+
public function parseAddress($xml) {
311+
$r = array();
312+
$r['Name'] = (string)$xml->Name;
313+
$r['Line1'] = (string)$xml->Line1;
314+
if (isset($xml->Line2)){
315+
$r['Line2'] = (string)$xml->Line2;
316+
}
317+
if (isset($xml->Line3)){
318+
$r['Line3'] = (string)$xml->Line3;
319+
}
320+
if (isset($xml->DistrictOrCounty)){
321+
$r['DistrictOrCounty'] = (string)$xml->DistrictOrCounty;
322+
}
323+
$r['City'] = (string)$xml->City;
324+
$r['StateOrProvinceCode'] = (string)$xml->StateOrProvinceCode;
325+
$r['CountryCode'] = (string)$xml->CountryCode;
326+
if (isset($xml->PostalCode)){
327+
$r['PostalCode'] = (string)$xml->PostalCode;
328+
}
329+
if (isset($xml->PhoneNumber)){
330+
$r['PhoneNumber'] = (string)$xml->PhoneNumber;
331+
}
332+
return $r;
282333
}
283334

284335
/**
@@ -323,6 +374,8 @@ public function cancelOrder(){
323374
* <li><b>Details</b> - array of general information, such as destination address</li>
324375
* <li><b>Items</b> - multi-dimensional array of item data</li>
325376
* <li><b>Shipments</b> - multi-dimensional array of shipment data</li>
377+
* <li><b>ReturnItems</b> - multi-dimensional array of return item data</li>
378+
* <li><b>ReturnAuthorizations</b> - multi-dimensional array of return authorization data</li>
326379
* </ul>
327380
* @return array|boolean data array, or <b>FALSE</b> if data not filled yet
328381
*/

includes/classes/AmazonMerchantServiceList.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,11 @@ protected function parseXML($xml){
553553
$this->serviceList[$i]['ShippingServiceOptions']['DeclaredValue']['Amount'] = (string)$x->ShippingServiceOptions->DeclaredValue->Amount;
554554
$this->serviceList[$i]['ShippingServiceOptions']['DeclaredValue']['CurrencyCode'] = (string)$x->ShippingServiceOptions->DeclaredValue->CurrencyCode;
555555
}
556+
if (isset($x->AvailableLabelFormats)) {
557+
foreach ($x->AvailableLabelFormats as $z) {
558+
$this->serviceList[$i]['AvailableLabelFormats'][] = (string)$z;
559+
}
560+
}
556561

557562
$i++;
558563
}
@@ -594,6 +599,7 @@ protected function parseXML($xml){
594599
* <li><b>LatestEstimatedDeliveryDate</b></li>
595600
* <li><b>Rate</b></li>
596601
* <li><b>ShippingServiceOptions</b></li>
602+
* <li><b>AvailableLabelFormats</b></li>
597603
* </ul>
598604
* @return array|boolean multi-dimensional array, or <b>FALSE</b> if list not filled yet
599605
*/

0 commit comments

Comments
 (0)