You've already forked wc-licensed-product-client
Add object-oriented license client library (v0.0.2)
- Add LicenseClient with PSR-3 logging and PSR-6 caching support - Add DTO classes: LicenseInfo, LicenseStatus, ActivationResult - Add LicenseState enum for license status values - Add comprehensive exception hierarchy for error handling - Add PSR dependencies (psr/log, psr/cache, psr/http-client) - Update README with usage examples - Update CHANGELOG for v0.0.2 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
90
README.md
90
README.md
@@ -15,12 +15,96 @@ composer require magdev/wc-licensed-product-client
|
||||
|
||||
## Features
|
||||
|
||||
- Easy integration in licensed software packages
|
||||
- Object-oriented client library
|
||||
- PSR-3 logging support
|
||||
- PSR-6 caching support
|
||||
- PSR-18 HTTP client compatible
|
||||
- License validation against domains
|
||||
- License activation on domains
|
||||
- License status checking
|
||||
- Comprehensive exception handling
|
||||
- Built on Symfony HttpClient
|
||||
|
||||
## Usage
|
||||
|
||||
### Basic Usage
|
||||
|
||||
```php
|
||||
use Magdev\WcLicensedProductClient\LicenseClient;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
|
||||
$httpClient = HttpClient::create();
|
||||
$client = new LicenseClient(
|
||||
httpClient: $httpClient,
|
||||
baseUrl: 'https://your-wordpress-site.com',
|
||||
);
|
||||
|
||||
// Validate a license
|
||||
$licenseInfo = $client->validate('ABCD-1234-EFGH-5678', 'example.com');
|
||||
echo "Product ID: " . $licenseInfo->productId;
|
||||
|
||||
// Check license status
|
||||
$status = $client->status('ABCD-1234-EFGH-5678');
|
||||
echo "Status: " . $status->status->value;
|
||||
|
||||
// Activate a license
|
||||
$result = $client->activate('ABCD-1234-EFGH-5678', 'example.com');
|
||||
echo "Activated: " . ($result->success ? 'Yes' : 'No');
|
||||
```
|
||||
|
||||
### With Logging
|
||||
|
||||
```php
|
||||
use Magdev\WcLicensedProductClient\LicenseClient;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
|
||||
$client = new LicenseClient(
|
||||
httpClient: HttpClient::create(),
|
||||
baseUrl: 'https://your-wordpress-site.com',
|
||||
logger: $yourPsrLogger, // Any PSR-3 compatible logger
|
||||
);
|
||||
```
|
||||
|
||||
### With Caching
|
||||
|
||||
```php
|
||||
use Magdev\WcLicensedProductClient\LicenseClient;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
|
||||
$client = new LicenseClient(
|
||||
httpClient: HttpClient::create(),
|
||||
baseUrl: 'https://your-wordpress-site.com',
|
||||
cache: $yourPsrCache, // Any PSR-6 compatible cache
|
||||
cacheTtl: 600, // Cache TTL in seconds (default: 300)
|
||||
);
|
||||
```
|
||||
|
||||
### Exception Handling
|
||||
|
||||
```php
|
||||
use Magdev\WcLicensedProductClient\Exception\LicenseNotFoundException;
|
||||
use Magdev\WcLicensedProductClient\Exception\LicenseExpiredException;
|
||||
use Magdev\WcLicensedProductClient\Exception\DomainMismatchException;
|
||||
use Magdev\WcLicensedProductClient\Exception\RateLimitExceededException;
|
||||
use Magdev\WcLicensedProductClient\Exception\LicenseException;
|
||||
|
||||
try {
|
||||
$licenseInfo = $client->validate($licenseKey, $domain);
|
||||
} catch (LicenseNotFoundException $e) {
|
||||
// License key does not exist
|
||||
} catch (LicenseExpiredException $e) {
|
||||
// License has expired
|
||||
} catch (DomainMismatchException $e) {
|
||||
// License is not valid for this domain
|
||||
} catch (RateLimitExceededException $e) {
|
||||
// Too many requests, retry after $e->retryAfter seconds
|
||||
} catch (LicenseException $e) {
|
||||
// Other license-related errors
|
||||
}
|
||||
```
|
||||
|
||||
## API Endpoints
|
||||
|
||||
This client interacts with the following WooCommerce Licensed Product API endpoints:
|
||||
@@ -29,10 +113,6 @@ This client interacts with the following WooCommerce Licensed Product API endpoi
|
||||
- **POST /status** - Get detailed license status information
|
||||
- **POST /activate** - Activate a license on a domain
|
||||
|
||||
## Usage
|
||||
|
||||
Coming soon in future versions.
|
||||
|
||||
## License
|
||||
|
||||
GPL-2.0-or-later
|
||||
|
||||
Reference in New Issue
Block a user