-
Notifications
You must be signed in to change notification settings - Fork 39
/
Context.php
183 lines (160 loc) · 4.03 KB
/
Context.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
namespace CommerceGuys\Tax\Resolver;
use CommerceGuys\Addressing\AddressInterface;
/**
* Contains information relevant to tax resolving.
*
* Includes customer information, store information, and the calculation date.
*/
class Context
{
/**
* The customer address.
*
* @var AddressInterface
*/
protected $customerAddress;
/**
* The store address.
*
* @var AddressInterface
*/
protected $storeAddress;
/**
* The customer's tax number, if provided.
*
* @var string
*/
protected $customerTaxNumber;
/**
* Store registrations.
*
* A list of country codes where the store is additionally registered to
* collect taxes.
*
* @var array
*/
protected $storeRegistrations;
/**
* The calculation date.
*
* @var \DateTime
*/
protected $date;
/**
* Creates a Context instance.
*
* @param AddressInterface $customerAddress
* @param AddressInterface $storeAddress
* @param string $customerTaxNumber
* @param array $storeRegistrations
* @param \DateTime $date
*/
public function __construct(AddressInterface $customerAddress, AddressInterface $storeAddress, $customerTaxNumber = '', array $storeRegistrations = [], \DateTime $date = null)
{
$this->customerAddress = $customerAddress;
$this->storeAddress = $storeAddress;
$this->customerTaxNumber = $customerTaxNumber;
$this->storeRegistrations = $storeRegistrations;
$this->date = $date ?: new \DateTime();
}
/**
* Gets the customer address.
*
* @return AddressInterface The customer address.
*/
public function getCustomerAddress()
{
return $this->customerAddress;
}
/**
* Sets the customer address.
*
* @param AddressInterface $customerAddress The customer address.
*/
public function setCustomerAddress($customerAddress)
{
$this->customerAddress = $customerAddress;
return $this;
}
/**
* Gets the store address.
*
* @return AddressInterface The store address.
*/
public function getStoreAddress()
{
return $this->storeAddress;
}
/**
* Sets the store address.
*
* @param AddressInterface $storeAddress The store address.
*/
public function setStoreAddress($storeAddress)
{
$this->storeAddress = $storeAddress;
return $this;
}
/**
* Gets the customer tax number.
*
* @return string The customer tax number.
*/
public function getCustomerTaxNumber()
{
return $this->customerTaxNumber;
}
/**
* Sets the customer tax number.
*
* @param string $customerTaxNumber The customer tax number.
*/
public function setCustomerTaxNumber($customerTaxNumber)
{
$this->customerTaxNumber = $customerTaxNumber;
return $this;
}
/**
* Gets the store registrations.
*
* For example, ['UK'], for a US store registered in the UK to collect
* EU VAT on digital services.
*
* @return array An array of country codes where the store is additionally
* registered to collect taxes.
*/
public function getStoreRegistrations()
{
return $this->storeRegistrations;
}
/**
* Sets the store registrations.
*
* @param array $storeRegistrations An array of country codes.
*/
public function setStoreRegistrations(array $storeRegistrations)
{
$this->storeRegistrations = $storeRegistrations;
return $this;
}
/**
* Gets the calculation date.
*
* @return \DateTime The calculation date.
*/
public function getDate()
{
return $this->date;
}
/**
* Sets the calculation date.
*
* @param \DateTime $date The calculation date.
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
}