Add update-check endpoint support (v0.2.1)

Implement /update-check endpoint aligned with remote OpenAPI spec:
- Add checkForUpdates() method to LicenseClientInterface
- Add UpdateInfo DTO for update check responses
- Add ProductNotFoundException for product_not_found error
- Update local openapi.json to v0.4.0

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-27 20:52:12 +01:00
parent 5e4b5a970f
commit 760e1e752a
11 changed files with 633 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ namespace Magdev\WcLicensedProductClient;
use Magdev\WcLicensedProductClient\Dto\ActivationResult;
use Magdev\WcLicensedProductClient\Dto\LicenseInfo;
use Magdev\WcLicensedProductClient\Dto\LicenseStatus;
use Magdev\WcLicensedProductClient\Dto\UpdateInfo;
use Magdev\WcLicensedProductClient\Exception\LicenseException;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
@@ -144,6 +145,57 @@ final class LicenseClient implements LicenseClientInterface
return $result;
}
public function checkForUpdates(
string $licenseKey,
string $domain,
?string $pluginSlug = null,
?string $currentVersion = null,
): UpdateInfo {
$cacheKey = $this->buildCacheKey('update-check', $licenseKey, $domain);
if ($this->cache !== null) {
$item = $this->cache->getItem($cacheKey);
if ($item->isHit()) {
$this->logger->debug('Update check cache hit', ['domain' => $domain]);
return $item->get();
}
}
$this->logger->info('Checking for updates', ['domain' => $domain]);
$payload = [
'license_key' => $licenseKey,
'domain' => $domain,
];
if ($pluginSlug !== null) {
$payload['plugin_slug'] = $pluginSlug;
}
if ($currentVersion !== null) {
$payload['current_version'] = $currentVersion;
}
$response = $this->request('update-check', $payload);
$result = UpdateInfo::fromArray($response);
if ($this->cache !== null) {
$item = $this->cache->getItem($cacheKey);
$item->set($result);
$item->expiresAfter($this->cacheTtl);
$this->cache->save($item);
}
$this->logger->info('Update check completed', [
'domain' => $domain,
'update_available' => $result->updateAvailable,
'version' => $result->version,
]);
return $result;
}
/**
* @throws LicenseException
*/