1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace h4kuna\Fio\Request\Pay\Payment; |
4
|
|
|
|
5
|
|
|
use h4kuna\Fio\Account; |
6
|
|
|
use h4kuna\Fio\Exceptions\InvalidArgument; |
7
|
|
|
use Iterator; |
8
|
|
|
use Nette\Utils\DateTime; |
9
|
|
|
|
10
|
|
|
abstract class Property implements Iterator |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** @var Account\FioAccount */ |
14
|
|
|
protected $accountFrom; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
protected $currency = 'CZK'; |
18
|
|
|
|
19
|
|
|
/** @var float */ |
20
|
|
|
protected $amount = 0.0; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
protected $accountTo = ''; |
24
|
|
|
|
25
|
|
|
/** @var string */ |
26
|
|
|
protected $date; |
27
|
|
|
|
28
|
|
|
/** @var string */ |
29
|
|
|
protected $comment; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Section in manual 7.2.3.1. |
33
|
|
|
* @var int |
34
|
|
|
*/ |
35
|
|
|
protected $paymentReason = 0; |
36
|
|
|
|
37
|
|
|
/** @var array */ |
38
|
|
|
private static $iterator = []; |
39
|
|
|
|
40
|
|
|
/** @var string */ |
41
|
|
|
private $key; |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function __construct(Account\FioAccount $account) |
45
|
|
|
{ |
46
|
|
|
$this->accountFrom = $account; |
47
|
|
|
$this->setDate('now'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return static |
53
|
|
|
*/ |
54
|
|
|
public function setAmount(float $amount) |
55
|
|
|
{ |
56
|
|
|
$this->amount = $amount; |
57
|
|
|
if ($amount <= 0) { |
58
|
|
|
throw new InvalidArgument('Amount must by positive number.'); |
59
|
|
|
} |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return static |
66
|
|
|
*/ |
67
|
|
|
abstract public function setAccountTo(string $accountTo); |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Currency code ISO 4217. |
72
|
|
|
* @return static |
73
|
|
|
*/ |
74
|
|
|
public function setCurrency(string $code) |
75
|
|
|
{ |
76
|
|
|
if (!preg_match('~[a-z]{3}~i', $code)) { |
77
|
|
|
throw new InvalidArgument('Currency code must match ISO 4217.'); |
78
|
|
|
} |
79
|
|
|
$this->currency = strtoupper($code); |
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return static |
86
|
|
|
*/ |
87
|
|
|
public function setMyComment(string $comment) |
88
|
|
|
{ |
89
|
|
|
$this->comment = InvalidArgument::check($comment, 255); |
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param int|string|\DateTimeInterface $date |
96
|
|
|
* @return static |
97
|
|
|
*/ |
98
|
|
|
public function setDate($date) |
99
|
|
|
{ |
100
|
|
|
$this->date = DateTime::from($date)->format('Y-m-d'); |
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return static |
107
|
|
|
*/ |
108
|
|
|
public function setPaymentReason(int $code) |
109
|
|
|
{ |
110
|
|
|
$this->paymentReason = InvalidArgument::checkRange($code, 999); |
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Order is important. |
117
|
|
|
* @return array<string, bool> |
|
|
|
|
118
|
|
|
*/ |
119
|
|
|
abstract public function getExpectedProperty(): array; |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
abstract public function getStartXmlElement(): string; |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
private function getProperties(): array |
126
|
|
|
{ |
127
|
|
|
if ($this->key === null) { |
128
|
|
|
$this->key = get_called_class(); |
129
|
|
|
} |
130
|
|
|
if (isset(self::$iterator[$this->key])) { |
131
|
|
|
return self::$iterator[$this->key]; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return self::$iterator[$this->key] = $this->getExpectedProperty(); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* ITERATOR INTERFACE ****************************************************** |
140
|
|
|
* ************************************************************************* |
141
|
|
|
*/ |
142
|
|
|
public function current() |
143
|
|
|
{ |
144
|
|
|
$property = $this->key(); |
145
|
|
|
$method = 'get' . ucfirst($property); |
146
|
|
|
if (method_exists($this, $method)) { |
147
|
|
|
return $this->{$method}(); |
148
|
|
|
} |
149
|
|
|
return $this->{$property}; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
public function key() |
154
|
|
|
{ |
155
|
|
|
return key(self::$iterator[$this->key]); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
public function next() |
160
|
|
|
{ |
161
|
|
|
next(self::$iterator[$this->key]); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
public function rewind() |
166
|
|
|
{ |
167
|
|
|
$this->getProperties(); |
168
|
|
|
reset(self::$iterator[$this->key]); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
public function valid() |
173
|
|
|
{ |
174
|
|
|
return array_key_exists(key(self::$iterator[$this->key]), self::$iterator[$this->key]); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
} |
178
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.