PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.3.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.3.3
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Models / ApiToken.php
ApiToken.php
79 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Models;
4
5 use SureCart\Support\Encryption;
6
7 /**
8 * The API token model.
9 */
10 class ApiToken {
11
12 /**
13 * The option key.
14 *
15 * @var string
16 */
17 protected $key = 'sc_api_token';
18
19 /**
20 * Prevent php warnings.
21 */
22 final public function __construct() {}
23
24 /**
25 * Clear the API token.
26 *
27 * @return bool True if the value was updated, false otherwise.
28 */
29 protected function clear() {
30 return delete_option( $this->key );
31 }
32
33 /**
34 * Save and encrypt the API token.
35 *
36 * @param string $value The API token.
37 * @return bool True if the value was updated, false otherwise.
38 */
39 protected function save( $value ) {
40 $saved = update_option( $this->key, Encryption::encrypt( $value ) );
41 \SureCart::requests()->setToken( $value );
42 return $saved;
43 }
44
45 /**
46 * Get and decrypt the API token
47 *
48 * @return string The decoded API token.
49 */
50 protected function get() {
51 if ( defined( 'SURECART_API_TOKEN' ) ) {
52 return SURECART_API_TOKEN;
53 }
54 return Encryption::decrypt( get_option( $this->key, '' ) );
55 }
56
57 /**
58 * Forward call to method
59 *
60 * @param string $method Method to call.
61 * @param mixed $params Method params.
62 */
63 public function __call( $method, $params ) {
64 return call_user_func_array( [ $this, $method ], $params );
65 }
66
67 /**
68 * Static Facade Accessor
69 *
70 * @param string $method Method to call.
71 * @param mixed $params Method params.
72 *
73 * @return mixed
74 */
75 public static function __callStatic( $method, $params ) {
76 return call_user_func_array( [ new static(), $method ], $params );
77 }
78 }
79