1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\Payone\Business\Api\Response\Container; |
9
|
|
|
|
10
|
|
|
abstract class AbstractResponseContainer |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string|null |
14
|
|
|
*/ |
15
|
|
|
protected $status; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string|null |
19
|
|
|
*/ |
20
|
|
|
protected $rawResponse; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string|null |
24
|
|
|
*/ |
25
|
|
|
protected $errorcode; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string|null |
29
|
|
|
*/ |
30
|
|
|
protected $errormessage; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string|null |
34
|
|
|
*/ |
35
|
|
|
protected $customerMessage; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param array $params |
39
|
|
|
*/ |
40
|
|
|
public function __construct(array $params = []) |
41
|
|
|
{ |
42
|
|
|
if (count($params) > 0) { |
43
|
|
|
$this->init($params); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param array $data |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function init(array $data = []): void |
53
|
|
|
{ |
54
|
|
|
foreach ($data as $key => $value) { |
55
|
|
|
$key = $this->getPreparedKey($key); |
56
|
|
|
$method = 'set' . str_replace(' ', '', $key); |
57
|
|
|
|
58
|
|
|
if (method_exists($this, $method)) { |
59
|
|
|
$this->{$method}($value); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
public function toArray(): array |
68
|
|
|
{ |
69
|
|
|
$result = []; |
70
|
|
|
foreach ($this as $key => $data) { |
71
|
|
|
if ($data === null) { |
72
|
|
|
continue; |
73
|
|
|
} else { |
74
|
|
|
$result[$key] = $data; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $result; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function __toString(): string |
85
|
|
|
{ |
86
|
|
|
$stringArray = []; |
87
|
|
|
foreach ($this->toArray() as $key => $value) { |
88
|
|
|
$stringArray[] = $key . '=' . $value; |
89
|
|
|
} |
90
|
|
|
$result = implode('|', $stringArray); |
91
|
|
|
|
92
|
|
|
return $result; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $status |
97
|
|
|
* |
98
|
|
|
* @return void |
99
|
|
|
*/ |
100
|
|
|
public function setStatus(string $status): void |
101
|
|
|
{ |
102
|
|
|
$this->status = $status; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return string|null |
107
|
|
|
*/ |
108
|
|
|
public function getStatus(): ?string |
109
|
|
|
{ |
110
|
|
|
return $this->status; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $customerMessage |
115
|
|
|
* |
116
|
|
|
* @return void |
117
|
|
|
*/ |
118
|
|
|
public function setCustomerMessage(string $customerMessage): void |
119
|
|
|
{ |
120
|
|
|
$this->customerMessage = $customerMessage; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return string|null |
125
|
|
|
*/ |
126
|
|
|
public function getCustomerMessage(): ?string |
127
|
|
|
{ |
128
|
|
|
return $this->customerMessage; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param string $errorcode |
133
|
|
|
* |
134
|
|
|
* @return void |
135
|
|
|
*/ |
136
|
|
|
public function setErrorcode(string $errorcode): void |
137
|
|
|
{ |
138
|
|
|
$this->errorcode = $errorcode; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return string|null |
143
|
|
|
*/ |
144
|
|
|
public function getErrorcode(): ?string |
145
|
|
|
{ |
146
|
|
|
return $this->errorcode; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return bool |
151
|
|
|
*/ |
152
|
|
|
public function isError(): bool |
153
|
|
|
{ |
154
|
|
|
if ($this->errorcode === null) { |
155
|
|
|
return false; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
return true; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param string $errormessage |
163
|
|
|
* |
164
|
|
|
* @return void |
165
|
|
|
*/ |
166
|
|
|
public function setErrormessage(string $errormessage): void |
167
|
|
|
{ |
168
|
|
|
$this->errormessage = $errormessage; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return string|null |
173
|
|
|
*/ |
174
|
|
|
public function getErrormessage(): ?string |
175
|
|
|
{ |
176
|
|
|
return $this->errormessage; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param string $key |
181
|
|
|
* |
182
|
|
|
* @return mixed |
183
|
|
|
*/ |
184
|
|
|
public function getValue(string $key) |
185
|
|
|
{ |
186
|
|
|
return $this->get($key); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @param string $name |
191
|
|
|
* @param string $value |
192
|
|
|
* |
193
|
|
|
* @return bool |
194
|
|
|
*/ |
195
|
|
|
public function setValue(string $name, $value): bool |
196
|
|
|
{ |
197
|
|
|
return $this->set($name, $value); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param string $name |
202
|
|
|
* |
203
|
|
|
* @return mixed|null |
204
|
|
|
*/ |
205
|
|
|
protected function get(string $name) |
206
|
|
|
{ |
207
|
|
|
if (property_exists($this, $name)) { |
208
|
|
|
return $this->$name; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
return null; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param string $name |
216
|
|
|
* @param mixed $value |
217
|
|
|
* |
218
|
|
|
* @return bool |
219
|
|
|
*/ |
220
|
|
|
protected function set(string $name, $value): bool |
221
|
|
|
{ |
222
|
|
|
if (property_exists($this, $name)) { |
223
|
|
|
$this->$name = $value; |
224
|
|
|
|
225
|
|
|
return true; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
return false; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @param string $rawResponse |
233
|
|
|
* |
234
|
|
|
* @return void |
235
|
|
|
*/ |
236
|
|
|
public function setRawResponse(string $rawResponse): void |
237
|
|
|
{ |
238
|
|
|
$this->rawResponse = $rawResponse; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @return string|null |
243
|
|
|
*/ |
244
|
|
|
public function getRawResponse(): ?string |
245
|
|
|
{ |
246
|
|
|
return $this->rawResponse; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @param string $key |
251
|
|
|
* |
252
|
|
|
* @return string |
253
|
|
|
*/ |
254
|
|
|
protected function getPreparedKey(string $key): string |
255
|
|
|
{ |
256
|
|
|
return ucwords(str_replace('_', ' ', $key)); |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
|