1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHP version 5.4 and 8 |
5
|
|
|
* |
6
|
|
|
* @category Core |
7
|
|
|
* @package Payever\Core |
8
|
|
|
* @author payever GmbH <[email protected]> |
9
|
|
|
* @author Andrey Puhovsky <[email protected]> |
10
|
|
|
* @author Hennadii.Shymanskyi <[email protected]> |
11
|
|
|
* @copyright 2017-2021 payever GmbH |
12
|
|
|
* @license MIT <https://opensource.org/licenses/MIT> |
13
|
|
|
* @link https://docs.payever.org/shopsystems/api/getting-started |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Payever\ExternalIntegration\Core; |
17
|
|
|
|
18
|
|
|
use Payever\ExternalIntegration\Core\Base\ClientConfigurationInterface; |
19
|
|
|
use Payever\ExternalIntegration\Core\Enum\ChannelSet; |
20
|
|
|
use Payever\ExternalIntegration\Core\Exception\ConfigurationException; |
21
|
|
|
use Payever\ExternalIntegration\Core\Logger\NullLogger; |
22
|
|
|
use Psr\Log\LoggerInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
26
|
|
|
*/ |
27
|
|
|
class ClientConfiguration implements ClientConfigurationInterface |
28
|
|
|
{ |
29
|
|
|
/** @var string */ |
30
|
|
|
protected $apiMode = self::API_MODE_LIVE; |
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
protected $clientId; |
34
|
|
|
|
35
|
|
|
/** @var string */ |
36
|
|
|
protected $clientSecret; |
37
|
|
|
|
38
|
|
|
/** @var string */ |
39
|
|
|
protected $customSandboxUrl; |
40
|
|
|
|
41
|
|
|
/** @var string */ |
42
|
|
|
protected $customLiveUrl; |
43
|
|
|
|
44
|
|
|
/** @var string */ |
45
|
|
|
protected $businessUuid; |
46
|
|
|
|
47
|
|
|
/** @var string */ |
48
|
|
|
protected $channelSet = ChannelSet::CHANNEL_OTHER_SHOPSYSTEM; |
49
|
|
|
|
50
|
|
|
/** @var LoggerInterface */ |
51
|
|
|
protected $logger; |
52
|
|
|
|
53
|
|
|
/** @var string */ |
54
|
|
|
protected $apiVersion = self::API_VERSION_DEFAULT; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string|null $clientId |
58
|
|
|
* @param string|null $clientSecret |
59
|
|
|
* @param string|null $businessUuid |
60
|
|
|
*/ |
61
|
|
|
public function __construct( |
62
|
|
|
$clientId = null, |
63
|
|
|
$clientSecret = null, |
64
|
|
|
$businessUuid = null |
65
|
|
|
) { |
66
|
|
|
$this->clientId = $clientId; |
67
|
|
|
$this->clientSecret = $clientSecret; |
68
|
|
|
$this->businessUuid = $businessUuid; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public function getClientId() |
75
|
|
|
{ |
76
|
|
|
return $this->clientId; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
|
|
public function getClientSecret() |
83
|
|
|
{ |
84
|
|
|
return $this->clientSecret; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
|
|
public function getBusinessUuid() |
91
|
|
|
{ |
92
|
|
|
return $this->businessUuid; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritdoc} |
97
|
|
|
*/ |
98
|
|
|
public function getApiMode() |
99
|
|
|
{ |
100
|
|
|
return $this->apiMode; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
|
|
public function getApiVersion() |
107
|
|
|
{ |
108
|
|
|
return $this->apiVersion; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* {@inheritdoc} |
113
|
|
|
*/ |
114
|
|
|
public function getChannelSet() |
115
|
|
|
{ |
116
|
|
|
return $this->channelSet; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* {@inheritdoc} |
121
|
|
|
*/ |
122
|
|
|
public function getCustomSandboxUrl() |
123
|
|
|
{ |
124
|
|
|
return $this->customSandboxUrl; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @inheritdoc |
129
|
|
|
*/ |
130
|
|
|
public function getCustomLiveUrl() |
131
|
|
|
{ |
132
|
|
|
return $this->customLiveUrl; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* {@inheritdoc} |
137
|
|
|
*/ |
138
|
|
|
public function getHash() |
139
|
|
|
{ |
140
|
|
|
return md5($this->getClientId() . $this->getClientSecret()); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return LoggerInterface |
145
|
|
|
*/ |
146
|
|
|
public function getLogger() |
147
|
|
|
{ |
148
|
|
|
if (is_null($this->logger)) { |
149
|
|
|
$this->logger = new NullLogger(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return $this->logger; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Sets Client ID |
157
|
|
|
* |
158
|
|
|
* @param mixed $clientId |
159
|
|
|
* |
160
|
|
|
* @return self |
161
|
|
|
*/ |
162
|
|
|
public function setClientId($clientId) |
163
|
|
|
{ |
164
|
|
|
$this->clientId = $clientId; |
165
|
|
|
|
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Sets Client Secret |
171
|
|
|
* |
172
|
|
|
* @param mixed $clientSecret |
173
|
|
|
* |
174
|
|
|
* @return self |
175
|
|
|
*/ |
176
|
|
|
public function setClientSecret($clientSecret) |
177
|
|
|
{ |
178
|
|
|
$this->clientSecret = $clientSecret; |
179
|
|
|
|
180
|
|
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Sets Business UUID |
185
|
|
|
* |
186
|
|
|
* @param mixed $businessUuid |
187
|
|
|
* |
188
|
|
|
* @return self |
189
|
|
|
*/ |
190
|
|
|
public function setBusinessUuid($businessUuid) |
191
|
|
|
{ |
192
|
|
|
$this->businessUuid = $businessUuid; |
193
|
|
|
|
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param string $apiMode |
199
|
|
|
* @return self |
200
|
|
|
*/ |
201
|
|
|
public function setApiMode($apiMode) |
202
|
|
|
{ |
203
|
|
|
$this->apiMode = $apiMode; |
204
|
|
|
|
205
|
|
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @param string $apiVersion |
210
|
|
|
* @return self |
211
|
|
|
*/ |
212
|
|
|
public function setApiVersion($apiVersion) |
213
|
|
|
{ |
214
|
|
|
$this->apiVersion = $apiVersion; |
215
|
|
|
|
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Sets Channel set |
221
|
|
|
* |
222
|
|
|
* @param mixed $channelSet |
223
|
|
|
* |
224
|
|
|
* @return $this |
225
|
|
|
* |
226
|
|
|
* @throws \Exception |
227
|
|
|
*/ |
228
|
|
|
public function setChannelSet($channelSet = null) |
229
|
|
|
{ |
230
|
|
|
if (!in_array($channelSet, ChannelSet::enum())) { |
231
|
|
|
throw new ConfigurationException(sprintf('Channel Set `%s` is not valid', $channelSet)); |
232
|
|
|
} |
233
|
|
|
$this->channelSet = $channelSet; |
234
|
|
|
|
235
|
|
|
return $this; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @internal |
240
|
|
|
* |
241
|
|
|
* Sets Custom sandbox API URL for all packages at once |
242
|
|
|
* |
243
|
|
|
* @param string $customSandboxUrl |
244
|
|
|
* |
245
|
|
|
* @return $this |
246
|
|
|
*/ |
247
|
|
|
public function setCustomSandboxUrl($customSandboxUrl) |
248
|
|
|
{ |
249
|
|
|
$this->customSandboxUrl = $customSandboxUrl; |
250
|
|
|
|
251
|
|
|
return $this; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @internal |
256
|
|
|
* |
257
|
|
|
* Sets Custom live API URL for all packages at once |
258
|
|
|
* |
259
|
|
|
* @param string $customLiveUrl |
260
|
|
|
* |
261
|
|
|
* @return $this |
262
|
|
|
*/ |
263
|
|
|
public function setCustomLiveUrl($customLiveUrl) |
264
|
|
|
{ |
265
|
|
|
$this->customLiveUrl = $customLiveUrl; |
266
|
|
|
|
267
|
|
|
return $this; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @param LoggerInterface $logger |
272
|
|
|
* |
273
|
|
|
* @return $this |
274
|
|
|
*/ |
275
|
|
|
public function setLogger(LoggerInterface $logger) |
276
|
|
|
{ |
277
|
|
|
$this->logger = $logger; |
278
|
|
|
|
279
|
|
|
return $this; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @inheritdoc |
284
|
|
|
*/ |
285
|
|
|
public function isLoaded() |
286
|
|
|
{ |
287
|
|
|
return |
288
|
|
|
$this->getClientId() && |
289
|
|
|
$this->getClientSecret() && |
290
|
|
|
$this->getBusinessUuid() |
291
|
|
|
; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @inheritdoc |
296
|
|
|
*/ |
297
|
|
|
public function assertLoaded() |
298
|
|
|
{ |
299
|
|
|
if (!$this->isLoaded()) { |
300
|
|
|
throw new ConfigurationException( |
301
|
|
|
'Payever API client credentials (client_id, client_secret, business_uuid) are not set.' |
302
|
|
|
); |
303
|
|
|
} |
304
|
|
|
} |
305
|
|
|
} |
306
|
|
|
|