Skip to content

Commit 33ca988

Browse files
authored
Support for New Additions Since Last Update (CPIGroup#130)
* Added new fields since July 2016 * Added new fields to Fulfillment Order
1 parent 3a29641 commit 33ca988

20 files changed

+1516
-27
lines changed

environment.php

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

includes/classes/AmazonFinancialEventList.php

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

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

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

includes/classes/AmazonFulfillmentOrder.php

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

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

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

includes/classes/AmazonMerchantServiceList.php

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

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

includes/classes/AmazonMerchantShipment.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ protected function parseXML($xml) {
145145
$this->data['Label']['FileContents']['Contents'] = (string)$d->Label->FileContents->Contents;
146146
$this->data['Label']['FileContents']['FileType'] = (string)$d->Label->FileContents->FileType;
147147
$this->data['Label']['FileContents']['Checksum'] = (string)$d->Label->FileContents->Checksum;
148+
if (isset($d->Label->CustomTextForLabel)) {
149+
$this->data['Label']['CustomTextForLabel'] = (string)$d->Label->CustomTextForLabel;
150+
}
151+
if (isset($d->Label->LabelFormat)) {
152+
$this->data['Label']['LabelFormat'] = (string)$d->Label->LabelFormat;
153+
}
154+
if (isset($d->Label->StandardIdForLabel)) {
155+
$this->data['Label']['StandardIdForLabel'] = (string)$d->Label->StandardIdForLabel;
156+
}
148157
}
149158

150159
$this->data['ItemList'] = array();
@@ -548,6 +557,9 @@ public function getDeclaredValue($only = false){
548557
* <li><b>Checksum</b></li>
549558
* </ul>
550559
* </li>
560+
* <li><b>CustomTextForLabel</b></li>
561+
* <li><b>LabelFormat</b></li>
562+
* <li><b>StandardIdForLabel</b></li>
551563
* </ul>
552564
* @param boolean $raw [optional] <p>Set to TRUE to get the raw, double-encoded file contents.</p>
553565
* @return array|boolean multi-dimensional array, or <b>FALSE</b> if label not set yet

includes/classes/AmazonMerchantShipmentCreator.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,56 @@ public function setCarrierWillPickUp($b = true) {
418418
$this->options['ShipmentRequestDetails.ShippingServiceOptions.CarrierWillPickUp'] = $v;
419419
}
420420

421+
/**
422+
* Sets the Label Format. (Optional)
423+
*
424+
* This method sets the label format to be sent in the next request.
425+
* @param string $f <p>Label format (ex: "PNG")</p>
426+
* @return boolean <b>FALSE</b> if improper input
427+
*/
428+
public function setLabelFormat($f) {
429+
if (is_string($f)){
430+
$this->options['ShipmentRequestDetails.ShippingServiceOptions.LabelFormat'] = $f;
431+
} else {
432+
$this->log("Tried to set LabelFormat to invalid value",'Warning');
433+
return false;
434+
}
435+
}
436+
437+
/**
438+
* Sets the Custom Text for the Label. (Optional)
439+
*
440+
* This method sets the custom text for the label to be sent in the next request.
441+
* @param string $t <p>Up to 14 characters</p>
442+
* @return boolean <b>FALSE</b> if improper input
443+
*/
444+
public function setCustomText($t) {
445+
if (is_string($t)){
446+
$this->options['ShipmentRequestDetails.LabelCustomization.CustomTextForLabel'] = $t;
447+
} else {
448+
$this->log("Tried to set CustomTextForLabel to invalid value",'Warning');
449+
return false;
450+
}
451+
}
452+
453+
/**
454+
* Sets the Standard ID for the Label. (Optional)
455+
*
456+
* This method sets the standard ID option for the label to be sent in the next request.
457+
* @param string $id <p>"AmazonOrderId"</p>
458+
*/
459+
public function setLabelId($id) {
460+
$options = array(
461+
'AmazonOrderId'
462+
);
463+
if (in_array($id, $options)){
464+
$this->options['ShipmentRequestDetails.LabelCustomization.StandardIdForLabel'] = $id;
465+
} else {
466+
$this->log("Tried to set StandardIdForLabel to invalid value",'Warning');
467+
return false;
468+
}
469+
}
470+
421471
/**
422472
* Sets the Shipping Service ID. (Required)
423473
*
@@ -451,6 +501,26 @@ public function setServiceOffer($id) {
451501
}
452502
}
453503

504+
/**
505+
* Sets the Hazmat Type. (Optional)
506+
*
507+
* This method sets the hazmat type to be sent in the next request.
508+
* @param string $h <p>"None" or "LQHazmat"</p>
509+
* @return boolean <b>FALSE</b> if improper input
510+
*/
511+
public function setHazmat($h) {
512+
$options = array(
513+
'None',
514+
'LQHazmat'
515+
);
516+
if (in_array($h, $options)){
517+
$this->options['HazmatType'] = $h;
518+
} else {
519+
$this->log("Tried to set HazmatType to invalid value",'Warning');
520+
return false;
521+
}
522+
}
523+
454524
/**
455525
* Fetches eligible services for the shipment from Amazon using the current options.
456526
*

0 commit comments

Comments
 (0)