| @@ -13,8 +13,12 @@ | ||
| 13 | 13 | if ( '/templately/v1/login' === $_route ) { |
| 14 | 14 | return true; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | + if ( '/templately/v1/pricing' === $_route ) { | |
| 18 | + return true; | |
| 19 | + } | |
| 20 | + | |
| 17 | 21 | return parent::permission_check( $request ); |
| 18 | 22 | } |
| 19 | 23 | |
| 20 | 24 | public function register_routes() { |
| @@ -20,9 +24,28 @@ | ||
| 20 | 24 | public function register_routes() { |
| 21 | 25 | $this->post( 'login', [$this, 'login'] ); |
| 22 | 26 | $this->post( 'logout', [$this, 'logout'] ); |
| 23 | 27 | $this->get( 'is-signed', [$this, 'is_signed'] ); |
| 28 | + $this->get( 'pricing', [$this, 'pricing'] ); | |
| 24 | 29 | } |
| 30 | + | |
| 31 | + public function pricing(){ | |
| 32 | + $data = get_transient( "templately_subscriptions" ); | |
| 33 | + | |
| 34 | + if( is_array( $data ) && ! empty( $data ) ) { | |
| 35 | + return $data; | |
| 36 | + } | |
| 37 | + | |
| 38 | + $query = 'id, price, name, discounted_price, type, sites'; | |
| 39 | + $response = $this->http()->query( | |
| 40 | + 'subscriptionPlans', | |
| 41 | + $query, | |
| 42 | + )->post(); | |
| 43 | + | |
| 44 | + set_transient( "templately_subscriptions", $response, WEEK_IN_SECONDS ); | |
| 45 | + | |
| 46 | + return $response; | |
| 47 | + } | |
| 25 | 48 | |
| 26 | 49 | public function login() { |
| 27 | 50 | $errors = []; |
| 28 | 51 | $_ip = Helper::get_ip(); |