Skip to content

Commit

Permalink
Add support for DeclaredValue on PackageServiceOptions level
Browse files Browse the repository at this point in the history
  • Loading branch information
agiorlando committed Mar 15, 2018
1 parent 5b35c2b commit af2970d
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
89 changes: 89 additions & 0 deletions src/Entity/DeclaredValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Ups\Entity;

use DOMDocument;
use DOMElement;
use Ups\NodeInterface;

class DeclaredValue implements NodeInterface
{
/** @deprecated */
public $CurrencyCode;
/** @deprecated */
public $MonetaryValue;

/**
* @var string
*/
private $currencyCode;

/**
* @var float
*/
private $monetaryValue;

public function __construct($response = null)
{
if (null !== $response) {
if (isset($response->CurrencyCode)) {
$this->setCurrencyCode($response->CurrencyCode);
}
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('DeclaredValue');
$node->appendChild($document->createElement('CurrencyCode', $this->getCurrencyCode()));
$node->appendChild($document->createElement('MonetaryValue', $this->getMonetaryValue()));

return $node;
}

/**
* @return string|null
*/
public function getCurrencyCode()
{
return $this->currencyCode;
}

/**
* @param $var string
*/
public function setCurrencyCode($var)
{
$this->CurrencyCode = $var;
$this->currencyCode = $var;
}

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

/**
* @param $var float
*/
public function setMonetaryValue($var)
{
$this->MonetaryValue = $var;
$this->monetaryValue = $var;
}
}
27 changes: 27 additions & 0 deletions src/Entity/PackageServiceOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class PackageServiceOptions implements NodeInterface
*/
private $insuredValue;

/**
* @var DeclaredValue
*/
private $declaredValue;

/**
* @var string
*/
Expand Down Expand Up @@ -59,6 +64,9 @@ public function __construct($parameters = null)
if (isset($parameters->InsuredValue)) {
$this->setInsuredValue(new InsuredValue($parameters->InsuredValue));
}
if (isset($parameters->DeclaredValue)) {
$this->setDeclaredValue(new DeclaredValue($parameters->DeclaredValue));
}
if (isset($parameters->EarliestDeliveryTime)) {
$this->setEarliestDeliveryTime($parameters->EarliestDeliveryTime);
}
Expand Down Expand Up @@ -89,6 +97,9 @@ public function toNode(DOMDocument $document = null)
if ($this->getInsuredValue()) {
$node->appendChild($this->getInsuredValue()->toNode($document));
}
if ($this->getDeclaredValue()) {
$node->appendChild($this->getDeclaredValue()->toNode($document));
}
foreach ($this->getHazMat() as $hazmat) {
$node->appendChild($hazmat->toNode($document));
}
Expand Down Expand Up @@ -118,6 +129,22 @@ public function setInsuredValue($var)
$this->insuredValue = $var;
}

/**
* @return DeclaredValue|null
*/
public function getDeclaredValue()
{
return $this->declaredValue;
}

/**
* @param $var
*/
public function setDeclaredValue($var)
{
$this->declaredValue = $var;
}

/**
* @return COD|null
*/
Expand Down
1 change: 1 addition & 0 deletions tests/Ups/Tests/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class EntityTest extends PHPUnit_Framework_TestCase
'SoldTo',
'PickupType',
'InsuredValue',
'DeclaredValue',
'InternationalForms',
'Product',
'COD',
Expand Down

0 comments on commit af2970d

Please sign in to comment.