-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added FreightCharges option to InternationalForms
- Loading branch information
1 parent
d77755e
commit 9720413
Showing
2 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters