1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use DOMElement; |
7
|
|
|
use Ups\NodeInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Eduard Sukharev <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class BillThirdParty implements NodeInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Address |
16
|
|
|
*/ |
17
|
|
|
private $thirdPartyAddress; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $accountNumber; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param \stdClass|null $attributes |
26
|
|
|
*/ |
27
|
1 |
|
public function __construct(\stdClass $attributes = null) |
28
|
|
|
{ |
29
|
1 |
|
$this->thirdPartyAddress = new Address(isset($attributes->Address) ? $attributes->Address : null); |
30
|
1 |
|
$this->accountNumber = isset($attributes->AccountNumber) ? $attributes->AccountNumber : null; |
31
|
1 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return Address |
35
|
|
|
*/ |
36
|
1 |
|
public function getThirdPartyAddress() |
37
|
|
|
{ |
38
|
1 |
|
return $this->thirdPartyAddress; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param Address $thirdPartyAddress |
43
|
|
|
* @return BillThirdParty |
44
|
|
|
*/ |
45
|
|
|
public function setThirdPartyAddress(Address $thirdPartyAddress = null) |
46
|
|
|
{ |
47
|
|
|
$this->thirdPartyAddress = $thirdPartyAddress; |
48
|
|
|
|
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
1 |
|
public function getAccountNumber() |
56
|
|
|
{ |
57
|
1 |
|
return $this->accountNumber; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $accountNumber |
62
|
|
|
* @return BillThirdParty |
63
|
|
|
*/ |
64
|
|
|
public function setAccountNumber($accountNumber) |
65
|
|
|
{ |
66
|
|
|
$this->accountNumber = $accountNumber; |
67
|
|
|
|
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param DOMDocument|null $document |
73
|
|
|
* @return DOMElement |
74
|
|
|
*/ |
75
|
1 |
|
public function toNode(DOMDocument $document = null) |
76
|
|
|
{ |
77
|
1 |
|
if (null === $document) { |
78
|
|
|
$document = new DOMDocument(); |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
$node = $document->createElement('BillThirdParty'); |
82
|
|
|
|
83
|
1 |
|
$btpNode = $node->appendChild($document->createElement('BillThirdPartyShipper')); |
84
|
1 |
|
$btpNode->appendChild($document->createElement('AccountNumber', $this->getAccountNumber())); |
85
|
|
|
|
86
|
1 |
|
$tpNode = $btpNode->appendChild($document->createElement('ThirdParty')); |
87
|
1 |
|
$addressNode = $tpNode->appendChild($document->createElement('Address')); |
88
|
|
|
|
89
|
1 |
|
$thirdPartAddress = $this->getThirdPartyAddress(); |
90
|
1 |
|
if (isset($thirdPartAddress) && $this->getThirdPartyAddress()->getPostalCode()) { |
91
|
|
|
$addressNode->appendChild($document->createElement('PostalCode', $this->getThirdPartyAddress()->getPostalCode())); |
92
|
|
|
} |
93
|
|
|
|
94
|
1 |
|
$addressNode->appendChild($document->createElement('CountryCode', $this->getThirdPartyAddress()->getCountryCode())); |
95
|
|
|
|
96
|
1 |
|
return $node; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|