PluginProbe
PayPlug for WooCommerce (Official) / 3.1.0
PayPlug for WooCommerce (Official) v3.1.0
3.1.0 3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 All 102 releases
payplug / vendor / payplug / payplug-php / lib / Payplug / Payplug.php

Payplug.php in PayPlug for WooCommerce (Official) 3.1.0, at vendor/payplug/payplug-php/lib/Payplug/Payplug.php

148 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Payplug;
4
5 use Payplug\Exception\ConfigurationException;
6
7 /**
8 * The client Payplug
9 */
10 class Payplug
11 {
12 /**
13 * @var Payplug|null The default authentication that should be used when no authentication is
14 * provided.
15 */
16 private static $_defaultConfiguration = null;
17
18 /**
19 * @var string The token.
20 */
21 private $_token;
22
23 /**
24 * @var string The API Version.
25 */
26 private $_apiVersion;
27
28 /**
29 * Constructor for a authentication.
30 *
31 * @param string $token The token
32 * @param string $api_version The API Version
33 *
34 * @throws Exception\ConfigurationException when token is not set
35 */
36 public function __construct($token, $apiVersion = null)
37 {
38 if (!is_string($token)) {
39 throw new Exception\ConfigurationException('Expected string values for token.');
40 }
41 $this->_token = $token;
42
43 // if no given version then set a default
44 $this->_apiVersion = $apiVersion ? $apiVersion : '2019-06-14';
45 }
46
47
48 /**
49 * Initializes a Authentication and sets it as the new default global authentication.
50 * It also performs some checks before saving the authentication.
51 *
52 * <pre>
53 * Expected array format for argument $authentication :
54 * $authentication['TOKEN'] = 'YOUR TOKEN'
55 * </pre>
56 *
57 * @param string $token the authentication token
58 *
59 * @return Payplug the new client authentication
60 *
61 * @throws Exception\ConfigurationException
62 * @deprecated Use Payplug::init(array('secretKey' => 'token', 'apiVersion' => 'version'))
63 */
64 public static function setSecretKey($token)
65 {
66 if (!is_string($token)) {
67 throw new Exception\ConfigurationException('Expected string values for the token.');
68 }
69
70 $clientConfiguration = new Payplug($token);
71
72 self::setDefaultConfiguration($clientConfiguration);
73
74 return $clientConfiguration;
75 }
76
77 /**
78 * Initializes a Authentication and sets it as the new default global authentication.
79 * It also performs some checks before saving the authentication and set the API version
80 *
81 * @param array $props
82 * @return Payplug
83 * @throws ConfigurationException
84 */
85 public static function init($props)
86 {
87 $secretKey = isset($props['secretKey']) && $props['secretKey'] ? $props['secretKey'] : null;
88 $apiVersion = isset($props['apiVersion']) && $props['apiVersion'] ? $props['apiVersion'] : null;
89
90 if (!$secretKey) {
91 throw new Exception\ConfigurationException('Expected string values for the token.');
92 }
93
94 $clientConfiguration = new Payplug($secretKey, $apiVersion);
95
96 self::setDefaultConfiguration($clientConfiguration);
97
98 return $clientConfiguration;
99 }
100
101 /**
102 * Gets the token corresponding to the mode currently in use (Live token or Test token).
103 *
104 * @return string The current token
105 */
106 public function getToken()
107 {
108 return $this->_token;
109 }
110
111 /**
112 * Sets the API Version corresponding to the module currently in use.
113 *
114 * @return string
115 */
116 public function getApiVersion()
117 {
118 return $this->_apiVersion;
119 }
120
121 /**
122 * Gets the default global authentication.
123 *
124 * @return Payplug The last client authentication
125 *
126 * @throws Exception\ConfigurationNotSetException when the global authentication was not set.
127 */
128 public static function getDefaultConfiguration()
129 {
130 if (self::$_defaultConfiguration === null) {
131 throw new Exception\ConfigurationNotSetException('Unable to find an authentication.');
132 }
133
134 return self::$_defaultConfiguration;
135 }
136
137 /**
138 * Sets the new default client authentication. This authentication will be used when no authentication is explicitly
139 * passed to methods.
140 *
141 * @param Payplug $defaultConfiguration the new default authentication
142 */
143 public static function setDefaultConfiguration($defaultConfiguration)
144 {
145 self::$_defaultConfiguration = $defaultConfiguration;
146 }
147 }
148