PluginProbe
MONEI Payments for WooCommerce / 4.2.0
MONEI Payments for WooCommerce v4.2.0
7.3.3 7.3.2 7.3.1 7.3.0 7.2.4 7.2.3 7.2.2 7.2.0 7.2.1 7.1.3 2.1.0 3.0.0 3.1.0 3.1.1 4.0.0 4.1.0 4.1.1 4.2.0 4.2.1 5.0 5.1.0 5.1.1 5.1.2 5.2.2 5.2.3 All 87 releases
monei / includes / lib / Configuration.php

Configuration.php in MONEI Payments for WooCommerce 4.2.0, at includes/lib/Configuration.php

485 lines 11.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Configuration
4 * PHP version 5
5 *
6 * @category Class
7 * @package OpenAPI\Client
8 * @author OpenAPI Generator team
9 * @link https://openapi-generator.tech
10 */
11
12 /**
13 * MONEI API v1
14 *
15 * The MONEI API is organized around [REST](https://en.wikipedia.org/wiki/Representational_State_Transfer). Our API has predictable resource-oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.
16 *
17 * The version of the OpenAPI document: 1.0.0
18 *
19 * Generated by: https://openapi-generator.tech
20 * OpenAPI Generator version: 4.3.1
21 */
22
23 /**
24 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
25 * https://openapi-generator.tech
26 * Do not edit the class manually.
27 */
28
29 namespace OpenAPI\Client;
30
31 /**
32 * Configuration Class Doc Comment
33 * PHP version 5
34 *
35 * @category Class
36 * @package OpenAPI\Client
37 * @author OpenAPI Generator team
38 * @link https://openapi-generator.tech
39 */
40 class Configuration
41 {
42 private static $defaultConfiguration;
43
44 /**
45 * Associate array to store API key(s)
46 *
47 * @var string[]
48 */
49 protected $apiKeys = [];
50
51 /**
52 * Associate array to store API prefix (e.g. Bearer)
53 *
54 * @var string[]
55 */
56 protected $apiKeyPrefixes = [];
57
58 /**
59 * Access token for OAuth/Bearer authentication
60 *
61 * @var string
62 */
63 protected $accessToken = '';
64
65 /**
66 * Username for HTTP basic authentication
67 *
68 * @var string
69 */
70 protected $username = '';
71
72 /**
73 * Password for HTTP basic authentication
74 *
75 * @var string
76 */
77 protected $password = '';
78
79 /**
80 * The host
81 *
82 * @var string
83 */
84 protected $host = 'http://api.monei.net/v1';
85
86 /**
87 * User agent of the HTTP request, set to "OpenAPI-Generator/{version}/PHP" by default
88 *
89 * @var string
90 */
91 protected $userAgent = 'OpenAPI-Generator/1.0.0/PHP';
92
93 /**
94 * Debug switch (default set to false)
95 *
96 * @var bool
97 */
98 protected $debug = false;
99
100 /**
101 * Debug file location (log to STDOUT by default)
102 *
103 * @var string
104 */
105 protected $debugFile = 'php://output';
106
107 /**
108 * Debug file location (log to STDOUT by default)
109 *
110 * @var string
111 */
112 protected $tempFolderPath;
113
114 /**
115 * Constructor
116 */
117 public function __construct()
118 {
119 $this->tempFolderPath = sys_get_temp_dir();
120 }
121
122 /**
123 * Sets API key
124 *
125 * @param string $apiKeyIdentifier API key identifier (authentication scheme)
126 * @param string $key API key or token
127 *
128 * @return $this
129 */
130 public function setApiKey($apiKeyIdentifier, $key)
131 {
132 $this->apiKeys[$apiKeyIdentifier] = $key;
133 return $this;
134 }
135
136 /**
137 * Gets API key
138 *
139 * @param string $apiKeyIdentifier API key identifier (authentication scheme)
140 *
141 * @return string API key or token
142 */
143 public function getApiKey($apiKeyIdentifier)
144 {
145 return isset($this->apiKeys[$apiKeyIdentifier]) ? $this->apiKeys[$apiKeyIdentifier] : null;
146 }
147
148 /**
149 * Sets the prefix for API key (e.g. Bearer)
150 *
151 * @param string $apiKeyIdentifier API key identifier (authentication scheme)
152 * @param string $prefix API key prefix, e.g. Bearer
153 *
154 * @return $this
155 */
156 public function setApiKeyPrefix($apiKeyIdentifier, $prefix)
157 {
158 $this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix;
159 return $this;
160 }
161
162 /**
163 * Gets API key prefix
164 *
165 * @param string $apiKeyIdentifier API key identifier (authentication scheme)
166 *
167 * @return string
168 */
169 public function getApiKeyPrefix($apiKeyIdentifier)
170 {
171 return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null;
172 }
173
174 /**
175 * Sets the access token for OAuth
176 *
177 * @param string $accessToken Token for OAuth
178 *
179 * @return $this
180 */
181 public function setAccessToken($accessToken)
182 {
183 $this->accessToken = $accessToken;
184 return $this;
185 }
186
187 /**
188 * Gets the access token for OAuth
189 *
190 * @return string Access token for OAuth
191 */
192 public function getAccessToken()
193 {
194 return $this->accessToken;
195 }
196
197 /**
198 * Sets the username for HTTP basic authentication
199 *
200 * @param string $username Username for HTTP basic authentication
201 *
202 * @return $this
203 */
204 public function setUsername($username)
205 {
206 $this->username = $username;
207 return $this;
208 }
209
210 /**
211 * Gets the username for HTTP basic authentication
212 *
213 * @return string Username for HTTP basic authentication
214 */
215 public function getUsername()
216 {
217 return $this->username;
218 }
219
220 /**
221 * Sets the password for HTTP basic authentication
222 *
223 * @param string $password Password for HTTP basic authentication
224 *
225 * @return $this
226 */
227 public function setPassword($password)
228 {
229 $this->password = $password;
230 return $this;
231 }
232
233 /**
234 * Gets the password for HTTP basic authentication
235 *
236 * @return string Password for HTTP basic authentication
237 */
238 public function getPassword()
239 {
240 return $this->password;
241 }
242
243 /**
244 * Sets the host
245 *
246 * @param string $host Host
247 *
248 * @return $this
249 */
250 public function setHost($host)
251 {
252 $this->host = $host;
253 return $this;
254 }
255
256 /**
257 * Gets the host
258 *
259 * @return string Host
260 */
261 public function getHost()
262 {
263 return $this->host;
264 }
265
266 /**
267 * Sets the user agent of the api client
268 *
269 * @param string $userAgent the user agent of the api client
270 *
271 * @throws \InvalidArgumentException
272 * @return $this
273 */
274 public function setUserAgent($userAgent)
275 {
276 if (!is_string($userAgent)) {
277 throw new \InvalidArgumentException('User-agent must be a string.');
278 }
279
280 $this->userAgent = $userAgent;
281 return $this;
282 }
283
284 /**
285 * Gets the user agent of the api client
286 *
287 * @return string user agent
288 */
289 public function getUserAgent()
290 {
291 return $this->userAgent;
292 }
293
294 /**
295 * Sets debug flag
296 *
297 * @param bool $debug Debug flag
298 *
299 * @return $this
300 */
301 public function setDebug($debug)
302 {
303 $this->debug = $debug;
304 return $this;
305 }
306
307 /**
308 * Gets the debug flag
309 *
310 * @return bool
311 */
312 public function getDebug()
313 {
314 return $this->debug;
315 }
316
317 /**
318 * Sets the debug file
319 *
320 * @param string $debugFile Debug file
321 *
322 * @return $this
323 */
324 public function setDebugFile($debugFile)
325 {
326 $this->debugFile = $debugFile;
327 return $this;
328 }
329
330 /**
331 * Gets the debug file
332 *
333 * @return string
334 */
335 public function getDebugFile()
336 {
337 return $this->debugFile;
338 }
339
340 /**
341 * Sets the temp folder path
342 *
343 * @param string $tempFolderPath Temp folder path
344 *
345 * @return $this
346 */
347 public function setTempFolderPath($tempFolderPath)
348 {
349 $this->tempFolderPath = $tempFolderPath;
350 return $this;
351 }
352
353 /**
354 * Gets the temp folder path
355 *
356 * @return string Temp folder path
357 */
358 public function getTempFolderPath()
359 {
360 return $this->tempFolderPath;
361 }
362
363 /**
364 * Gets the default configuration instance
365 *
366 * @return Configuration
367 */
368 public static function getDefaultConfiguration()
369 {
370 if (self::$defaultConfiguration === null) {
371 self::$defaultConfiguration = new Configuration();
372 }
373
374 return self::$defaultConfiguration;
375 }
376
377 /**
378 * Sets the detault configuration instance
379 *
380 * @param Configuration $config An instance of the Configuration Object
381 *
382 * @return void
383 */
384 public static function setDefaultConfiguration(Configuration $config)
385 {
386 self::$defaultConfiguration = $config;
387 }
388
389 /**
390 * Gets the essential information for debugging
391 *
392 * @return string The report for debugging
393 */
394 public static function toDebugReport()
395 {
396 $report = 'PHP SDK (OpenAPI\Client) Debug Report:' . PHP_EOL;
397 $report .= ' OS: ' . php_uname() . PHP_EOL;
398 $report .= ' PHP Version: ' . PHP_VERSION . PHP_EOL;
399 $report .= ' The version of the OpenAPI document: 1.0.0' . PHP_EOL;
400 $report .= ' Temp Folder Path: ' . self::getDefaultConfiguration()->getTempFolderPath() . PHP_EOL;
401
402 return $report;
403 }
404
405 /**
406 * Get API key (with prefix if set)
407 *
408 * @param string $apiKeyIdentifier name of apikey
409 *
410 * @return string API key with the prefix
411 */
412 public function getApiKeyWithPrefix($apiKeyIdentifier)
413 {
414 $prefix = $this->getApiKeyPrefix($apiKeyIdentifier);
415 $apiKey = $this->getApiKey($apiKeyIdentifier);
416
417 if ($apiKey === null) {
418 return null;
419 }
420
421 if ($prefix === null) {
422 $keyWithPrefix = $apiKey;
423 } else {
424 $keyWithPrefix = $prefix . ' ' . $apiKey;
425 }
426
427 return $keyWithPrefix;
428 }
429
430 /**
431 * Returns an array of host settings
432 *
433 * @return an array of host settings
434 */
435 public function getHostSettings()
436 {
437 return array(
438 array(
439 "url" => "http://api.monei.com/v1",
440 "description" => "MONEI API v1",
441 )
442 );
443 }
444
445 /**
446 * Returns URL based on the index and variables
447 *
448 * @param index array index of the host settings
449 * @param variables hash of variable and the corresponding value (optional)
450 * @return URL based on host settings
451 */
452 public function getHostFromSettings($index, $variables = null)
453 {
454 if (null === $variables) {
455 $variables = array();
456 }
457
458 $hosts = $this->getHostSettings();
459
460 // check array index out of bound
461 if ($index < 0 || $index >= sizeof($hosts)) {
462 throw new \InvalidArgumentException("Invalid index $index when selecting the host. Must be less than ".sizeof($hosts));
463 }
464
465 $host = $hosts[$index];
466 $url = $host["url"];
467
468 // go through variable and assign a value
469 foreach ($host["variables"] as $name => $variable) {
470 if (array_key_exists($name, $variables)) { // check to see if it's in the variables provided by the user
471 if (in_array($variables[$name], $variable["enum_values"])) { // check to see if the value is in the enum
472 $url = str_replace("{".$name."}", $variables[$name], $url);
473 } else {
474 throw new \InvalidArgumentException("The variable `$name` in the host URL has invalid value ".$variables[$name].". Must be ".join(',', $variable["enum_values"]).".");
475 }
476 } else {
477 // use default value
478 $url = str_replace("{".$name."}", $variable["default_value"], $url);
479 }
480 }
481
482 return $url;
483 }
484 }
485