1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace Korobovn\CloudPayments\Message\Receipt; |
6
|
|
|
|
7
|
|
|
use Korobovn\CloudPayments\Message\Reference\TaxationSystem; |
8
|
|
|
|
9
|
|
|
class Receipt |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Items |
13
|
|
|
* |
14
|
|
|
* @var array|Item[] |
15
|
|
|
*/ |
16
|
|
|
protected $items = []; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Place of settlement, the default value is taken from the cashier. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $calculation_place; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Tax system; optional if you have one tax system. |
27
|
|
|
* |
28
|
|
|
* @see TaxationSystem |
29
|
|
|
* |
30
|
|
|
* @var int |
31
|
|
|
*/ |
32
|
|
|
protected $taxation_system; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The customer’s email, if you need to send an email with a check. |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $email; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The customer’s phone in any format, if you need to send a message with a link to the check. |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected $phone; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* The check is a form of strict reporting. |
50
|
|
|
* |
51
|
|
|
* @var bool |
52
|
|
|
*/ |
53
|
|
|
protected $is_bso = false; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The amount of payment by electronic money. |
57
|
|
|
* |
58
|
|
|
* @var float |
59
|
|
|
*/ |
60
|
|
|
protected $electronic_amount; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Amount of prepayment (offset by advance) (2 decimal places). |
64
|
|
|
* |
65
|
|
|
* @var float |
66
|
|
|
*/ |
67
|
|
|
protected $advance_payment_amount; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Postpay amount (on credit) (2 decimal places). |
71
|
|
|
* |
72
|
|
|
* @var float |
73
|
|
|
*/ |
74
|
|
|
protected $credit_amount; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Amount of payment by counter-provision (certificates, other mat. Value) (2 decimal places). |
78
|
|
|
* |
79
|
|
|
* @var float |
80
|
|
|
*/ |
81
|
|
|
protected $provision_amount; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Items |
85
|
|
|
* |
86
|
|
|
* @param array $items |
87
|
|
|
* |
88
|
|
|
* @return Receipt |
89
|
|
|
*/ |
90
|
|
|
public function setItems(array $items): self |
91
|
|
|
{ |
92
|
|
|
$this->items = $items; |
93
|
|
|
|
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Place of settlement, the default value is taken from the cashier. |
99
|
|
|
* |
100
|
|
|
* @param string $calculation_place |
101
|
|
|
* |
102
|
|
|
* @return Receipt |
103
|
|
|
*/ |
104
|
|
|
public function setCalculationPlace(string $calculation_place): self |
105
|
|
|
{ |
106
|
|
|
$this->calculation_place = $calculation_place; |
107
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Tax system; optional if you have one tax system. |
113
|
|
|
* |
114
|
|
|
* @param int $taxation_system |
115
|
|
|
* |
116
|
|
|
* @return Receipt |
117
|
|
|
*/ |
118
|
|
|
public function setTaxationSystem(int $taxation_system): self |
119
|
|
|
{ |
120
|
|
|
$this->taxation_system = $taxation_system; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* The customer’s email, if you need to send an email with a check. |
127
|
|
|
* |
128
|
|
|
* @param string $email |
129
|
|
|
* |
130
|
|
|
* @return Receipt |
131
|
|
|
*/ |
132
|
|
|
public function setEmail(string $email): self |
133
|
|
|
{ |
134
|
|
|
$this->email = $email; |
135
|
|
|
|
136
|
|
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* The customer’s phone in any format, if you need to send a message with a link to the check. |
141
|
|
|
* |
142
|
|
|
* @param string $phone |
143
|
|
|
* |
144
|
|
|
* @return Receipt |
145
|
|
|
*/ |
146
|
|
|
public function setPhone(string $phone): self |
147
|
|
|
{ |
148
|
|
|
$this->phone = $phone; |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* The check is a form of strict reporting. |
155
|
|
|
* |
156
|
|
|
* @param bool $is_bso |
157
|
|
|
* |
158
|
|
|
* @return Receipt |
159
|
|
|
*/ |
160
|
|
|
public function setIsBso(bool $is_bso): self |
161
|
|
|
{ |
162
|
|
|
$this->is_bso = $is_bso; |
163
|
|
|
|
164
|
|
|
return $this; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* The amount of payment by electronic money. |
169
|
|
|
* |
170
|
|
|
* @param float $electronic_amount |
171
|
|
|
* |
172
|
|
|
* @return Receipt |
173
|
|
|
*/ |
174
|
|
|
public function setElectronicAmount(float $electronic_amount): self |
175
|
|
|
{ |
176
|
|
|
$this->electronic_amount = $electronic_amount; |
177
|
|
|
|
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Amount of prepayment (offset by advance) (2 decimal places). |
183
|
|
|
* |
184
|
|
|
* @param float $advance_payment_amount |
185
|
|
|
* |
186
|
|
|
* @return Receipt |
187
|
|
|
*/ |
188
|
|
|
public function setAdvancePaymentAmount(float $advance_payment_amount): self |
189
|
|
|
{ |
190
|
|
|
$this->advance_payment_amount = $advance_payment_amount; |
191
|
|
|
|
192
|
|
|
return $this; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Postpay amount (on credit) (2 decimal places). |
197
|
|
|
* |
198
|
|
|
* @param float $credit_amount |
199
|
|
|
* |
200
|
|
|
* @return Receipt |
201
|
|
|
*/ |
202
|
|
|
public function setCreditAmount(float $credit_amount): self |
203
|
|
|
{ |
204
|
|
|
$this->credit_amount = $credit_amount; |
205
|
|
|
|
206
|
|
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Amount of payment by counter-provision (certificates, other mat. Value) (2 decimal places). |
211
|
|
|
* |
212
|
|
|
* @param float $provision_amount |
213
|
|
|
* |
214
|
|
|
* @return Receipt |
215
|
|
|
*/ |
216
|
|
|
public function setProvisionAmount(float $provision_amount): self |
217
|
|
|
{ |
218
|
|
|
$this->provision_amount = $provision_amount; |
219
|
|
|
|
220
|
|
|
return $this; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @param Item $item |
225
|
|
|
* |
226
|
|
|
* @return Receipt |
227
|
|
|
*/ |
228
|
|
|
public function addItem(Item $item): self |
229
|
|
|
{ |
230
|
|
|
$this->items[] = $item; |
231
|
|
|
|
232
|
|
|
return $this; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @return array |
237
|
|
|
*/ |
238
|
|
|
public function toArray(): array |
239
|
|
|
{ |
240
|
|
|
$receipt_items = []; |
241
|
|
|
foreach ($this->items as $receipt_item) { |
242
|
|
|
if ($receipt_item instanceof Item) { |
243
|
|
|
$receipt_items[] = $receipt_item->toArray(); |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
return \array_filter([ |
248
|
|
|
'Items' => $receipt_items, |
249
|
|
|
'calculationPlace' => $this->calculation_place, |
250
|
|
|
'taxationSystem' => $this->taxation_system, |
251
|
|
|
'email' => $this->email, |
252
|
|
|
'phone' => $this->phone, |
253
|
|
|
'isBso' => $this->is_bso, |
254
|
|
|
'amounts' => [ |
255
|
|
|
'electronic' => \number_format((float) $this->electronic_amount, 2, '.', ''), |
256
|
|
|
'advancePayment' => \number_format((float) $this->advance_payment_amount, 2, '.', ''), |
257
|
|
|
'credit' => \number_format((float) $this->credit_amount, 2, '.', ''), |
258
|
|
|
'provision' => \number_format((float) $this->provision_amount, 2, '.', ''), |
259
|
|
|
], |
260
|
|
|
]); |
261
|
|
|
} |
262
|
|
|
} |
263
|
|
|
|