1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Order item. |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2018 Pronamic |
7
|
|
|
* @license GPL-3.0-or-later |
8
|
|
|
* @package Pronamic\WordPress\Pay\Gateways\OmniKassa2 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Order item. |
15
|
|
|
* |
16
|
|
|
* @author Reüel van der Steege |
17
|
|
|
* @version 2.0.3 |
18
|
|
|
* @since 2.0.3 |
19
|
|
|
*/ |
20
|
|
|
class OrderItem { |
21
|
|
|
/** |
22
|
|
|
* Item id. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $id; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Item name (required). |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $name; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Description. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
private $description; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Quantity (required). |
44
|
|
|
* |
45
|
|
|
* @var int |
46
|
|
|
*/ |
47
|
|
|
private $quantity; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Amount (required). |
51
|
|
|
* |
52
|
|
|
* @var Money |
53
|
|
|
*/ |
54
|
|
|
private $amount; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Tax. |
58
|
|
|
* |
59
|
|
|
* @var Money |
60
|
|
|
*/ |
61
|
|
|
private $tax; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Category; physical or digital (required). |
65
|
|
|
* |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
private $category; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* VAT category. |
72
|
|
|
* |
73
|
|
|
* @var int |
74
|
|
|
*/ |
75
|
|
|
private $vat_category; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Construct order result. |
79
|
|
|
* |
80
|
|
|
* @param string $name Name. |
81
|
|
|
* @param int $quantity Quantity. |
82
|
|
|
* @param Money $amount Amount. |
83
|
|
|
* @param string $category Category. |
84
|
|
|
*/ |
85
|
|
|
public function __construct( $name, $quantity, Money $amount, $category ) { |
86
|
|
|
$this->name = $name; |
87
|
|
|
$this->quantity = $quantity; |
88
|
|
|
$this->amount = $amount; |
89
|
|
|
$this->category = $category; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get item ID. |
94
|
|
|
* |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function get_id() { |
98
|
|
|
return $this->id; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get item name. |
103
|
|
|
* |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function get_name() { |
107
|
|
|
return $this->name; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get item description. |
112
|
|
|
* |
113
|
|
|
* @return int|string |
114
|
|
|
*/ |
115
|
|
|
public function get_description() { |
116
|
|
|
return $this->description; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Get quantity. |
121
|
|
|
* |
122
|
|
|
* @return int |
123
|
|
|
*/ |
124
|
|
|
public function get_quantity() { |
125
|
|
|
return $this->quantity; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get amount. |
130
|
|
|
* |
131
|
|
|
* @return Money |
132
|
|
|
*/ |
133
|
|
|
public function get_amount() { |
134
|
|
|
return $this->amount; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Get tax. |
139
|
|
|
* |
140
|
|
|
* @return Money |
141
|
|
|
*/ |
142
|
|
|
public function get_tax() { |
143
|
|
|
return $this->tax; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Get category. |
148
|
|
|
* |
149
|
|
|
* @return string |
150
|
|
|
*/ |
151
|
|
|
public function get_category() { |
152
|
|
|
return $this->category; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Get VAT category. |
157
|
|
|
* |
158
|
|
|
* @return int |
159
|
|
|
*/ |
160
|
|
|
public function get_vat_category() { |
161
|
|
|
return $this->vat_category; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Get JSON. |
166
|
|
|
* |
167
|
|
|
* @return object |
168
|
|
|
*/ |
169
|
|
|
public function get_json() { |
170
|
|
|
$object = (object) array(); |
171
|
|
|
|
172
|
|
|
if ( null !== $this->id ) { |
173
|
|
|
$object->id = $this->id; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
$object->name = $this->name; |
177
|
|
|
|
178
|
|
|
if ( null !== $this->description ) { |
179
|
|
|
$object->description = $this->description; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$object->quantity = $this->quantity; |
183
|
|
|
$object->amount = $this->amount->get_json(); |
184
|
|
|
|
185
|
|
|
if ( null !== $this->tax ) { |
186
|
|
|
$object->tax = $this->tax->get_json(); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
$object->category = $this->category; |
190
|
|
|
|
191
|
|
|
if ( null !== $this->vat_category ) { |
192
|
|
|
$object->vatCategory = $this->vat_category; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return $object; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Get signature data. |
200
|
|
|
* |
201
|
|
|
* @param array $data Data. |
202
|
|
|
* @return array |
203
|
|
|
*/ |
204
|
|
|
public function get_signature_fields( $data = array() ) { |
205
|
|
|
if ( null !== $this->id ) { |
206
|
|
|
$data[] = $this->id; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
$data[] = $this->name; |
210
|
|
|
$data[] = $this->description; |
211
|
|
|
$data[] = $this->quantity; |
212
|
|
|
$data[] = $this->amount->get_currency(); |
213
|
|
|
$data[] = $this->amount->get_amount(); |
214
|
|
|
|
215
|
|
|
if ( null === $this->tax ) { |
216
|
|
|
$data[] = null; |
217
|
|
|
} else { |
218
|
|
|
$data[] = $this->tax->get_currency(); |
219
|
|
|
$data[] = $this->tax->get_amount(); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
$data[] = $this->category; |
223
|
|
|
|
224
|
|
|
if ( null !== $this->vatCategory ) { |
225
|
|
|
$data[] = $this->vatCategory; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
return $data; |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
|