Skip to content

Commit

Permalink
Added FreightCharges option to InternationalForms
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandoorn committed Jun 20, 2015
1 parent d77755e commit 9720413
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
58 changes: 58 additions & 0 deletions src/Ups/Entity/FreightCharges.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace Ups\Entity;

use Ups\NodeInterface;
use DOMDocument;
use DOMElement;

class FreightCharges implements NodeInterface
{

private $monetaryValue;

function __construct($response = null)
{
if (null != $response) {
if (isset($response->MonetaryValue)) {
$this->setMonetaryValue($response->MonetaryValue);
}
}
}

/**
* @param null|DOMDocument $document
* @return DOMElement
*/
public function toNode(DOMDocument $document = null)
{
if (null === $document) {
$document = new DOMDocument();
}

$node = $document->createElement('FreightCharges');
$node->appendChild($document->createElement('MonetaryValue', $this->getMonetaryValue()));

return $node;
}

/**
* @return mixed
*/
public function getMonetaryValue() {
return $this->monetaryValue;
}

/**
* @param $var
*/
public function setMonetaryValue($var) {
$this->monetaryValue = round($var, 2); // Max 2 decimals places

if(strlen((string) $this->monetaryValue) > 15) {
throw new \Exception('Value too long');
}

return $this;
}

}
28 changes: 27 additions & 1 deletion src/Ups/Entity/InternationalForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ class InternationalForms implements NodeInterface
*/
private $discount;

/**
* @var FreightCharges
*/
private $freightCharges;

/**
* @return array
*/
Expand Down Expand Up @@ -192,6 +197,24 @@ public function getType()
return $this->type;
}

/**
* @param $freightCharges FreightCharges
* @return $this
*/
public function setFreightCharges(FreightCharges $freightCharges)
{
$this->freightCharges = $freightCharges;
return $this;
}

/**
* @return FreightCharges
*/
public function getFreightCharges()
{
return $this->freightCharges;
}

/**
* @param $discount Discount
* @return $this
Expand All @@ -203,7 +226,7 @@ public function setDiscount(Discount $discount)
}

/**
* @return string
* @return Discount
*/
public function getDiscount()
{
Expand Down Expand Up @@ -267,6 +290,9 @@ public function toNode(DOMDocument $document = null)
if($this->getDiscount() !== null) {
$node->appendChild($this->getDiscount()->toNode($document));
}
if($this->getFreightCharges() !== null) {
$node->appendChild($this->getFreightCharges()->toNode($document));
}
foreach($this->products as $product) {
$node->appendChild($product->toNode($document));
}
Expand Down

0 comments on commit 9720413

Please sign in to comment.