From eb77fa466ae1cd262ce409caf3e0f94164105cba Mon Sep 17 00:00:00 2001
From: Osman Yucekaya The XML response from Amazon. Charge node of the XML response from Amazon. Address node of the XML response from Amazon. Set to TRUE to get the raw, double-encoded file contents. Label format (ex: "PNG") Up to 14 characters "AmazonOrderId" "None" or "LQHazmat" either string or number either string or number
+ *
+ * @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
+ *
+ *
+ *
+ *
+ *
+ * @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.
+ *
+ *
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: + *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 $xmlThe 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 $xmlMoney 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 $xmlFee 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: + *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 @@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