1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use Ups\NodeInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @author Eduard Sukharev <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class BillShipper implements NodeInterface |
12
|
|
|
{ |
13
|
|
|
const TYPE_ALTERNATE_PAYMENT_METHOD_PAYPAL = '01'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $accountNumber; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var CreditCard |
22
|
|
|
*/ |
23
|
|
|
private $creditCard; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $alternatePaymentMethod; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param \stdClass|null $attributes |
32
|
|
|
*/ |
33
|
3 |
|
public function __construct(\stdClass $attributes = null) |
34
|
|
|
{ |
35
|
3 |
|
if (isset($attributes->AccountNumber)) { |
36
|
|
|
$this->setAccountNumber($attributes->AccountNumber); |
37
|
|
|
} |
38
|
3 |
|
if (isset($attributes->CreditCard)) { |
39
|
|
|
$this->setCreditCard(new CreditCard($attributes->CreditCard)); |
40
|
|
|
} |
41
|
3 |
|
if (isset($attributes->alternatePaymentMethod)) { |
42
|
|
|
$this->setAlternatePaymentMethod($attributes->alternatePaymentMethod); |
43
|
|
|
} |
44
|
3 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param null|DOMDocument $document |
48
|
|
|
* |
49
|
|
|
* @return DOMElement |
50
|
|
|
*/ |
51
|
1 |
|
public function toNode(DOMDocument $document = null) |
52
|
|
|
{ |
53
|
1 |
|
if (null === $document) { |
54
|
|
|
$document = new DOMDocument(); |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
$node = $document->createElement('BillShipper'); |
58
|
|
|
|
59
|
1 |
|
if ($this->getAccountNumber()) { |
60
|
|
|
$node->appendChild($document->createElement('AccountNumber', $this->getAccountNumber())); |
61
|
1 |
|
} elseif ($creditCard = $this->getCreditCard()) { |
62
|
|
|
$node->appendChild($creditCard->toNode($document)); |
63
|
1 |
|
} elseif ($type = $this->getAlternatePaymentMethod()) { |
64
|
|
|
$node->appendChild($document->createElement('AlternatePaymentMethod', $type)); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
return $node; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
1 |
|
public function getAccountNumber() |
74
|
|
|
{ |
75
|
1 |
|
return $this->accountNumber; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $accountNumber |
80
|
|
|
* |
81
|
|
|
* @return BillShipper |
82
|
|
|
*/ |
83
|
|
|
public function setAccountNumber($accountNumber) |
84
|
|
|
{ |
85
|
|
|
$this->accountNumber = $accountNumber; |
86
|
|
|
|
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return CreditCard |
92
|
|
|
*/ |
93
|
1 |
|
public function getCreditCard() |
94
|
|
|
{ |
95
|
1 |
|
return $this->creditCard; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param CreditCard $creditCard |
100
|
|
|
* @return BillShipper |
101
|
|
|
*/ |
102
|
|
|
public function setCreditCard(CreditCard $creditCard) |
103
|
|
|
{ |
104
|
|
|
$this->creditCard = $creditCard; |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param string $type |
111
|
|
|
* @return BillShipper |
112
|
|
|
*/ |
113
|
|
|
public function setAlternatePaymentMethod($type) |
114
|
|
|
{ |
115
|
|
|
$this->alternatePaymentMethod = $type; |
116
|
|
|
|
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return string|null |
122
|
|
|
*/ |
123
|
1 |
|
public function getAlternatePaymentMethod() |
124
|
|
|
{ |
125
|
1 |
|
return $this->alternatePaymentMethod; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|