/**
  * @param Wslm_LicenseManagerApiResponse $result
  * @param string|null $licenseKey
  * @param string|null $siteToken
  * @return Wslm_ProductLicense|WP_Error
  */
 private function processActivationResponse($result, $licenseKey = null, $siteToken = null)
 {
     if ($result->success()) {
         //Success! Lets save our license data.
         $this->license = $this->createLicenseObject($result->response->license);
         $this->siteToken = isset($result->response->site_token) ? $result->response->site_token : $siteToken;
         $this->licenseKey = $this->storeLicenseKey ? $licenseKey : null;
         if (!isset($this->license['site_url']) && !empty($this->siteToken)) {
             $this->license['site_url'] = $this->getSiteUrl();
         }
         if ($this->tokenHistorySize > 0 && !empty($this->siteToken)) {
             //Add this token+site combination to the bottom of the list.
             $this->tokenHistory = isset($this->tokenHistory) ? $this->tokenHistory : array();
             unset($this->tokenHistory[$this->siteToken]);
             $this->tokenHistory[$this->siteToken] = $this->getSiteUrl();
         }
         do_action('wslm_license_activated-' . $this->productSlug, $this->license);
         $this->save();
         //Now that we have a valid license, an update might be available. Clear the cache.
         if ($this->updateChecker !== null) {
             $this->updateChecker->resetUpdateState();
         }
         return $this->license;
     } else {
         $error = $result->asWpError();
         if (isset($result->response->license)) {
             $error->add_data($this->createLicenseObject($result->response->license), 'license');
         }
         return $error;
     }
 }
Esempio n. 2
0
 /**
  * @param $licenseKey
  * @return Wslm_ProductLicense|WP_Error
  */
 public function licenseThisSite($licenseKey)
 {
     $result = $this->api->licenseSite($this->productSlug, $licenseKey, $this->getSiteUrl());
     if ($result->success()) {
         //Success! Lets save our license data.
         $this->license = $this->createLicenseObject($result->response->license);
         $this->siteToken = $result->response->site_token;
         $this->licenseKey = $licenseKey;
         $this->save();
         //Now that we have a valid license, an update might be available. Clear the cache.
         if ($this->updateChecker !== null) {
             $this->updateChecker->resetUpdateState();
         }
         return $this->license;
     } else {
         $error = $result->asWpError();
         if (isset($result->response->license)) {
             $error->add_data($this->createLicenseObject($result->response->license), 'license');
         }
         return $error;
     }
 }