Passed
Push — master ( cbaed7...1988ba )
by payever
02:29
created

ClientConfiguration::getCustomLiveUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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