1 | <?php namespace EmailLog\Addon\License; |
||
12 | abstract class BaseLicense { |
||
13 | |||
14 | protected $addon_name; |
||
15 | protected $license_key; |
||
16 | protected $license_data; |
||
17 | |||
18 | /** |
||
19 | * EDD API Wrapper. |
||
20 | * |
||
21 | * @var \EmailLog\Addon\API\EDDAPI |
||
22 | */ |
||
23 | protected $edd_api; |
||
24 | |||
25 | /** |
||
26 | * Is the license activated and valid? |
||
27 | * |
||
28 | * @return bool True if license is active, False otherwise. |
||
29 | */ |
||
30 | abstract public function is_valid(); |
||
31 | |||
32 | /** |
||
33 | * Get the option name in which license data will be stored. |
||
34 | * |
||
35 | * @return string Option name. |
||
36 | */ |
||
37 | abstract protected function get_option_name(); |
||
38 | |||
39 | /** |
||
40 | * Construct a new License object. |
||
41 | * If the API Wrapper is not provided, then a new one is initialized. |
||
42 | * |
||
43 | * @param \EmailLog\Addon\API\EDDAPI|null $edd_api (Optional) EDD API Wrapper instance. Default is null. |
||
44 | */ |
||
45 | public function __construct( $edd_api = null ) { |
||
52 | |||
53 | /** |
||
54 | * Set the license Key. |
||
55 | * |
||
56 | * @param string $license_key License Key. |
||
57 | */ |
||
58 | public function set_license_key( $license_key ) { |
||
61 | |||
62 | /** |
||
63 | * Get the license key. |
||
64 | * |
||
65 | * @return string|null License Key. |
||
66 | */ |
||
67 | public function get_license_key() { |
||
68 | return $this->license_key; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Set add-on name. |
||
73 | * |
||
74 | * @param string $addon_name Add-on Name. |
||
75 | */ |
||
76 | public function set_addon_name( $addon_name ) { |
||
79 | |||
80 | /** |
||
81 | * Get the add-on name. |
||
82 | * |
||
83 | * @return string Add-on name. |
||
84 | */ |
||
85 | public function get_addon_name() { |
||
88 | |||
89 | /** |
||
90 | * Get the expiry date of the license. |
||
91 | * |
||
92 | * @return false|string Expiry date in `yyyy-mm-dd hh:mm:ss` format if license is valid, False otherwise. |
||
93 | */ |
||
94 | public function get_expiry_date() { |
||
101 | |||
102 | /** |
||
103 | * Activate License by calling EDD API. |
||
104 | * The license data returned by API is stored in an option. |
||
105 | * |
||
106 | * @throws \Exception In case of communication errors or License Issues. |
||
107 | * |
||
108 | * @return object API Response JSON Object. |
||
109 | */ |
||
110 | public function activate() { |
||
157 | |||
158 | /** |
||
159 | * Deactivate the license by calling EDD API. |
||
160 | * The stored license data will be cleared. |
||
161 | * |
||
162 | * @throws \Exception In case of communication errors. |
||
163 | * |
||
164 | * @return object API Response JSON object. |
||
165 | */ |
||
166 | public function deactivate() { |
||
183 | |||
184 | /** |
||
185 | * Get version information by calling EDD API. |
||
186 | * // TODO: Currently not used. Will be removed eventually. |
||
187 | * |
||
188 | * @throws \Exception In case of communication errors. |
||
189 | * |
||
190 | * @return object API Response JSON Object. |
||
191 | */ |
||
192 | public function get_version() { |
||
203 | |||
204 | /** |
||
205 | * Load the license data from DB option. |
||
206 | */ |
||
207 | public function load() { |
||
210 | |||
211 | /** |
||
212 | * Store License data in DB option. |
||
213 | * |
||
214 | * @access protected |
||
215 | * |
||
216 | * @param object $license_data License data. |
||
217 | */ |
||
218 | protected function store( $license_data ) { |
||
222 | |||
223 | /** |
||
224 | * Clear stored license data. |
||
225 | * |
||
226 | * @access protected |
||
227 | */ |
||
228 | protected function clear() { |
||
233 | } |
||
234 |