From eb77fa466ae1cd262ce409caf3e0f94164105cba Mon Sep 17 00:00:00 2001 From: Osman Yucekaya Date: Mon, 26 Sep 2016 16:19:16 +0200 Subject: [PATCH 1/9] Add touch to create the logfile if it does not exist --- includes/classes/AmazonCore.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/classes/AmazonCore.php b/includes/classes/AmazonCore.php index 3cc301b3..e44b85a8 100644 --- a/includes/classes/AmazonCore.php +++ b/includes/classes/AmazonCore.php @@ -378,6 +378,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 { From d01a7fd8cbcd1b0d37d22fad910b2ea7fe077892 Mon Sep 17 00:00:00 2001 From: Osman Yucekaya Date: Wed, 28 Sep 2016 09:58:54 +0200 Subject: [PATCH 2/9] fixed tests --- .../includes/classes/AmazonCoreTest.php | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/test-cases/includes/classes/AmazonCoreTest.php b/test-cases/includes/classes/AmazonCoreTest.php index 56c46052..09a66204 100644 --- a/test-cases/includes/classes/AmazonCoreTest.php +++ b/test-cases/includes/classes/AmazonCoreTest.php @@ -24,7 +24,11 @@ protected function setUp() { * This method is called after a test is executed. */ protected function tearDown() { - + $fileName = 'no-file.log'; + + if (file_exists($fileName)){ + @unlink($fileName); + } } /** @@ -41,7 +45,7 @@ public function mockProvider() { array('no',null, null), ); } - + /** * @covers AmazonCore::setMock * @dataProvider mockProvider @@ -69,11 +73,22 @@ public function testSetConfig() { /** * @covers AmazonCore::setLogPath - * @expectedException Exception - * @expectedExceptionMessage Log file does not exist or cannot be read! (no) */ public function testSetLogPath() { - $this->object->setLogPath('no'); + $fileName = 'no-file.log'; + + $this->object->setLogPath($fileName); + + $this->assertFileExists($fileName); + } + + /** + * @covers AmazonCore::setLogPath + * @expectedException Exception + * @expectedExceptionMessage Log file does not exist or cannot be read! () + */ + public function testSetLogPathThrowsException() { + $this->object->setLogPath(false); } /** @@ -92,7 +107,7 @@ public function testSetStore() { $this->assertEquals('Access Key ID is missing!',$bad[1]); $this->assertEquals('Secret Key is missing!',$bad[2]); } - + public function testGetOptions(){ $o = $this->object->getOptions(); $this->assertInternalType('array',$o); @@ -103,7 +118,7 @@ public function testGetOptions(){ $this->assertArrayHasKey('SignatureMethod',$o); $this->assertArrayHasKey('Version',$o); } - + } require_once('helperFunctions.php'); From e146a103de02c66429e6c2d79ef552683e8ff6a5 Mon Sep 17 00:00:00 2001 From: lukes Date: Fri, 21 Apr 2017 17:00:27 +0100 Subject: [PATCH 3/9] [bug] - added conditional check for index existence before trying to reference it. --- includes/classes/AmazonCore.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/AmazonCore.php b/includes/classes/AmazonCore.php index 3cc301b3..3d6aee5a 100644 --- a/includes/classes/AmazonCore.php +++ b/includes/classes/AmazonCore.php @@ -607,7 +607,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); } From 3a2964122d37f9b03f489c11ebac6868f91c77d9 Mon Sep 17 00:00:00 2001 From: Thomas Hernandez Date: Fri, 26 May 2017 17:11:03 -0400 Subject: [PATCH 4/9] Fixed test compatibility with PHP7 (#128) --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index af78f761..08737f50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,6 @@ php: - '5.5' - '5.6' - '7' -script: cd test-cases && phpunit --bootstrap bootstrap.php +before_script: + - wget https://phar.phpunit.de/phpunit-3.7.phar +script: cd test-cases && php ../phpunit-3.7.phar --bootstrap bootstrap.php From 33ca9883ce2538a38ea196a3510b0b3520ca1431 Mon Sep 17 00:00:00 2001 From: Thomas Hernandez Date: Thu, 29 Jun 2017 18:39:20 -0400 Subject: [PATCH 5/9] Support for New Additions Since Last Update (#130) * Added new fields since July 2016 * Added new fields to Fulfillment Order --- environment.php | 1 + includes/classes/AmazonFinancialEventList.php | 58 ++- includes/classes/AmazonFulfillmentOrder.php | 97 +++-- .../classes/AmazonMerchantServiceList.php | 6 + includes/classes/AmazonMerchantShipment.php | 12 + .../classes/AmazonMerchantShipmentCreator.php | 70 ++++ includes/classes/AmazonOrder.php | 131 ++++++- includes/classes/AmazonProductFeeEstimate.php | 348 ++++++++++++++++++ .../classes/AmazonFinancialEventListTest.php | 36 ++ .../classes/AmazonFulfillmentOrderTest.php | 54 +++ .../classes/AmazonMerchantShipmentTest.php | 104 ++++++ .../includes/classes/AmazonOrderTest.php | 66 +++- .../classes/AmazonProductFeeEstimateTest.php | 209 +++++++++++ test-cases/mock/createMerchantShipment.xml | 3 + test-cases/mock/fetchEstimates.xml | 162 ++++++++ test-cases/mock/fetchFinancialEvents.xml | 62 ++++ test-cases/mock/fetchFinancialEventsToken.xml | 23 ++ .../mock/fetchFinancialEventsToken2.xml | 23 ++ test-cases/mock/fetchFulfillmentOrder.xml | 62 ++++ test-cases/mock/fetchOrder.xml | 16 + 20 files changed, 1516 insertions(+), 27 deletions(-) create mode 100644 includes/classes/AmazonProductFeeEstimate.php create mode 100644 test-cases/includes/classes/AmazonProductFeeEstimateTest.php create mode 100644 test-cases/mock/fetchEstimates.xml diff --git a/environment.php b/environment.php index 800ef873..4d8cdebd 100644 --- a/environment.php +++ b/environment.php @@ -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; diff --git a/includes/classes/AmazonFinancialEventList.php b/includes/classes/AmazonFinancialEventList.php index fa263d13..6cef707a 100644 --- a/includes/classes/AmazonFinancialEventList.php +++ b/includes/classes/AmazonFinancialEventList.php @@ -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; + } + } } /** @@ -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

The XML response from Amazon.

- * @return array parsed structure from XML + * @param SimpleXMLElement $xml

Charge node of the XML response from Amazon.

+ * @return array Parsed structure from XML */ protected function parseCharge($xml) { $r = array(); @@ -585,6 +608,7 @@ protected function parseFee($xml) { *
  • DebtRecovery - see getDebtRecoveryEvents
  • *
  • LoanServicing - see getLoanServicingEvents
  • *
  • Adjustment - see getAdjustmentEvents
  • + *
  • SAFET - see getSafetEvents
  • * * @return array|boolean multi-dimensional array, or FALSE if list not filled yet * @see getShipmentEvents @@ -600,6 +624,7 @@ protected function parseFee($xml) { * @see getDebtRecoveryEvents * @see getLoanServicingEvents * @see getAdjustmentEvents + * @see getSafetEvents */ public function getEvents(){ if (isset($this->list)){ @@ -991,4 +1016,33 @@ public function getAdjustmentEvents(){ } } + /** + * Returns all SAFE-T reimbursement events. + * + * Each event array will have the following keys: + *
      + *
    • PostedDate - ISO 8601 date format
    • + *
    • Amount - number
    • + *
    • CurrencyCode - ISO 4217 currency code
    • + *
    • SAFETClaimId
    • + *
    • SAFETReimbursementItemList - multi-dimensional array, each array has the following keys:
    • + *
        + *
      • ItemChargeList - multi-dimensional array, each array has the following keys:
      • + *
          + *
        • ChargeType
        • + *
        • Amount - number
        • + *
        • CurrencyCode - ISO 4217 currency code
        • + *
        + *
      + *
    + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getSafetEvents(){ + if (isset($this->list['SAFET'])){ + return $this->list['SAFET']; + } else { + return false; + } + } + } diff --git a/includes/classes/AmazonFulfillmentOrder.php b/includes/classes/AmazonFulfillmentOrder.php index 499dc990..547fba93 100644 --- a/includes/classes/AmazonFulfillmentOrder.php +++ b/includes/classes/AmazonFulfillmentOrder.php @@ -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; } @@ -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

    Address node of the XML response from Amazon.

    + * @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; } /** @@ -323,6 +374,8 @@ public function cancelOrder(){ *
  • Details - array of general information, such as destination address
  • *
  • Items - multi-dimensional array of item data
  • *
  • Shipments - multi-dimensional array of shipment data
  • + *
  • ReturnItems - multi-dimensional array of return item data
  • + *
  • ReturnAuthorizations - multi-dimensional array of return authorization data
  • * * @return array|boolean data array, or FALSE if data not filled yet */ diff --git a/includes/classes/AmazonMerchantServiceList.php b/includes/classes/AmazonMerchantServiceList.php index 5fdb5212..c7f54651 100644 --- a/includes/classes/AmazonMerchantServiceList.php +++ b/includes/classes/AmazonMerchantServiceList.php @@ -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++; } @@ -594,6 +599,7 @@ protected function parseXML($xml){ *
  • LatestEstimatedDeliveryDate
  • *
  • Rate
  • *
  • ShippingServiceOptions
  • + *
  • AvailableLabelFormats
  • * * @return array|boolean multi-dimensional array, or FALSE if list not filled yet */ diff --git a/includes/classes/AmazonMerchantShipment.php b/includes/classes/AmazonMerchantShipment.php index 44900bdc..730957d8 100644 --- a/includes/classes/AmazonMerchantShipment.php +++ b/includes/classes/AmazonMerchantShipment.php @@ -145,6 +145,15 @@ protected function parseXML($xml) { $this->data['Label']['FileContents']['Contents'] = (string)$d->Label->FileContents->Contents; $this->data['Label']['FileContents']['FileType'] = (string)$d->Label->FileContents->FileType; $this->data['Label']['FileContents']['Checksum'] = (string)$d->Label->FileContents->Checksum; + if (isset($d->Label->CustomTextForLabel)) { + $this->data['Label']['CustomTextForLabel'] = (string)$d->Label->CustomTextForLabel; + } + if (isset($d->Label->LabelFormat)) { + $this->data['Label']['LabelFormat'] = (string)$d->Label->LabelFormat; + } + if (isset($d->Label->StandardIdForLabel)) { + $this->data['Label']['StandardIdForLabel'] = (string)$d->Label->StandardIdForLabel; + } } $this->data['ItemList'] = array(); @@ -548,6 +557,9 @@ public function getDeclaredValue($only = false){ *
  • Checksum
  • * * + *
  • CustomTextForLabel
  • + *
  • LabelFormat
  • + *
  • StandardIdForLabel
  • * * @param boolean $raw [optional]

    Set to TRUE to get the raw, double-encoded file contents.

    * @return array|boolean multi-dimensional array, or FALSE if label not set yet diff --git a/includes/classes/AmazonMerchantShipmentCreator.php b/includes/classes/AmazonMerchantShipmentCreator.php index 8a1f7f51..7f1ae644 100644 --- a/includes/classes/AmazonMerchantShipmentCreator.php +++ b/includes/classes/AmazonMerchantShipmentCreator.php @@ -418,6 +418,56 @@ public function setCarrierWillPickUp($b = true) { $this->options['ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp'] = $v; } + /** + * Sets the Label Format. (Optional) + * + * This method sets the label format to be sent in the next request. + * @param string $f

    Label format (ex: "PNG")

    + * @return boolean FALSE if improper input + */ + public function setLabelFormat($f) { + if (is_string($f)){ + $this->options['ShipmentRequestDetails.ShippingServiceOptions.LabelFormat'] = $f; + } else { + $this->log("Tried to set LabelFormat to invalid value",'Warning'); + return false; + } + } + + /** + * Sets the Custom Text for the Label. (Optional) + * + * This method sets the custom text for the label to be sent in the next request. + * @param string $t

    Up to 14 characters

    + * @return boolean FALSE if improper input + */ + public function setCustomText($t) { + if (is_string($t)){ + $this->options['ShipmentRequestDetails.LabelCustomization.CustomTextForLabel'] = $t; + } else { + $this->log("Tried to set CustomTextForLabel to invalid value",'Warning'); + return false; + } + } + + /** + * Sets the Standard ID for the Label. (Optional) + * + * This method sets the standard ID option for the label to be sent in the next request. + * @param string $id

    "AmazonOrderId"

    + */ + public function setLabelId($id) { + $options = array( + 'AmazonOrderId' + ); + if (in_array($id, $options)){ + $this->options['ShipmentRequestDetails.LabelCustomization.StandardIdForLabel'] = $id; + } else { + $this->log("Tried to set StandardIdForLabel to invalid value",'Warning'); + return false; + } + } + /** * Sets the Shipping Service ID. (Required) * @@ -451,6 +501,26 @@ public function setServiceOffer($id) { } } + /** + * Sets the Hazmat Type. (Optional) + * + * This method sets the hazmat type to be sent in the next request. + * @param string $h

    "None" or "LQHazmat"

    + * @return boolean FALSE if improper input + */ + public function setHazmat($h) { + $options = array( + 'None', + 'LQHazmat' + ); + if (in_array($h, $options)){ + $this->options['HazmatType'] = $h; + } else { + $this->log("Tried to set HazmatType to invalid value",'Warning'); + return false; + } + } + /** * Fetches eligible services for the shipment from Amazon using the current options. * diff --git a/includes/classes/AmazonOrder.php b/includes/classes/AmazonOrder.php index 266c841c..dc7647d3 100644 --- a/includes/classes/AmazonOrder.php +++ b/includes/classes/AmazonOrder.php @@ -70,7 +70,7 @@ public function __construct($s = null, $id = null, $data = null, $mock = false, * * This method sets the Amazon Order ID to be sent in the next request. * This parameter is required for fetching the order from Amazon. - * @param string $s

    either string or number

    + * @param string $id

    either string or number

    * @return boolean FALSE if improper input */ public function setOrderId($id){ @@ -209,6 +209,15 @@ protected function parseXML($xml){ if (isset($xml->PaymentMethod)){ $d['PaymentMethod'] = (string)$xml->PaymentMethod; } + if (isset($xml->PaymentMethodDetails)){ + foreach ($xml->PaymentMethodDetails as $x) { + $d['PaymentMethodDetails'][] = (string)$x->PaymentMethodDetail; + } + } + if (isset($xml->IsReplacementOrder)){ + $d['IsReplacementOrder'] = (string)$xml->IsReplacementOrder; + $d['ReplacedOrderId'] = (string)$xml->ReplacedOrderId; + } $d['MarketplaceId'] = (string)$xml->MarketplaceId; if (isset($xml->BuyerName)){ $d['BuyerName'] = (string)$xml->BuyerName; @@ -216,6 +225,26 @@ protected function parseXML($xml){ if (isset($xml->BuyerEmail)){ $d['BuyerEmail'] = (string)$xml->BuyerEmail; } + if (isset($xml->BuyerCounty)){ + $d['BuyerCounty'] = (string)$xml->BuyerCounty; + } + if (isset($xml->BuyerTaxInfo)){ + $d['BuyerTaxInfo'] = array(); + if (isset($xml->BuyerTaxInfo->CompanyLegalName)){ + $d['BuyerTaxInfo']['CompanyLegalName'] = (string)$xml->BuyerTaxInfo->CompanyLegalName; + } + if (isset($xml->BuyerTaxInfo->TaxingRegion)){ + $d['BuyerTaxInfo']['TaxingRegion'] = (string)$xml->BuyerTaxInfo->TaxingRegion; + } + if (isset($xml->BuyerTaxInfo->TaxClassifications)){ + foreach($xml->BuyerTaxInfo->TaxClassifications->children() as $x){ + $temp = array(); + $temp['Name'] = (string)$x->Name; + $temp['Value'] = (string)$x->Value; + $d['BuyerTaxInfo']['TaxClassifications'][] = $temp; + } + } + } if (isset($xml->ShipmentServiceLevelCategory)){ $d['ShipmentServiceLevelCategory'] = (string)$xml->ShipmentServiceLevelCategory; } @@ -281,10 +310,28 @@ protected function parseXML($xml){ *
  • NumberOfItemsUnshipped (optional) - number of items not shipped
  • *
  • PaymentExecutionDetail (optional) - multi-dimensional array, see getPaymentExecutionDetail for more details
  • *
  • PaymentMethod (optional) - "COD", "CVS", or "Other"
  • + *
  • PaymentMethodDetails (optional) - array of payment detail strings
  • + *
  • IsReplacementOrder (optional) - "true" or "false"
  • + *
  • ReplacedOrderId (optional) - Amazon Order ID, only given if IsReplacementOrder is true
  • + *
  • MarketplaceId (optional) - marketplace for the order
  • *
  • BuyerName (optional) - name of the buyer
  • *
  • BuyerEmail (optional) - Amazon-generated email for the buyer
  • + *
  • BuyerCounty (optional) - county for the buyer
  • + *
  • BuyerTaxInfo (optional) - tax information about the buyer, see getBuyerTaxInfo for more details
  • *
  • ShipmentServiceLevelCategory (optional) - "Expedited", "FreeEconomy", "NextDay", * "SameDay", "SecondDay", "Scheduled", or "Standard"
  • + *
  • ShippedByAmazonTFM (optional) - "true" or "false"
  • + *
  • TFMShipmentStatus (optional) - the status of the TFM shipment, see getTfmShipmentStatus for more details
  • + *
  • CbaDisplayableShippingLabel (optional) - customized Checkout by Amazon label of the order
  • + *
  • OrderType (optional) - "StandardOrder" or "Preorder"
  • + *
  • EarliestShipDate (optional) - time in ISO8601 date format
  • + *
  • LatestShipDate (optional) - time in ISO8601 date format
  • + *
  • EarliestDeliveryDate (optional) - time in ISO8601 date format
  • + *
  • LatestDeliveryDate (optional) - time in ISO8601 date format
  • + *
  • IsBusinessOrder (optional) - "true" or "false"
  • + *
  • PurchaseOrderNumber (optional) - the Purchase Order number entered by the buyer
  • + *
  • IsPrime (optional) - "true" or "false"
  • + *
  • IsPremiumOrder (optional) - "true" or "false"
  • * * @return array|boolean array of data, or FALSE if data not filled yet */ @@ -553,6 +600,48 @@ public function getPaymentMethod(){ return false; } } + + /** + * Returns the payment method details of the Order. + * + * This method will return FALSE if the payment method details have not been set yet. + * @return array|boolean array of detail strings, or FALSE if value not set yet + */ + public function getPaymentMethodDetails(){ + if (isset($this->data['PaymentMethodDetails'])){ + return $this->data['PaymentMethodDetails']; + } else { + return false; + } + } + + /** + * Returns an indication of whether or not the Order is a Replacement Order. + * + * This method will return FALSE if the replacement order flag has not been set yet. + * @return string|boolean "true" or "false", or FALSE if value not set yet + */ + public function getIsReplacementOrder(){ + if (isset($this->data['IsReplacementOrder'])){ + return $this->data['IsReplacementOrder']; + } else { + return false; + } + } + + /** + * Returns the ID of the Order that this Order replaces. + * + * This method will return FALSE if the replaced order ID has not been set yet. + * @return string|boolean single value, or FALSE if ID not set yet + */ + public function getReplacedOrderId(){ + if (isset($this->data['ReplacedOrderId'])){ + return $this->data['ReplacedOrderId']; + } else { + return false; + } + } /** * Returns the ID of the Marketplace in which the Order was placed. @@ -595,6 +684,44 @@ public function getBuyerEmail(){ return false; } } + + /** + * Returns the county of the buyer. + * + * This method will return FALSE if the buyer county has not been set yet. + * @return string|boolean single value, or FALSE if county not set yet + */ + public function getBuyerCounty(){ + if (isset($this->data['BuyerCounty'])){ + return $this->data['BuyerCounty']; + } else { + return false; + } + } + + /** + * Returns additional tax information about the buyer. + * + * This method will return FALSE if the tax info has not been set yet. + * The returned array has the following fields: + *
      + *
    • CompanyLegalName
    • + *
    • TaxingRegion
    • + *
    • TaxClassifications - array of arrays, each with the following keys:
    • + *
        + *
      • Name
      • + *
      • Value
      • + *
      + *
    + * @return array|boolean associative array, or FALSE if info not set yet + */ + public function getBuyerTaxInfo(){ + if (isset($this->data['BuyerTaxInfo'])){ + return $this->data['BuyerTaxInfo']; + } else { + return false; + } + } /** * Returns the shipment service level category of the Order. @@ -786,7 +913,7 @@ public function getPercentShipped(){ * Returns an indication of whether or not the Order is a business number. * * This method will return FALSE if the business order flag has not been set yet. - * @return string|boolean single value, or FALSE if value not set yet + * @return string|boolean "true" or "false", or FALSE if value not set yet */ public function getIsBusinessOrder(){ if (isset($this->data['IsBusinessOrder'])){ diff --git a/includes/classes/AmazonProductFeeEstimate.php b/includes/classes/AmazonProductFeeEstimate.php new file mode 100644 index 00000000..5cfa711b --- /dev/null +++ b/includes/classes/AmazonProductFeeEstimate.php @@ -0,0 +1,348 @@ +Name for the store you want to use. + * This parameter is optional if only one store is defined in the config file.

    + * @param boolean $mock [optional]

    This is a flag for enabling Mock Mode. + * This defaults to FALSE.

    + * @param array|string $m [optional]

    The files (or file) to use in Mock Mode.

    + * @param string $config [optional]

    An alternate config file to set. Used for testing.

    + */ + public function __construct($s = null, $mock = false, $m = null, $config = null){ + parent::__construct($s, $mock, $m, $config); + include($this->env); + + $this->options['Action'] = 'GetMyFeesEstimate'; + + if(isset($THROTTLE_TIME_PRODUCTFEE)) { + $this->throttleTime = $THROTTLE_TIME_PRODUCTFEE; + } + $this->throttleGroup = 'GetMyFeesEstimate'; + } + + /** + * Sets the estimate request(s). (Required) + * + * This method sets the list of estimate requests to be sent in the next request. + * This parameter is required for getting fee estimates from Amazon. + * The array provided should contain a list of arrays, each with the following fields: + *
      + *
    • MarketplaceId - an Amazon marketplace ID
    • + *
    • IdType - "ASIN" or "SellerSKU"
    • + *
    • IdValue - product identifier
    • + *
    • ListingPrice - array
    • + *
        + *
      • CurrencyCode - ISO 4217 currency code
      • + *
      • Value - number
      • + *
      + *
    • Shipping (optional) - array
    • + *
        + *
      • CurrencyCode - ISO 4217 currency code
      • + *
      • Value - number
      • + *
      + *
    • Points (optional) - number
    • + *
    • Identifier - unique value that will identify this request
    • + *
    • IsAmazonFulfilled - if offer is fulfilled by Amazon, boolean
    • + *
    + * @param array $a

    See above.

    + * @return boolean FALSE if improper input + */ + public function setRequests($a){ + if (!is_array($a) || !$a){ + $this->log('Tried to set Fee Estimate Requests to invalid values','Warning'); + return false; + } + $this->resetRequests(); + $i = 1; + foreach ($a as $x){ + if (is_array($x) && array_key_exists('MarketplaceId', $x) && + array_key_exists('IdType', $x) && array_key_exists('IdValue', $x) && + array_key_exists('ListingPrice', $x) && array_key_exists('Identifier', $x) && + array_key_exists('IsAmazonFulfilled', $x) && is_array($x['ListingPrice']) && + array_key_exists('CurrencyCode', $x['ListingPrice']) && + array_key_exists('Value', $x['ListingPrice'])){ + $this->options['FeesEstimateRequestList.FeesEstimateRequest.'.$i.'.MarketplaceId'] = $x['MarketplaceId']; + $this->options['FeesEstimateRequestList.FeesEstimateRequest.'.$i.'.IdType'] = $x['IdType']; + $this->options['FeesEstimateRequestList.FeesEstimateRequest.'.$i.'.IdValue'] = $x['IdValue']; + $this->options['FeesEstimateRequestList.FeesEstimateRequest.'.$i.'.ListingPrice.CurrencyCode'] = $x['ListingPrice']['CurrencyCode']; + $this->options['FeesEstimateRequestList.FeesEstimateRequest.'.$i.'.ListingPrice.Value'] = $x['ListingPrice']['Value']; + if (isset($x['Shipping']) && is_array($x['Shipping'])){ + $this->options['FeesEstimateRequestList.FeesEstimateRequest.'.$i.'.Shipping.CurrencyCode'] = $x['Shipping']['CurrencyCode']; + $this->options['FeesEstimateRequestList.FeesEstimateRequest.'.$i.'.Shipping.Value'] = $x['Shipping']['Value']; + } + if (array_key_exists('Points', $x)){ + $this->options['FeesEstimateRequestList.FeesEstimateRequest.'.$i.'.Points.PointsNumber'] = $x['Points']; + } + $this->options['FeesEstimateRequestList.FeesEstimateRequest.'.$i.'.Identifier'] = $x['Identifier']; + $this->options['FeesEstimateRequestList.FeesEstimateRequest.'.$i.'.IsAmazonFulfilled'] = $x['IsAmazonFulfilled']; + + $i++; + } else { + $this->resetRequests(); + $this->log('Tried to set Fee Estimate Requests with invalid array','Warning'); + return false; + } + } + } + + /** + * Removes request options. + * + * Since the list of requests is a required parameter, these options should not be removed + * without replacing them, so this method is not public. + */ + protected function resetRequests() { + foreach($this->options as $op=>$junk){ + if(preg_match("#FeesEstimateRequestList#",$op)){ + unset($this->options[$op]); + } + } + } + + /** + * Fetches a list of product fee estimates from Amazon. + * + * Submits a GetMyFeesEstimate request to Amazon. Amazon will send + * the list back as a response, which can be retrieved using getEstimates. + * @return boolean FALSE if something goes wrong + */ + public function fetchEstimates(){ + if (!array_key_exists('FeesEstimateRequestList.FeesEstimateRequest.1.MarketplaceId',$this->options)){ + $this->log('Fee Requests must be set in order to fetch estimates!','Warning'); + return false; + } + + $url = $this->urlbase.$this->urlbranch; + + $query = $this->genQuery(); + + $path = $this->options['Action'].'Result'; + + if ($this->mockMode){ + $xml = $this->fetchMockFile(); + } else { + $response = $this->sendRequest($url, array('Post'=>$query)); + + if (!$this->checkResponse($response)){ + return false; + } + + $xml = simplexml_load_string($response['body']); + } + + $this->parseXml($xml->$path); + } + + /** + * Parses XML response into array. + * + * This is what reads the response XML and converts it into an array. + * @param SimpleXMLElement $xml

    The XML response from Amazon.

    + * @return boolean FALSE if no XML data is found + */ + protected function parseXml($xml){ + if (!$xml){ + return false; + } + + $this->productList = array(); + if (!isset($xml->FeesEstimateResultList)){ + return; + } + foreach($xml->FeesEstimateResultList->children() as $x){ + $temp = array(); + $temp['MarketplaceId'] = (string)$x->FeesEstimateIdentifier->MarketplaceId; + $temp['IdType'] = (string)$x->FeesEstimateIdentifier->IdType; + $temp['IdValue'] = (string)$x->FeesEstimateIdentifier->IdValue; + $temp['ListingPrice'] = $this->parseMoney($x->FeesEstimateIdentifier->PriceToEstimateFees->ListingPrice); + if (isset($x->FeesEstimateIdentifier->PriceToEstimateFees->Shipping)){ + $temp['Shipping'] = $this->parseMoney($x->FeesEstimateIdentifier->PriceToEstimateFees->Shipping); + } + if (isset($x->FeesEstimateIdentifier->PriceToEstimateFees->Points->PointsNumber)){ + $temp['Points'] = (string)$x->FeesEstimateIdentifier->PriceToEstimateFees->Points->PointsNumber; + } + $temp['IsAmazonFulfilled'] = (string)$x->FeesEstimateIdentifier->IsAmazonFulfilled; + $temp['SellerInputIdentifier'] = (string)$x->FeesEstimateIdentifier->SellerInputIdentifier; + $temp['TimeOfFeesEstimation'] = (string)$x->FeesEstimateIdentifier->TimeOfFeesEstimation; + $temp['Status'] = (string)$x->Status; + if (isset($x->FeesEstimate)){ + $temp['TotalFeesEstimate'] = $this->parseMoney($x->FeesEstimate->TotalFeesEstimate); + $temp['FeeDetailList'] = array(); + if (isset($x->FeesEstimate->FeeDetailList)){ + foreach($x->FeesEstimate->FeeDetailList->children() as $z){ + $temp['FeeDetailList'][] = $this->parseFeeDetail($z); + } + } + } + if (isset($x->Error)){ + $temp['Error']['Type'] = (string)$x->Error->Type; + $temp['Error']['Code'] = (string)$x->Error->Code; + $temp['Error']['Message'] = (string)$x->Error->Message; + } + $this->productList[] = $temp; + } + } + + /** + * Parses XML for a single money element into an array. + * This structure is used many times throughout fee estimates. + * @param SimpleXMLElement $xml

    Money node of the XML response from Amazon.

    + * @return array Parsed structure from XML + */ + protected function parseMoney($xml){ + $r = array(); + $r['Amount'] = (string)$xml->Amount; + $r['CurrencyCode'] = (string)$xml->CurrencyCode; + return $r; + } + + /** + * Parses XML for a single fee detail into an array. + * This structure is used recursively in fee estimates. + * @param SimpleXMLElement $xml

    Fee Detail node of the XML response from Amazon.

    + * @return array Parsed structure from XML + */ + protected function parseFeeDetail($xml){ + $r = array(); + $r['FeeType'] = (string)$xml->FeeType; + $r['FeeAmount'] = $this->parseMoney($xml->FeeAmount); + if (isset($xml->FeePromotion)){ + $r['FeePromotion'] = $this->parseMoney($xml->FeePromotion); + } + if (isset($xml->TaxAmount)){ + $r['TaxAmount'] = $this->parseMoney($xml->TaxAmount); + } + $r['FinalFee'] = $this->parseMoney($xml->FinalFee); + if (isset($xml->IncludedFeeDetailList)){ + $r['IncludedFeeDetailList'] = array(); + foreach($xml->IncludedFeeDetailList->children() as $x){ + $r['IncludedFeeDetailList'][] = $this->parseFeeDetail($x); + } + } + return $r; + } + + /** + * Returns fee estimate specified or array of fee estimates. + * Each estimate array will have the following keys: + *
      + *
    • MarketplaceId
    • + *
    • IdType - "ASIN" or "SellerSKU"
    • + *
    • IdValue
    • + *
    • ListingPrice - money array
    • + *
    • Shipping (optional) - money array
    • + *
    • Points (optional)
    • + *
    • IsAmazonFulfilled - "true" or "false"
    • + *
    • SellerInputIdentifier
    • + *
    • TimeOfFeesEstimation - ISO 8601 date format
    • + *
    • Status
    • + *
    • TotalFeesEstimate (optional) - money array
    • + *
    • FeeDetailList (optional) - array of fee detail arrays
    • + *
    • Error (optional) - array
    • + *
        + *
      • Type
      • + *
      • Code
      • + *
      • Message
      • + *
      + *
    + * + * Each "money" array has the following keys: + *
      + *
    • Amount - number
    • + *
    • CurrencyCode - ISO 4217 currency code
    • + *
    + * Each "fee detail" array has the following keys: + *
      + *
    • FeeType - "ReferralFee", "VariableClosingFee", "PerItemFee", + * "FBAFees", "FBAPickAndPack", "FBAWeightHandling", + * "FBAOrderHandling", or "FBADeliveryServicesFee"
    • + *
    • FeeAmount - money array
    • + *
    • FeePromotion (optional) - money array
    • + *
    • TaxAmount (optional) - money array
    • + *
    • FinalFee - money array
    • + *
    • IncludedFeeDetailList (optional) - array of fee detail arrays
    • + *
    + * @param int $num [optional]

    List index to retrieve the value from.

    + * @return array|boolean multi-dimensional array, or FALSE if list not filled yet + */ + public function getEstimates($num = null){ + if (!isset($this->productList)){ + return false; + } + if (is_numeric($num)){ + return $this->productList[$num]; + } else { + return $this->productList; + } + } + + /** + * Iterator function + * @return array + */ + public function current(){ + return $this->productList[$this->i]; + } + + /** + * Iterator function + */ + public function rewind(){ + $this->i = 0; + } + + /** + * Iterator function + * @return int + */ + public function key() { + return $this->i; + } + + /** + * Iterator function + */ + public function next() { + $this->i++; + } + + /** + * Iterator function + * @return boolean + */ + public function valid() { + return isset($this->productList[$this->i]); + } + +} diff --git a/test-cases/includes/classes/AmazonFinancialEventListTest.php b/test-cases/includes/classes/AmazonFinancialEventListTest.php index 3a297d94..8480f6d1 100644 --- a/test-cases/includes/classes/AmazonFinancialEventListTest.php +++ b/test-cases/includes/classes/AmazonFinancialEventListTest.php @@ -173,6 +173,8 @@ public function testGetEvents($o) { $this->assertEquals($o->getLoanServicingEvents(), $list['LoanServicing']); $this->assertArrayHasKey('Adjustment', $list); $this->assertEquals($o->getAdjustmentEvents(), $list['Adjustment']); + $this->assertArrayHasKey('SAFET', $list); + $this->assertEquals($o->getSafetEvents(), $list['SAFET']); //not fetched yet for this object $this->assertFalse($this->object->getEvents()); } @@ -790,6 +792,40 @@ public function testGetAdjustmentEvents($o) { $this->assertFalse($this->object->getAdjustmentEvents()); } + /** + * @param AmazonFinancialEventList $o + * @depends testFetchEventList + */ + public function testGetSafetEvents($o) { + $x = array(); + $x[0]['Amount'] = '4.99'; + $x[0]['CurrencyCode'] = 'INR'; + $x[0]['PostedDate'] = '2017-01-11T13:17:15.000Z'; + $x[0]['SAFETClaimId'] = '77165-06605-4776427'; + $x[0]['SAFETReimbursementItemList'][0]['ItemChargeList'][0]['ChargeType'] = 'SAFE-T Reimbursement'; + $x[0]['SAFETReimbursementItemList'][0]['ItemChargeList'][0]['Amount'] = '25.99'; + $x[0]['SAFETReimbursementItemList'][0]['ItemChargeList'][0]['CurrencyCode'] = 'USD'; + $x[0]['SAFETReimbursementItemList'][0]['ItemChargeList'][1]['ChargeType'] = 'Test'; + $x[0]['SAFETReimbursementItemList'][0]['ItemChargeList'][1]['Amount'] = '1.99'; + $x[0]['SAFETReimbursementItemList'][0]['ItemChargeList'][1]['CurrencyCode'] = 'USD'; + $x[1]['Amount'] = '12.99'; + $x[1]['CurrencyCode'] = 'INR'; + $x[1]['PostedDate'] = '2017-02-11T14:15:16.000Z'; + $x[1]['SAFETClaimId'] = '12345-98760-8675309'; + $x[1]['SAFETReimbursementItemList'][0]['ItemChargeList'][0]['ChargeType'] = 'SAFE-T Reimbursement'; + $x[1]['SAFETReimbursementItemList'][0]['ItemChargeList'][0]['Amount'] = '29.99'; + $x[1]['SAFETReimbursementItemList'][0]['ItemChargeList'][0]['CurrencyCode'] = 'USD'; + $x[1]['SAFETReimbursementItemList'][1]['ItemChargeList'][0]['ChargeType'] = 'Double Test'; + $x[1]['SAFETReimbursementItemList'][1]['ItemChargeList'][0]['Amount'] = '22.22'; + $x[1]['SAFETReimbursementItemList'][1]['ItemChargeList'][0]['CurrencyCode'] = 'USD'; + + $list = $o->getSafetEvents(); + $this->assertInternalType('array', $list); + $this->assertEquals($x, $list); + //not fetched yet for this object + $this->assertFalse($this->object->getSafetEvents()); + } + } require_once('helperFunctions.php'); diff --git a/test-cases/includes/classes/AmazonFulfillmentOrderTest.php b/test-cases/includes/classes/AmazonFulfillmentOrderTest.php index 1d2ba5ed..54c3422a 100644 --- a/test-cases/includes/classes/AmazonFulfillmentOrderTest.php +++ b/test-cases/includes/classes/AmazonFulfillmentOrderTest.php @@ -178,6 +178,60 @@ public function testGetOrder($o){ $xs[1]['FulfillmentShipmentPackage'][0]['EstimatedArrivalDateTime'] = '2012-12-12T12:12:12Z'; $x['Shipments'] = $xs; + + $xr = array(); + $xr[0]['SellerReturnItemId'] = '16a6a142EXAMPLE'; + $xr[1]['SellerReturnItemId'] = '16a6a142EXAMPLE2'; + $xr[0]['SellerFulfillmentOrderItemId'] = 'order-item-1'; + $xr[1]['SellerFulfillmentOrderItemId'] = 'order-item-2'; + $xr[0]['AmazonShipmentId'] = 'DLHg36GDN'; + $xr[1]['AmazonShipmentId'] = 'DKMKLXJmN'; + $xr[0]['SellerReturnReasonCode'] = 'REASON-CODE'; + $xr[1]['SellerReturnReasonCode'] = 'REASON-CODE-2'; + $xr[0]['ReturnComment'] = 'Did not like color'; + $xr[1]['ReturnComment'] = 'Did not like shape'; + $xr[0]['AmazonReturnReasonCode'] = 'OTHER-REASON-CODE'; + $xr[1]['AmazonReturnReasonCode'] = 'OTHER-REASON-CODE-2'; + $xr[0]['Status'] = 'Processed'; + $xr[1]['Status'] = 'Processed2'; + $xr[0]['StatusChangedDate'] = '2016-09-02T02:40:36Z'; + $xr[1]['StatusChangedDate'] = '2016-09-08T02:40:36Z'; + $xr[0]['ReturnAuthorizationId'] = 'amzn-rma-id'; + $xr[1]['ReturnAuthorizationId'] = 'amzn-rma-id-2'; + $xr[0]['ReturnReceivedCondition'] = 'Sellable'; + $xr[1]['ReturnReceivedCondition'] = 'Sellable2'; + $xr[0]['FulfillmentCenterId'] = 'FC123'; + $xr[1]['FulfillmentCenterId'] = 'FC321'; + + $x['ReturnItems'] = $xr; + + $xa = array(); + $xa[0]['ReturnAuthorizationId'] = 'amzn-rma-id'; + $xa[1]['ReturnAuthorizationId'] = 'amzn-rma-id-2'; + $xa[0]['FulfillmentCenterId'] = 'FC123'; + $xa[1]['FulfillmentCenterId'] = 'FC321'; + $xa[0]['ReturnToAddress']['Name'] = 'Amazon FC'; + $xa[1]['ReturnToAddress']['Name'] = 'Amazon FC2'; + $xa[0]['ReturnToAddress']['Line1'] = '123 Main Street'; + $xa[1]['ReturnToAddress']['Line1'] = '321 Main Street'; + $xa[0]['ReturnToAddress']['Line2'] = 'Suite 16'; + $xa[0]['ReturnToAddress']['Line3'] = 'Hole in Wall'; + $xa[0]['ReturnToAddress']['DistrictOrCounty'] = 'Ninth'; + $xa[0]['ReturnToAddress']['City'] = 'Anywhere'; + $xa[1]['ReturnToAddress']['City'] = 'Somewhere'; + $xa[0]['ReturnToAddress']['StateOrProvinceCode'] = 'WA'; + $xa[1]['ReturnToAddress']['StateOrProvinceCode'] = 'WA'; + $xa[0]['ReturnToAddress']['CountryCode'] = 'US'; + $xa[1]['ReturnToAddress']['CountryCode'] = 'US'; + $xa[0]['ReturnToAddress']['PostalCode'] = '98122'; + $xa[1]['ReturnToAddress']['PostalCode'] = '98123'; + $xa[0]['ReturnToAddress']['PhoneNumber'] = '555-867-5309'; + $xa[0]['AmazonRmaId'] = 'test123'; + $xa[1]['AmazonRmaId'] = 'test321'; + $xa[0]['RmaPageURL'] = 'https://sellercentral.amazon.com/URL'; + $xa[1]['RmaPageURL'] = 'https://sellercentral.amazon.com/URL#2'; + + $x['ReturnAuthorizations'] = $xa; $this->assertEquals($x,$get); diff --git a/test-cases/includes/classes/AmazonMerchantShipmentTest.php b/test-cases/includes/classes/AmazonMerchantShipmentTest.php index 482b015e..bd5599b5 100644 --- a/test-cases/includes/classes/AmazonMerchantShipmentTest.php +++ b/test-cases/includes/classes/AmazonMerchantShipmentTest.php @@ -275,6 +275,107 @@ public function testSetCarrierWillPickUp() { $this->assertEquals('false', $o4[$key]); } + public function testSetLabelFormat() { + $key = 'ShipmentRequestDetails.ShippingServiceOptions.LabelFormat'; + $this->assertNull($this->object->setLabelFormat('PNG')); + $o = $this->object->getOptions(); + $this->assertArrayHasKey($key, $o); + $this->assertEquals('PNG', $o[$key]); + + $this->assertFalse($this->object->setLabelFormat(77)); //won't work for this + $this->assertFalse($this->object->setLabelFormat(array())); //won't work for this + $this->assertFalse($this->object->setLabelFormat(null)); //won't work for other things + + $check = parseLog(); + $this->assertEquals('Tried to set LabelFormat to invalid value',$check[1]); + $this->assertEquals('Tried to set LabelFormat to invalid value',$check[2]); + $this->assertEquals('Tried to set LabelFormat to invalid value',$check[3]); + } + + public function testSetCustomText() { + $key = 'ShipmentRequestDetails.LabelCustomization.CustomTextForLabel'; + $this->assertNull($this->object->setCustomText('Very Neat')); + $o = $this->object->getOptions(); + $this->assertArrayHasKey($key, $o); + $this->assertEquals('Very Neat', $o[$key]); + + $this->assertFalse($this->object->setCustomText(77)); //won't work for this + $this->assertFalse($this->object->setCustomText(array())); //won't work for this + $this->assertFalse($this->object->setCustomText(null)); //won't work for other things + + $check = parseLog(); + $this->assertEquals('Tried to set CustomTextForLabel to invalid value',$check[1]); + $this->assertEquals('Tried to set CustomTextForLabel to invalid value',$check[2]); + $this->assertEquals('Tried to set CustomTextForLabel to invalid value',$check[3]); + } + + public function testSetLabelId() { + $key = 'ShipmentRequestDetails.LabelCustomization.StandardIdForLabel'; + $this->assertNull($this->object->setLabelId('AmazonOrderId')); + $o = $this->object->getOptions(); + $this->assertArrayHasKey($key, $o); + $this->assertEquals('AmazonOrderId', $o[$key]); + + $this->assertFalse($this->object->setLabelId('something')); //won't work for this + $this->assertFalse($this->object->setLabelId(array())); //won't work for other things + $this->assertFalse($this->object->setLabelId(null)); //won't work for other things + + $check = parseLog(); + $this->assertEquals('Tried to set StandardIdForLabel to invalid value',$check[1]); + $this->assertEquals('Tried to set StandardIdForLabel to invalid value',$check[2]); + $this->assertEquals('Tried to set StandardIdForLabel to invalid value',$check[3]); + } + + public function testSetService() { + $key = 'ShippingServiceId'; + $this->assertNull($this->object->setService('Ground')); + $o = $this->object->getOptions(); + $this->assertArrayHasKey($key, $o); + $this->assertEquals('Ground', $o[$key]); + + $this->assertFalse($this->object->setService(77)); //won't work for this + $this->assertFalse($this->object->setService(array())); //won't work for this + $this->assertFalse($this->object->setService(null)); //won't work for other things + + $check = parseLog(); + $this->assertEquals('Tried to set ShippingServiceId to invalid value',$check[1]); + $this->assertEquals('Tried to set ShippingServiceId to invalid value',$check[2]); + $this->assertEquals('Tried to set ShippingServiceId to invalid value',$check[3]); + } + + public function testSetServiceOffer() { + $key = 'ShippingServiceOfferId'; + $this->assertNull($this->object->setServiceOffer('123ABC')); + $o = $this->object->getOptions(); + $this->assertArrayHasKey($key, $o); + $this->assertEquals('123ABC', $o[$key]); + + $this->assertFalse($this->object->setServiceOffer(77)); //won't work for this + $this->assertFalse($this->object->setServiceOffer(array())); //won't work for this + $this->assertFalse($this->object->setServiceOffer(null)); //won't work for other things + + $check = parseLog(); + $this->assertEquals('Tried to set ShippingServiceOfferId to invalid value',$check[1]); + $this->assertEquals('Tried to set ShippingServiceOfferId to invalid value',$check[2]); + $this->assertEquals('Tried to set ShippingServiceOfferId to invalid value',$check[3]); + } + + public function testSetHazmat() { + $key = 'HazmatType'; + $this->assertNull($this->object->setHazmat('LQHazmat')); + $o = $this->object->getOptions(); + $this->assertArrayHasKey($key, $o); + $this->assertEquals('LQHazmat', $o[$key]); + + $this->assertFalse($this->object->setHazmat('something')); //won't work for this + $this->assertFalse($this->object->setHazmat(array())); //won't work for other things + $this->assertFalse($this->object->setHazmat(null)); //won't work for other things + + $check = parseLog(); + $this->assertEquals('Tried to set HazmatType to invalid value',$check[1]); + $this->assertEquals('Tried to set HazmatType to invalid value',$check[2]); + $this->assertEquals('Tried to set HazmatType to invalid value',$check[3]); + } public function testCreateShipment(){ resetLog(); @@ -515,6 +616,9 @@ public function testGetLabelData($o) { $x['FileContents']['Contents'] = 'This is a test'; $x['FileContents']['FileType'] = 'application/pdf'; $x['FileContents']['Checksum'] = 'DmsWbJpdMPALN3jV4wHOrg=='; + $x['CustomTextForLabel'] = 'Wow Cool'; + $x['LabelFormat'] = 'ZPL203'; + $x['StandardIdForLabel'] = 'AmazonOrderId'; $this->assertEquals($x, $get); $this->assertEquals($x['FileContents']['Contents'], $o->getLabelFileContents()); diff --git a/test-cases/includes/classes/AmazonOrderTest.php b/test-cases/includes/classes/AmazonOrderTest.php index f831a74f..75dfe13f 100644 --- a/test-cases/includes/classes/AmazonOrderTest.php +++ b/test-cases/includes/classes/AmazonOrderTest.php @@ -123,9 +123,17 @@ public function testGetData($o){ $x['PaymentExecutionDetail'][1]['CurrencyCode'] = 'USD'; $x['PaymentExecutionDetail'][1]['SubPaymentMethod'] = 'GC'; $x['PaymentMethod'] = 'COD'; + $x['PaymentMethodDetails'][0] = 'CreditCard'; + $x['IsReplacementOrder'] = 'true'; + $x['ReplacedOrderId'] = '555-1233752-8214740'; $x['MarketplaceId'] = 'ATVPDKIKX0DER'; $x['BuyerName'] = 'Amazon User'; $x['BuyerEmail'] = '5vlh04mgfmjh9h5@marketplace.amazon.com'; + $x['BuyerCounty'] = 'Best'; + $x['BuyerTaxInfo']['CompanyLegalName'] = 'Company Name'; + $x['BuyerTaxInfo']['TaxingRegion'] = 'US'; + $x['BuyerTaxInfo']['TaxClassifications'][0]['Name'] = 'VATNumber'; + $x['BuyerTaxInfo']['TaxClassifications'][0]['Value'] = 'XXX123'; $x['ShipmentServiceLevelCategory'] = 'Standard'; $x['CbaDisplayableShippingLabel'] = 'Best'; $x['ShippedByAmazonTFM'] = 'false'; @@ -326,6 +334,37 @@ public function testGetPaymentMethod($o){ $this->assertFalse($this->object->getPaymentMethod()); //not fetched yet for this object } + + /** + * @depends testFetchOrder + */ + public function testGetPaymentMethodDetails($o){ + $get = $o->getPaymentMethodDetails(); + $x = array('CreditCard'); + $this->assertEquals($x, $get); + + $this->assertFalse($this->object->getPaymentMethodDetails()); //not fetched yet for this object + } + + /** + * @depends testFetchOrder + */ + public function testGetIsReplacementOrder($o){ + $get = $o->getIsReplacementOrder(); + $this->assertEquals('true',$get); + + $this->assertFalse($this->object->getIsReplacementOrder()); //not fetched yet for this object + } + + /** + * @depends testFetchOrder + */ + public function testGetReplacedOrderId($o){ + $get = $o->getReplacedOrderId(); + $this->assertEquals('555-1233752-8214740',$get); + + $this->assertFalse($this->object->getReplacedOrderId()); //not fetched yet for this object + } /** * @depends testFetchOrder @@ -356,6 +395,31 @@ public function testGetBuyerEmail($o){ $this->assertFalse($this->object->getBuyerEmail()); //not fetched yet for this object } + + /** + * @depends testFetchOrder + */ + public function testGetBuyerCounty($o){ + $get = $o->getBuyerCounty(); + $this->assertEquals('Best', $get); + + $this->assertFalse($this->object->getBuyerCounty()); //not fetched yet for this object + } + + /** + * @depends testFetchOrder + */ + public function testGetBuyerTaxInfo($o){ + $get = $o->getBuyerTaxInfo(); + $x = array(); + $x['CompanyLegalName'] = 'Company Name'; + $x['TaxingRegion'] = 'US'; + $x['TaxClassifications'][0]['Name'] = 'VATNumber'; + $x['TaxClassifications'][0]['Value'] = 'XXX123'; + $this->assertEquals($x, $get); + + $this->assertFalse($this->object->getBuyerTaxInfo()); //not fetched yet for this object + } /** * @depends testFetchOrder @@ -421,7 +485,7 @@ public function testGetEarliestShipDate($o) { * @depends testFetchOrder * @param AmazonOrder $o */ - public function testgetLatestShipDate($o) { + public function testGetLatestShipDate($o) { $this->assertEquals('2010-10-07T12:43:16.000Z', $o->getLatestShipDate()); $this->assertFalse($this->object->getLatestShipDate()); //not fetched yet for this object diff --git a/test-cases/includes/classes/AmazonProductFeeEstimateTest.php b/test-cases/includes/classes/AmazonProductFeeEstimateTest.php new file mode 100644 index 00000000..3c40a593 --- /dev/null +++ b/test-cases/includes/classes/AmazonProductFeeEstimateTest.php @@ -0,0 +1,209 @@ +object = new AmazonProductFeeEstimate('testStore', true, null, __DIR__.'/../../test-config.php'); + } + + public function testSetRequest() { + //bad input + $this->assertFalse($this->object->setRequests(null)); + $this->assertFalse($this->object->setRequests(123)); + $this->assertFalse($this->object->setRequests('word')); + $this->assertFalse($this->object->setRequests(array())); + $this->assertFalse($this->object->setRequests(array(123))); + $this->assertFalse($this->object->setRequests(array('word'))); + + $op = array(); + $this->assertFalse($this->object->setRequests(array($op))); //missing keys + + $op['MarketplaceId'] = 'Marketplace'; + $this->assertFalse($this->object->setRequests(array($op))); //still missing keys + $op['IdType'] = 'ASIN'; + $this->assertFalse($this->object->setRequests(array($op))); //still missing keys + $op['IdValue'] = 'B00123ASIN'; + $this->assertFalse($this->object->setRequests(array($op))); //still missing keys + $op['ListingPrice'] = array(); + $this->assertFalse($this->object->setRequests(array($op))); //still missing keys + $op['ListingPrice']['CurrencyCode'] = 'USD'; + $this->assertFalse($this->object->setRequests(array($op))); //still missing keys + $op['ListingPrice']['Value'] = '123'; + $this->assertFalse($this->object->setRequests(array($op))); //still missing keys + $op['Identifier'] = 'TEST123'; + $this->assertFalse($this->object->setRequests(array($op))); //still missing keys + $op['IsAmazonFulfilled'] = 'false'; + $this->assertNull($this->object->setRequests(array($op))); //finally good + + //test doubles + $op2 = $op; + $op2['MarketplaceId'] = 'Mark II'; + $op2['Shipping']['CurrencyCode'] = 'USD'; + $op2['Shipping']['Value'] = '1.23'; + $op2['Points'] = '3'; + $this->assertNull($this->object->setRequests(array($op, $op2))); + + //verify options were set correctly + $o = $this->object->getOptions(); + $pre = 'FeesEstimateRequestList.FeesEstimateRequest.'; + $this->assertArrayHasKey($pre.'1.MarketplaceId', $o); + $this->assertEquals('Marketplace', $o[$pre.'1.MarketplaceId']); + $this->assertArrayHasKey($pre.'1.IdType', $o); + $this->assertEquals('ASIN', $o[$pre.'1.IdType']); + $this->assertArrayHasKey($pre.'1.IdValue', $o); + $this->assertEquals('B00123ASIN', $o[$pre.'1.IdValue']); + $this->assertArrayHasKey($pre.'1.ListingPrice.CurrencyCode', $o); + $this->assertEquals('USD', $o[$pre.'1.ListingPrice.CurrencyCode']); + $this->assertArrayHasKey($pre.'1.ListingPrice.Value', $o); + $this->assertEquals('123', $o[$pre.'1.ListingPrice.Value']); + $this->assertArrayHasKey($pre.'1.Identifier', $o); + $this->assertEquals('TEST123', $o[$pre.'1.Identifier']); + $this->assertArrayHasKey($pre.'1.IsAmazonFulfilled', $o); + $this->assertEquals('false', $o[$pre.'1.IsAmazonFulfilled']); + $this->assertArrayHasKey($pre.'2.MarketplaceId', $o); + $this->assertEquals('Mark II', $o[$pre.'2.MarketplaceId']); + $this->assertArrayHasKey($pre.'2.Shipping.CurrencyCode', $o); + $this->assertEquals('USD', $o[$pre.'2.Shipping.CurrencyCode']); + $this->assertArrayHasKey($pre.'2.Shipping.Value', $o); + $this->assertEquals('1.23', $o[$pre.'2.Shipping.Value']); + $this->assertArrayHasKey($pre.'2.Points.PointsNumber', $o); + $this->assertEquals('3', $o[$pre.'2.Points.PointsNumber']); + + //setting again should reset + $this->assertNull($this->object->setRequests(array($op))); + $o2 = $this->object->getOptions(); + $this->assertArrayHasKey($pre.'1.MarketplaceId', $o2); + $this->assertArrayNotHasKey($pre.'2.MarketplaceId', $o2); + $this->assertArrayNotHasKey($pre.'3.MarketplaceId', $o2); + + //check logs + $check = parseLog(); + $err1 = 'Tried to set Fee Estimate Requests to invalid values'; + $err2 = 'Tried to set Fee Estimate Requests with invalid array'; + $this->assertEquals($err1, $check[1]); + $this->assertEquals($err1, $check[2]); + $this->assertEquals($err1, $check[3]); + $this->assertEquals($err1, $check[4]); + $this->assertEquals($err2, $check[5]); + $this->assertEquals($err2, $check[6]); + $this->assertEquals($err2, $check[7]); + $this->assertEquals($err2, $check[8]); + $this->assertEquals($err2, $check[9]); + $this->assertEquals($err2, $check[10]); + $this->assertEquals($err2, $check[11]); + $this->assertEquals($err2, $check[12]); + $this->assertEquals($err2, $check[13]); + $this->assertEquals($err2, $check[14]); + + return $this->object; + } + + /** + * @depends testSetRequest + * @param AmazonProductFeeEstimate $o + */ + public function testFetchEstimates($o) { + resetLog(); + $this->object->setMock(true, 'fetchEstimates.xml'); + $this->assertFalse($this->object->getEstimates()); //no data yet + $this->assertFalse($this->object->fetchEstimates()); //no requests yet + $o->setMock(true, 'fetchEstimates.xml'); + $this->assertNull($o->fetchEstimates()); //good, request already set + + $check = parseLog(); + $this->assertEquals('Single Mock File set: fetchEstimates.xml', $check[1]); + $this->assertEquals('Fee Requests must be set in order to fetch estimates!', $check[2]); + + return $o; + } + + /** + * @depends testFetchEstimates + * @param AmazonProductFeeEstimate $o + */ + public function testGetEstimates($o) { + $get = $o->getEstimates(); + $this->assertInternalType('array', $get); + $x = array(); + $x[0]['MarketplaceId'] = 'ATVPDKIKX0DER'; + $x[0]['IdType'] = 'ASIN'; + $x[0]['IdValue'] = 'B0002GTTRC'; + $x[0]['ListingPrice']['Amount'] = '58.00'; + $x[0]['ListingPrice']['CurrencyCode'] = 'USD'; + $x[0]['Shipping']['Amount'] = '0.01'; + $x[0]['Shipping']['CurrencyCode'] = 'USD'; + $x[0]['Points'] = '1'; + $x[0]['IsAmazonFulfilled'] = 'True'; + $x[0]['SellerInputIdentifier'] = 'IDDDDDDDD'; + $x[0]['TimeOfFeesEstimation'] = '2015-07-19T23:15:11.859Z'; + $x[0]['Status'] = 'Success'; + $x[0]['TotalFeesEstimate']['Amount'] = '10.00'; + $x[0]['TotalFeesEstimate']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][0]['FeeType'] = 'AmazonReferralFee'; + $x[0]['FeeDetailList'][0]['FeeAmount']['Amount'] = '8.70'; + $x[0]['FeeDetailList'][0]['FeeAmount']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][0]['FeePromotion']['Amount'] = '1.00'; + $x[0]['FeeDetailList'][0]['FeePromotion']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][0]['FinalFee']['Amount'] = '7.70'; + $x[0]['FeeDetailList'][0]['FinalFee']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][1]['FeeType'] = 'VariableClosingFee'; + $x[0]['FeeDetailList'][1]['FeeAmount']['Amount'] = '0.01'; + $x[0]['FeeDetailList'][1]['FeeAmount']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][1]['FinalFee']['Amount'] = '0.02'; + $x[0]['FeeDetailList'][1]['FinalFee']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][2]['FeeType'] = 'FulfillmentFees'; + $x[0]['FeeDetailList'][2]['FeeAmount']['Amount'] = '2.30'; + $x[0]['FeeDetailList'][2]['FeeAmount']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][2]['FinalFee']['Amount'] = '2.31'; + $x[0]['FeeDetailList'][2]['FinalFee']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][0]['FeeType'] = 'OrderHandlingFee'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][0]['FeeAmount']['Amount'] = '1.00'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][0]['FeeAmount']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][0]['FinalFee']['Amount'] = '1.01'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][0]['FinalFee']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][1]['FeeType'] = 'PickAndPackFee'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][1]['FeeAmount']['Amount'] = '0.30'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][1]['FeeAmount']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][1]['FinalFee']['Amount'] = '0.31'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][1]['FinalFee']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][2]['FeeType'] = 'WeightHandlingFee'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][2]['FeeAmount']['Amount'] = '1.00'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][2]['FeeAmount']['CurrencyCode'] = 'USD'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][2]['FinalFee']['Amount'] = '1.01'; + $x[0]['FeeDetailList'][2]['IncludedFeeDetailList'][2]['FinalFee']['CurrencyCode'] = 'USD'; + $x[1]['MarketplaceId'] = 'ATVPDKIKX0DER'; + $x[1]['IdType'] = 'ASIN'; + $x[1]['IdValue'] = 'B00032ASIN'; + $x[1]['ListingPrice']['Amount'] = '58.00'; + $x[1]['ListingPrice']['CurrencyCode'] = 'USD'; + $x[1]['Shipping']['Amount'] = '0.00'; + $x[1]['Shipping']['CurrencyCode'] = 'USD'; + $x[1]['Points'] = '100'; + $x[1]['IsAmazonFulfilled'] = 'True'; + $x[1]['SellerInputIdentifier'] = 'IDDDDDDDD2'; + $x[1]['TimeOfFeesEstimation'] = '2015-07-20T12:13:14.000Z'; + $x[1]['Status'] = 'Success'; + $x[1]['TotalFeesEstimate']['Amount'] = '10.00'; + $x[1]['TotalFeesEstimate']['CurrencyCode'] = 'USD'; + $x[1]['FeeDetailList'][0]['FeeType'] = 'AmazonReferralFee'; + $x[1]['FeeDetailList'][0]['FeeAmount']['Amount'] = '2.24'; + $x[1]['FeeDetailList'][0]['FeeAmount']['CurrencyCode'] = 'USD'; + $x[1]['FeeDetailList'][0]['FeePromotion']['Amount'] = '1.01'; + $x[1]['FeeDetailList'][0]['FeePromotion']['CurrencyCode'] = 'USD'; + $x[1]['FeeDetailList'][0]['FinalFee']['Amount'] = '1.23'; + $x[1]['FeeDetailList'][0]['FinalFee']['CurrencyCode'] = 'USD'; + $this->assertEquals($x, $get); + $this->assertFalse($this->object->getEstimates()); //not fetched yet for this object + } + +} diff --git a/test-cases/mock/createMerchantShipment.xml b/test-cases/mock/createMerchantShipment.xml index 12047f47..dfc1d18b 100644 --- a/test-cases/mock/createMerchantShipment.xml +++ b/test-cases/mock/createMerchantShipment.xml @@ -32,6 +32,9 @@ 11.00000 inches + Wow Cool + ZPL203 + AmazonOrderId FEDEX diff --git a/test-cases/mock/fetchEstimates.xml b/test-cases/mock/fetchEstimates.xml new file mode 100644 index 00000000..35ac0e3d --- /dev/null +++ b/test-cases/mock/fetchEstimates.xml @@ -0,0 +1,162 @@ + + + + + + Success + + ATVPDKIKX0DER + B0002GTTRC + ASIN + True + + + USD + 58.00 + + + USD + 0.01 + + + 1 + + + IDDDDDDDD + 2015-07-19T23:15:11.859Z + + + + USD + 10.00 + + + + AmazonReferralFee + + USD + 8.70 + + + USD + 1.00 + + + USD + 7.70 + + + + VariableClosingFee + + USD + 0.01 + + + USD + 0.02 + + + + FulfillmentFees + + USD + 2.30 + + + USD + 2.31 + + + + OrderHandlingFee + + USD + 1.00 + + + USD + 1.01 + + + + PickAndPackFee + + USD + 0.30 + + + USD + 0.31 + + + + WeightHandlingFee + + USD + 1.00 + + + USD + 1.01 + + + + + + + + + Success + + ATVPDKIKX0DER + B00032ASIN + ASIN + True + + + USD + 58.00 + + + USD + 0.00 + + + 100 + + + IDDDDDDDD2 + 2015-07-20T12:13:14.000Z + + + + USD + 10.00 + + + + AmazonReferralFee + + USD + 2.24 + + + USD + 1.01 + + + USD + 1.23 + + + + + + + + + 21534f03-e7e3-4d9a-9bea-0e15add3326d + + diff --git a/test-cases/mock/fetchFinancialEvents.xml b/test-cases/mock/fetchFinancialEvents.xml index 9a22cceb..c41cf57a 100644 --- a/test-cases/mock/fetchFinancialEvents.xml +++ b/test-cases/mock/fetchFinancialEvents.xml @@ -977,6 +977,68 @@ + + + 2017-01-11T13:17:15.000Z + 77165-06605-4776427 + + 4.99 + INR + + + + + + SAFE-T Reimbursement + + 25.99 + USD + + + + Test + + 1.99 + USD + + + + + + + + 2017-02-11T14:15:16.000Z + 12345-98760-8675309 + + 12.99 + INR + + + + + + SAFE-T Reimbursement + + 29.99 + USD + + + + + + + + Double Test + + 22.22 + USD + + + + + + + diff --git a/test-cases/mock/fetchFinancialEventsToken.xml b/test-cases/mock/fetchFinancialEventsToken.xml index 404aa881..5b9d557a 100644 --- a/test-cases/mock/fetchFinancialEventsToken.xml +++ b/test-cases/mock/fetchFinancialEventsToken.xml @@ -660,6 +660,29 @@ + + + 2017-01-11T13:17:15.000Z + 77165-06605-4776427 + + 4.99 + INR + + + + + + SAFE-T Reimbursement + + 25.99 + USD + + + + + + + diff --git a/test-cases/mock/fetchFinancialEventsToken2.xml b/test-cases/mock/fetchFinancialEventsToken2.xml index 889c4378..13eaa7fe 100644 --- a/test-cases/mock/fetchFinancialEventsToken2.xml +++ b/test-cases/mock/fetchFinancialEventsToken2.xml @@ -346,6 +346,29 @@ + + + 2017-02-11T14:15:16.000Z + 12345-98760-8675309 + + 12.99 + INR + + + + + + SAFE-T Reimbursement + + 29.99 + USD + + + + + + + diff --git a/test-cases/mock/fetchFulfillmentOrder.xml b/test-cases/mock/fetchFulfillmentOrder.xml index 52df3c61..aa89c676 100644 --- a/test-cases/mock/fetchFulfillmentOrder.xml +++ b/test-cases/mock/fetchFulfillmentOrder.xml @@ -132,6 +132,68 @@ 2006-08-12T07:00:00Z + + + 16a6a142EXAMPLE + order-item-1 + DLHg36GDN + REASON-CODE + Did not like color + OTHER-REASON-CODE + Processed + 2016-09-02T02:40:36Z + amzn-rma-id + Sellable + FC123 + + + 16a6a142EXAMPLE2 + order-item-2 + DKMKLXJmN + REASON-CODE-2 + Did not like shape + OTHER-REASON-CODE-2 + Processed2 + 2016-09-08T02:40:36Z + amzn-rma-id-2 + Sellable2 + FC321 + + + + + amzn-rma-id + FC123 + + Amazon FC + 123 Main Street + Suite 16 + Hole in Wall + Ninth + Anywhere + WA + US + 98122 + 555-867-5309 + + test123 + https://sellercentral.amazon.com/URL + + + amzn-rma-id-2 + FC321 + + Amazon FC2 + 321 Main Street + Somewhere + WA + US + 98123 + + test321 + https://sellercentral.amazon.com/URL#2 + + 5e5e5694-8e76-11df-929f-87c80302f8f6 diff --git a/test-cases/mock/fetchOrder.xml b/test-cases/mock/fetchOrder.xml index 7c69233e..0fe99a0a 100644 --- a/test-cases/mock/fetchOrder.xml +++ b/test-cases/mock/fetchOrder.xml @@ -50,9 +50,25 @@ COD + + CreditCard + + true + 555-1233752-8214740 ATVPDKIKX0DER Amazon User 5vlh04mgfmjh9h5@marketplace.amazon.com + Best + + Company Name + US + + + VATNumber + XXX123 + + + Standard Best false From f793832472a2729c1843b5720438ab943ef51055 Mon Sep 17 00:00:00 2001 From: Thomas Hernandez Date: Fri, 21 Jul 2017 17:52:39 -0400 Subject: [PATCH 6/9] Allows disabled SSL verification (#132) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * permitimos deshabilitar SSL en la peticiĆ³n curl interna * Added warnings to SSL disabling --- includes/classes/AmazonCore.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/includes/classes/AmazonCore.php b/includes/classes/AmazonCore.php index c8b477bb..348d0c7a 100644 --- a/includes/classes/AmazonCore.php +++ b/includes/classes/AmazonCore.php @@ -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. * @@ -746,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 not recommended for a production environment, + * as it is a security risk 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]

    Defaults to TRUE.

    + */ + 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 @@ -769,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']); From 4b3603eb4efe39f1114ae99da2dcf05492ffc83d Mon Sep 17 00:00:00 2001 From: Hugo Zonderland Date: Fri, 8 Sep 2017 19:38:27 +0200 Subject: [PATCH 7/9] Update composer.json & travis.yml (#138) * Update composer.json: Limited the phpunit version to max 5.7.20 to fix Travis * Update composer.json: Composer.json jshint fix * Update .travis.yml: Merge with the patch-2 branch * Fully fixed formatting for composer.json and minor tweaks to the allowed failures matrix * explicitly tell Travis to install packages * use the vendor binary --- .travis.yml | 27 +++++++++++++++++++++------ composer.json | 20 +++++++++++++------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 08737f50..a89d0130 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,24 @@ language: php php: - - '5.4' - - '5.5' - - '5.6' - - '7' + - 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: - - wget https://phar.phpunit.de/phpunit-3.7.phar -script: cd test-cases && php ../phpunit-3.7.phar --bootstrap bootstrap.php + - vendor/bin/phpunit --version + +# run the test suite +script: cd test-cases && php ../vendor/bin/phpunit --bootstrap bootstrap.php diff --git a/composer.json b/composer.json index 10c0a2dd..086e7fd6 100644 --- a/composer.json +++ b/composer.json @@ -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/" + ] } } From cef73c2a73281231d44f0a190b9f0bffccc99571 Mon Sep 17 00:00:00 2001 From: Thomas Hernandez Date: Fri, 29 Sep 2017 18:42:13 -0400 Subject: [PATCH 8/9] Updated change log with upcoming 1.4.0 --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89f32937..6f3139bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 - TBD +### 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 From b3e6b0c97c039782324e541752399391ab2215f5 Mon Sep 17 00:00:00 2001 From: Thomas Hernandez Date: Fri, 17 Nov 2017 12:51:31 -0500 Subject: [PATCH 9/9] Added release date for version 1.4 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f3139bb..becd5e3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## 1.4.0 - TBD +## 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)