license-route.php
84 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 | } |
| 13 | |
| 14 | |
| 15 | /** |
| 16 | * /shopengine-builder/v1/license/deactive |
| 17 | * |
| 18 | * http://localhost/shopengine/pro/wp-json/shopengine-builder/v1/license/post_deactive |
| 19 | */ |
| 20 | public function post_deactive() { |
| 21 | |
| 22 | $res = Helper::instance()->deactivate(); |
| 23 | |
| 24 | //wp_redirect('https://account.wpmet.com/?wpmet-screen=products'); exit; |
| 25 | |
| 26 | return [ |
| 27 | 'success' => 'ok', |
| 28 | 'msg' => esc_html__('Successfully deactivated', 'shopengine'), |
| 29 | ]; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * /shopengine-builder/v1/license/activate |
| 34 | * |
| 35 | * http://localhost/shopengine/pro/wp-json/shopengine-builder/v1/license/activate |
| 36 | */ |
| 37 | public function post_activate() { |
| 38 | |
| 39 | $data = json_decode($this->request->get_body(), true); |
| 40 | |
| 41 | if(empty($data['license_key'])) { |
| 42 | |
| 43 | return [ |
| 44 | 'success' => 'danger', |
| 45 | 'dt' => $data, |
| 46 | 'msg' => esc_html__('License key is empty', 'shopengine'), |
| 47 | ]; |
| 48 | } |
| 49 | |
| 50 | $res = Helper::instance()->activate($data['license_key']); |
| 51 | |
| 52 | if(!empty($res->is_activated)) { |
| 53 | |
| 54 | return [ |
| 55 | 'success' => 'ok', |
| 56 | 'dt' => $res, |
| 57 | 'msg' => esc_html__('Successfully activated', 'shopengine'), |
| 58 | ]; |
| 59 | } |
| 60 | |
| 61 | if(!empty($res->error)) { |
| 62 | return [ |
| 63 | 'success' => 'danger', |
| 64 | 'msg' => $res->message, |
| 65 | ]; |
| 66 | } |
| 67 | |
| 68 | return [ |
| 69 | 'success' => 'danger', |
| 70 | 'msg' => esc_html__('Unsupported pro version', 'shopengine'), |
| 71 | ]; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * /shopengine-builder/v1/license/test |
| 76 | * |
| 77 | * http://localhost/shopengine/pro/wp-json/shopengine-builder/v1/license/test |
| 78 | */ |
| 79 | public function get_test() { |
| 80 | |
| 81 | echo 'hello....'; |
| 82 | } |
| 83 | } |
| 84 |