/**
  * Verify user entitlement
  *
  * @return bool|\WP_Error Whether user has entitlement or error message
  */
 public function verify_entitlement()
 {
     $auth_token = '';
     $product_id = '';
     if (!empty($_REQUEST['authToken'])) {
         $auth_token = trim($_REQUEST['authToken']);
     }
     if (!empty($_REQUEST['productId'])) {
         $product_id = trim($_REQUEST['productId']);
     }
     if ('' === $product_id) {
         // Empty Product ID
         return Util::get_wp_error('product-required');
     }
     // Get user from auth token
     $user = User::get_user_from_auth_token($auth_token);
     if ($user && !is_wp_error($user)) {
         // Check if user has entitlement
         $has_entitlement = $user->has_entitlement($product_id);
     } else {
         // Error getting user from auth token
         $has_entitlement = $user;
     }
     return $has_entitlement;
 }
 /**
  * Get entitlements from request based on auth token and corresponding user
  *
  * @return array|\WP_Error List of entitlements or error message
  */
 public function get_entitlements()
 {
     $entitlements = array();
     // Get auth token
     $auth_token = '';
     if (!empty($_REQUEST['authToken'])) {
         $auth_token = trim($_REQUEST['authToken']);
     }
     // Get user from auth token
     $user = User::get_user_from_auth_token($auth_token);
     if (!is_wp_error($user)) {
         // Get entitlements for user
         $entitlements = $user->get_entitlements();
     } else {
         // No user for auth token found
         $this->response_code = Server::HTTP_FORBIDDEN;
         $this->error = $user;
     }
     return $entitlements;
 }
 /**
  * Renew auth token or revoke if inactive
  *
  * @return string|\WP_Error Auth token or error message
  */
 public function renew_auth_token()
 {
     $auth_token = '';
     $uuid = '';
     if (!empty($_REQUEST['authToken'])) {
         $auth_token = trim($_REQUEST['authToken']);
     }
     if (!empty($_REQUEST['uuid'])) {
         $uuid = trim($_REQUEST['uuid']);
     }
     if (!empty($uuid)) {
         // Get user from auth token
         $user = User::get_user_from_auth_token($auth_token);
         if (!is_wp_error($user)) {
             // Check if subscription is active
             $subscription_is_active = $user->is_subscription_active();
             if ($subscription_is_active) {
                 // Check if UUID is registered
                 if (!$user->is_uuid_allowed($uuid, false)) {
                     $auth_token = Util::get_wp_error('uuid-not-registered');
                 }
             } else {
                 // Subscription is not active
                 // Delete auth token from user
                 $user->delete_auth_token();
                 $auth_token = Util::get_wp_error('subscription-inactive');
             }
         } else {
             // Error getting user from auth token
             $auth_token = $user;
         }
     } else {
         // Missing UUID
         $auth_token = Util::get_wp_error('uuid-invalid');
     }
     return $auth_token;
 }