license-route.php
101 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopEngine\Libs\License; |
| 4 | |
| 5 | |
| 6 | class License_Route extends \ShopEngine\Base\Api { |
| 7 | |
| 8 | public function config() { |
| 9 | |
| 10 | $this->prefix = 'license'; |
| 11 | $this->param = ""; |
| 12 | $this->only_admin = true; |
| 13 | } |
| 14 | |
| 15 | |
| 16 | /** |
| 17 | * /shopengine-builder/v1/license/deactive |
| 18 | * |
| 19 | * http://localhost/shopengine/pro/wp-json/shopengine-builder/v1/license/post_deactive |
| 20 | */ |
| 21 | public function post_deactive() { |
| 22 | |
| 23 | // Check if user has administrator capabilities |
| 24 | if (!current_user_can('manage_options')) { |
| 25 | return [ |
| 26 | 'Status' => 'Fail', |
| 27 | 'msg' => esc_html__('Sorry, you are not allowed to deactivate licenses.', 'shopengine'), |
| 28 | ]; |
| 29 | } |
| 30 | |
| 31 | $res = Helper::instance()->deactivate(); |
| 32 | |
| 33 | //wp_redirect('https://account.wpmet.com/?wpmet-screen=products'); exit; |
| 34 | |
| 35 | return [ |
| 36 | 'success' => 'ok', |
| 37 | 'msg' => esc_html__('Successfully deactivated', 'shopengine'), |
| 38 | ]; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * /shopengine-builder/v1/license/activate |
| 43 | * |
| 44 | * http://localhost/shopengine/pro/wp-json/shopengine-builder/v1/license/activate |
| 45 | */ |
| 46 | public function post_activate() { |
| 47 | |
| 48 | // Check if user has administrator capabilities |
| 49 | if (!current_user_can('manage_options')) { |
| 50 | return [ |
| 51 | 'Status' => 'Fail', |
| 52 | 'msg' => esc_html__('Sorry, you are not allowed to activate licenses.', 'shopengine'), |
| 53 | ]; |
| 54 | } |
| 55 | |
| 56 | $data = json_decode($this->request->get_body(), true); |
| 57 | |
| 58 | if(empty($data['license_key'])) { |
| 59 | |
| 60 | return [ |
| 61 | 'success' => 'danger', |
| 62 | 'dt' => $data, |
| 63 | 'msg' => esc_html__('License key is empty', 'shopengine'), |
| 64 | ]; |
| 65 | } |
| 66 | |
| 67 | $res = Helper::instance()->activate($data['license_key']); |
| 68 | |
| 69 | if(!empty($res->is_activated)) { |
| 70 | |
| 71 | return [ |
| 72 | 'success' => 'ok', |
| 73 | 'dt' => $res, |
| 74 | 'msg' => esc_html__('Successfully activated', 'shopengine'), |
| 75 | ]; |
| 76 | } |
| 77 | |
| 78 | if(!empty($res->error)) { |
| 79 | return [ |
| 80 | 'success' => 'danger', |
| 81 | 'msg' => $res->message, |
| 82 | ]; |
| 83 | } |
| 84 | |
| 85 | return [ |
| 86 | 'success' => 'danger', |
| 87 | 'msg' => esc_html__('Unsupported pro version', 'shopengine'), |
| 88 | ]; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * /shopengine-builder/v1/license/test |
| 93 | * |
| 94 | * http://localhost/shopengine/pro/wp-json/shopengine-builder/v1/license/test |
| 95 | */ |
| 96 | public function get_test() { |
| 97 | |
| 98 | echo 'hello....'; |
| 99 | } |
| 100 | } |
| 101 |