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