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
← All changes | vendor/payplug/payplug-php/lib/Payplug/Payplug.php +53 -5 1.0.21 → 3.1.0 View file →
@@ -1,7 +1,10 @@
1 1 <?php
2 +
2 3 namespace Payplug;
3 4
5 +use Payplug\Exception\ConfigurationException;
6 +
4 7 /**
5 8 * The client Payplug
6 9 */
7 10 class Payplug
@@ -17,22 +20,32 @@
17 20 */
18 21 private $_token;
19 22
20 23 /**
24 + * @var string The API Version.
25 + */
26 + private $_apiVersion;
27 +
28 + /**
21 29 * Constructor for a authentication.
22 30 *
23 - * @param string $token The token
31 + * @param string $token The token
32 + * @param string $api_version The API Version
24 33 *
25 34 * @throws Exception\ConfigurationException when token is not set
26 35 */
27 - public function __construct($token)
36 + public function __construct($token, $apiVersion = null)
28 37 {
29 38 if (!is_string($token)) {
30 39 throw new Exception\ConfigurationException('Expected string values for token.');
31 40 }
32 41 $this->_token = $token;
42 +
43 + // if no given version then set a default
44 + $this->_apiVersion = $apiVersion ? $apiVersion : '2019-06-14';
33 45 }
34 46
47 +
35 48 /**
36 49 * Initializes a Authentication and sets it as the new default global authentication.
37 50 * It also performs some checks before saving the authentication.
38 51 *
@@ -40,13 +53,14 @@
40 53 * Expected array format for argument $authentication :
41 54 * $authentication['TOKEN'] = 'YOUR TOKEN'
42 55 * </pre>
43 56 *
44 - * @param string $token the authentication token
57 + * @param string $token the authentication token
45 58 *
46 59 * @return Payplug the new client authentication
47 60 *
48 61 * @throws Exception\ConfigurationException
62 + * @deprecated Use Payplug::init(array('secretKey' => 'token', 'apiVersion' => 'version'))
49 63 */
50 64 public static function setSecretKey($token)
51 65 {
52 66 if (!is_string($token)) {
@@ -60,8 +74,32 @@
60 74 return $clientConfiguration;
61 75 }
62 76
63 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 + /**
64 102 * Gets the token corresponding to the mode currently in use (Live token or Test token).
65 103 *
66 104 * @return string The current token
67 105 */
@@ -70,8 +108,18 @@
70 108 return $this->_token;
71 109 }
72 110
73 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 + /**
74 122 * Gets the default global authentication.
75 123 *
76 124 * @return Payplug The last client authentication
77 125 *
@@ -79,9 +127,9 @@
79 127 */
80 128 public static function getDefaultConfiguration()
81 129 {
82 130 if (self::$_defaultConfiguration === null) {
83 - throw new Exception\ConfigurationNotSetException('Unable to find an authentication.');
131 + throw new Exception\ConfigurationNotSetException('Unable to find an authentication.');
84 132 }
85 133
86 134 return self::$_defaultConfiguration;
87 135 }
@@ -89,9 +137,9 @@
89 137 /**
90 138 * Sets the new default client authentication. This authentication will be used when no authentication is explicitly
91 139 * passed to methods.
92 140 *
93 - * @param Payplug $defaultConfiguration the new default authentication
141 + * @param Payplug $defaultConfiguration the new default authentication
94 142 */
95 143 public static function setDefaultConfiguration($defaultConfiguration)
96 144 {
97 145 self::$_defaultConfiguration = $defaultConfiguration;