Skip to content

Commit

Permalink
Merge pull request #140 from CPIGroup/master
Browse files Browse the repository at this point in the history
Version 1.4 Release Candidate
  • Loading branch information
Peardian authored Nov 17, 2017
2 parents ddede71 + b3e6b0c commit 7ab8701
Show file tree
Hide file tree
Showing 25 changed files with 1,619 additions and 49 deletions.
27 changes: 22 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
language: php
php:
- '5.4'
- '5.5'
- '5.6'
- '7'
script: cd test-cases && phpunit --bootstrap bootstrap.php
- 5.4
- 5.5
- 5.6
- 7
- 7.1
- 7.2

matrix:
allow_failures:
php: 7.1
php: 7.2

# install packages explicitly
install:
- composer self-update && composer install

# show me what phpunit version we are running
before_script:
- vendor/bin/phpunit --version

# run the test suite
script: cd test-cases && php ../vendor/bin/phpunit --bootstrap bootstrap.php
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

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

## 1.3.0 - 2016-08-03
### Added
- Travis support
Expand Down
20 changes: 13 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
"type": "library",
"description": "An open-source library to connect to Amazon's MWS web services in an object-oriented manner, with a focus on intuitive usage.",
"license": "Apache-2.0",
"keywords": ["API", "Amazon", "PHP"],
"require":{
"php": ">=5.4",
"ext-curl": "*"
"keywords": [
"API",
"Amazon",
"PHP"
],
"require": {
"php": ">=5.4",
"ext-curl": "*"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"phpunit/phpunit": ">=4.0.0, <6.0.0"
},
"autoload": {
"classmap": ["includes/classes/"]
"classmap": [
"includes/classes/"
]
}
}
1 change: 1 addition & 0 deletions environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
$THROTTLE_TIME_PRODUCTMATCH = 1;
$THROTTLE_TIME_PRODUCTID = 4;
$THROTTLE_TIME_PRODUCTPRICE = 2;
$THROTTLE_TIME_PRODUCTFEE = 10;
//Requesting a Report
$THROTTLE_LIMIT_REPORTREQUEST = 15;
$THROTTLE_TIME_REPORTREQUEST = 60;
Expand Down
33 changes: 30 additions & 3 deletions includes/classes/AmazonCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ abstract class AmazonCore{
protected $logpath;
protected $env;
protected $rawResponses = array();

protected $disableSslVerify = false;

/**
* AmazonCore constructor sets up key information used in all Amazon requests.
*
Expand Down Expand Up @@ -378,6 +379,10 @@ public function setConfig($path){
* @throws Exception If the file cannot be found or read.
*/
public function setLogPath($path){
if (!file_exists($path)){
touch($path);
}

if (file_exists($path) && is_readable($path)){
$this->logpath = $path;
} else {
Expand Down Expand Up @@ -607,7 +612,7 @@ protected function sendRequest($url,$param){
$this->log("Making request to Amazon: ".$this->options['Action']);
$response = $this->fetchURL($url,$param);

while ($response['code'] == '503' && $this->throttleStop==false){
while (isset($response['code']) && $response['code'] == '503' && $this->throttleStop==false){
$this->sleep();
$response = $this->fetchURL($url,$param);
}
Expand Down Expand Up @@ -742,7 +747,24 @@ protected function checkToken($xml){
$this->tokenFlag = false;
}
}


/**
* Disables or enables the use of SSL verification when sending requests to Amazon.
*
* This is <b>not recommended</b> for a production environment,
* as it is a <b>security risk</b> and can put merchant credentials in danger.
* However, this option is still available in case it is needed.
*
* Use at your own risk.
* @param boolean $b [optional] <p>Defaults to <b>TRUE</b>.</p>
*/
public function setDisableSslVerify($b = true) {
$this->disableSslVerify = $b;
if ($b) {
$this->log('Caution: Disabling SSL verification.', 'Warning');
}
}

//Functions from Athena:
/**
* Get url or send POST data
Expand All @@ -765,6 +787,11 @@ function fetchURL ($url, $param) {
curl_setopt($ch,CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch,CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_URL,$url);
if ($this->disableSslVerify) {
$this->log('Caution: Request being sent without SSL verification.', 'Warning');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
if (!empty($param)){
if (!empty($param['Header'])){
curl_setopt($ch,CURLOPT_HTTPHEADER, $param['Header']);
Expand Down
58 changes: 56 additions & 2 deletions includes/classes/AmazonFinancialEventList.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,29 @@ protected function parseXml($xml) {
$this->list['Adjustment'][] = $temp;
}
}
if (isset($xml->SAFETReimbursementEventList)) {
foreach($xml->SAFETReimbursementEventList->children() as $x) {
$temp = array();
$temp['PostedDate'] = (string)$x->PostedDate;
$temp['SAFETClaimId'] = (string)$x->SAFETClaimId;
$temp['Amount'] = (string)$x->ReimbursedAmount->CurrencyAmount;
$temp['CurrencyCode'] = (string)$x->ReimbursedAmount->CurrencyCode;
$temp['SAFETReimbursementItemList'] = array();
if (isset($x->SAFETReimbursementItemList)) {
foreach($x->SAFETReimbursementItemList->children() as $y) {
if (!isset($y->ItemChargeList)) {
continue;
}
$ztemp = array();
foreach($y->ItemChargeList->children() as $z) {
$ztemp['ItemChargeList'][] = $this->parseCharge($z);
}
$temp['SAFETReimbursementItemList'][] = $ztemp;
}
}
$this->list['SAFET'][] = $temp;
}
}
}

/**
Expand Down Expand Up @@ -542,8 +565,8 @@ protected function parseShipmentEvent($xml) {
/**
* Parses XML for a single charge into an array.
* This structure is used many times throughout shipment events.
* @param SimpleXMLElement $xml <p>The XML response from Amazon.</p>
* @return array parsed structure from XML
* @param SimpleXMLElement $xml <p>Charge node of the XML response from Amazon.</p>
* @return array Parsed structure from XML
*/
protected function parseCharge($xml) {
$r = array();
Expand Down Expand Up @@ -585,6 +608,7 @@ protected function parseFee($xml) {
* <li><b>DebtRecovery</b> - see <i>getDebtRecoveryEvents</i></li>
* <li><b>LoanServicing</b> - see <i>getLoanServicingEvents</i></li>
* <li><b>Adjustment</b> - see <i>getAdjustmentEvents</i></li>
* <li><b>SAFET</b> - see <i>getSafetEvents</i></li>
* </ul>
* @return array|boolean multi-dimensional array, or <b>FALSE</b> if list not filled yet
* @see getShipmentEvents
Expand All @@ -600,6 +624,7 @@ protected function parseFee($xml) {
* @see getDebtRecoveryEvents
* @see getLoanServicingEvents
* @see getAdjustmentEvents
* @see getSafetEvents
*/
public function getEvents(){
if (isset($this->list)){
Expand Down Expand Up @@ -991,4 +1016,33 @@ public function getAdjustmentEvents(){
}
}

/**
* Returns all SAFE-T reimbursement events.
*
* Each event array will have the following keys:
* <ul>
* <li><b>PostedDate</b> - ISO 8601 date format</li>
* <li><b>Amount</b> - number</li>
* <li><b>CurrencyCode</b> - ISO 4217 currency code</li>
* <li><b>SAFETClaimId</b></li>
* <li><b>SAFETReimbursementItemList</b> - multi-dimensional array, each array has the following keys:</li>
* <ul>
* <li><b>ItemChargeList</b> - multi-dimensional array, each array has the following keys:</li>
* <ul>
* <li><b>ChargeType</b></li>
* <li><b>Amount</b> - number</li>
* <li><b>CurrencyCode</b> - ISO 4217 currency code</li>
* </ul>
* </ul>
* </ul>
* @return array|boolean multi-dimensional array, or <b>FALSE</b> if list not filled yet
*/
public function getSafetEvents(){
if (isset($this->list['SAFET'])){
return $this->list['SAFET'];
} else {
return false;
}
}

}
97 changes: 75 additions & 22 deletions includes/classes/AmazonFulfillmentOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,7 @@ protected function parseXML($xml) {
$this->order['Details']['DeliveryWindow']['StartDateTime'] = (string)$d->DeliveryWindow->StartDateTime;
$this->order['Details']['DeliveryWindow']['EndDateTime'] = (string)$d->DeliveryWindow->EndDateTime;
}
//Address
$this->order['Details']['DestinationAddress']['Name'] = (string)$d->DestinationAddress->Name;
$this->order['Details']['DestinationAddress']['Line1'] = (string)$d->DestinationAddress->Line1;
if (isset($d->DestinationAddress->Line2)){
$this->order['Details']['DestinationAddress']['Line2'] = (string)$d->DestinationAddress->Line2;
}
if (isset($d->DestinationAddress->Line3)){
$this->order['Details']['DestinationAddress']['Line3'] = (string)$d->DestinationAddress->Line3;
}
if (isset($d->DestinationAddress->DistrictOrCounty)){
$this->order['Details']['DestinationAddress']['DistrictOrCounty'] = (string)$d->DestinationAddress->DistrictOrCounty;
}
$this->order['Details']['DestinationAddress']['City'] = (string)$d->DestinationAddress->City;
$this->order['Details']['DestinationAddress']['StateOrProvinceCode'] = (string)$d->DestinationAddress->StateOrProvinceCode;
$this->order['Details']['DestinationAddress']['CountryCode'] = (string)$d->DestinationAddress->CountryCode;
if (isset($d->DestinationAddress->PostalCode)){
$this->order['Details']['DestinationAddress']['PostalCode'] = (string)$d->DestinationAddress->PostalCode;
}
if (isset($d->DestinationAddress->PhoneNumber)){
$this->order['Details']['DestinationAddress']['PhoneNumber'] = (string)$d->DestinationAddress->PhoneNumber;
}
//End of Address
$this->order['Details']['DestinationAddress'] = $this->parseAddress($d->DestinationAddress);
if (isset($d->FulfillmentAction)){
$this->order['Details']['FulfillmentAction'] = (string)$d->FulfillmentAction;
}
Expand Down Expand Up @@ -279,6 +258,78 @@ protected function parseXML($xml) {

$i++;
}

//Section 4: Return Items
if (isset($xml->ReturnItemList)) {
foreach ($xml->ReturnItemList->children() as $x) {
$temp = array();
$temp['SellerReturnItemId'] = (string)$x->SellerReturnItemId;
$temp['SellerFulfillmentOrderItemId'] = (string)$x->SellerFulfillmentOrderItemId;
$temp['AmazonShipmentId'] = (string)$x->AmazonShipmentId;
$temp['SellerReturnReasonCode'] = (string)$x->SellerReturnReasonCode;
if (isset($x->ReturnComment)) {
$temp['ReturnComment'] = (string)$x->ReturnComment;
}
if (isset($x->AmazonReturnReasonCode)) {
$temp['AmazonReturnReasonCode'] = (string)$x->AmazonReturnReasonCode;
}
$temp['Status'] = (string)$x->Status;
$temp['StatusChangedDate'] = (string)$x->StatusChangedDate;
if (isset($x->ReturnAuthorizationId)) {
$temp['ReturnAuthorizationId'] = (string)$x->ReturnAuthorizationId;
}
if (isset($x->ReturnReceivedCondition)) {
$temp['ReturnReceivedCondition'] = (string)$x->ReturnReceivedCondition;
}
if (isset($x->FulfillmentCenterId)) {
$temp['FulfillmentCenterId'] = (string)$x->FulfillmentCenterId;
}
$this->order['ReturnItems'][] = $temp;
}
}

//Section 5: Return Authorizations
if (isset($xml->ReturnAuthorizationList)) {
foreach ($xml->ReturnAuthorizationList->children() as $x) {
$temp = array();
$temp['ReturnAuthorizationId'] = (string)$x->ReturnAuthorizationId;
$temp['FulfillmentCenterId'] = (string)$x->FulfillmentCenterId;
$temp['ReturnToAddress'] = $this->parseAddress($x->ReturnToAddress);
$temp['AmazonRmaId'] = (string)$x->AmazonRmaId;
$temp['RmaPageURL'] = (string)$x->RmaPageURL;
$this->order['ReturnAuthorizations'][] = $temp;
}
}
}

/**
* Parses XML for an address into an array.
* @param SimpleXMLElement $xml <p>Address node of the XML response from Amazon.</p>
* @return array Parsed structure from XML
*/
public function parseAddress($xml) {
$r = array();
$r['Name'] = (string)$xml->Name;
$r['Line1'] = (string)$xml->Line1;
if (isset($xml->Line2)){
$r['Line2'] = (string)$xml->Line2;
}
if (isset($xml->Line3)){
$r['Line3'] = (string)$xml->Line3;
}
if (isset($xml->DistrictOrCounty)){
$r['DistrictOrCounty'] = (string)$xml->DistrictOrCounty;
}
$r['City'] = (string)$xml->City;
$r['StateOrProvinceCode'] = (string)$xml->StateOrProvinceCode;
$r['CountryCode'] = (string)$xml->CountryCode;
if (isset($xml->PostalCode)){
$r['PostalCode'] = (string)$xml->PostalCode;
}
if (isset($xml->PhoneNumber)){
$r['PhoneNumber'] = (string)$xml->PhoneNumber;
}
return $r;
}

/**
Expand Down Expand Up @@ -323,6 +374,8 @@ public function cancelOrder(){
* <li><b>Details</b> - array of general information, such as destination address</li>
* <li><b>Items</b> - multi-dimensional array of item data</li>
* <li><b>Shipments</b> - multi-dimensional array of shipment data</li>
* <li><b>ReturnItems</b> - multi-dimensional array of return item data</li>
* <li><b>ReturnAuthorizations</b> - multi-dimensional array of return authorization data</li>
* </ul>
* @return array|boolean data array, or <b>FALSE</b> if data not filled yet
*/
Expand Down
6 changes: 6 additions & 0 deletions includes/classes/AmazonMerchantServiceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,11 @@ protected function parseXML($xml){
$this->serviceList[$i]['ShippingServiceOptions']['DeclaredValue']['Amount'] = (string)$x->ShippingServiceOptions->DeclaredValue->Amount;
$this->serviceList[$i]['ShippingServiceOptions']['DeclaredValue']['CurrencyCode'] = (string)$x->ShippingServiceOptions->DeclaredValue->CurrencyCode;
}
if (isset($x->AvailableLabelFormats)) {
foreach ($x->AvailableLabelFormats as $z) {
$this->serviceList[$i]['AvailableLabelFormats'][] = (string)$z;
}
}

$i++;
}
Expand Down Expand Up @@ -594,6 +599,7 @@ protected function parseXML($xml){
* <li><b>LatestEstimatedDeliveryDate</b></li>
* <li><b>Rate</b></li>
* <li><b>ShippingServiceOptions</b></li>
* <li><b>AvailableLabelFormats</b></li>
* </ul>
* @return array|boolean multi-dimensional array, or <b>FALSE</b> if list not filled yet
*/
Expand Down
Loading

0 comments on commit 7ab8701

Please sign in to comment.