paid premium plugins you have subscribed to. * * @method static \Piwik\Plugins\Marketplace\API getInstance() */ class API extends \Piwik\Plugin\API { /** * @var Client */ private $marketplaceClient; /** * @var Service */ private $marketplaceService; /** * @var InvalidLicenses */ private $expired; public function __construct(Service $service, Client $client, InvalidLicenses $expired) { $this->marketplaceService = $service; $this->marketplaceClient = $client; $this->expired = $expired; } /** * Deletes an existing license key if one is set. * * @return bool */ public function deleteLicenseKey() { Piwik::checkUserHasSuperUserAccess(); $this->setLicenseKey(null); return true; } /** * Saves the given license key in case the key is actually valid (exists on the Matomo Marketplace and is not * yet expired). * * @param string $licenseKey * @return bool * * @throws Exception In case of an invalid license key * @throws Service\Exception In case of any network problems */ public function saveLicenseKey($licenseKey) { Piwik::checkUserHasSuperUserAccess(); $licenseKey = trim($licenseKey); // we are currently using the Marketplace service directly to 1) change LicenseKey and 2) not use any cache $this->marketplaceService->authenticate($licenseKey); try { $consumer = $this->marketplaceService->fetch('consumer/validate', array()); } catch (Api\Service\Exception $e) { if ($e->getCode() === Api\Service\Exception::HTTP_ERROR) { throw $e; } $consumer = array(); } if (empty($consumer['isValid'])) { throw new Exception(Piwik::translate('Marketplace_ExceptionLinceseKeyIsNotValid')); } $this->setLicenseKey($licenseKey); return true; } private function setLicenseKey($licenseKey) { $key = new LicenseKey(); $key->set($licenseKey); $this->marketplaceClient->clearAllCacheEntries(); $this->expired->clearCache(); } }