give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Requests
/
Credit
/
SetQuota.php
give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Requests
/
Credit
Last commit date
CreatePool.php
3 months ago
DeletePool.php
3 months ago
ListLedgerEntries.php
3 months ago
RecordUsage.php
3 months ago
Refund.php
3 months ago
SetQuota.php
3 months ago
UpdatePool.php
3 months ago
SetQuota.php
123 lines
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace Give\Vendors\LiquidWeb\LicensingApiClient\Requests\Credit; |
| 4 | |
| 5 | use DateTimeImmutable; |
| 6 | use Give\Vendors\LiquidWeb\LicensingApiClient\Concerns\InteractsWithDateTime; |
| 7 | |
| 8 | /** |
| 9 | * Represents a site quota write request payload. |
| 10 | * |
| 11 | * `quota` semantics: |
| 12 | * - `null` means uncapped and is omitted from the outgoing payload |
| 13 | * - `0` means blocked |
| 14 | * - a positive integer means a fixed quota |
| 15 | * |
| 16 | * `firstPeriodStart` is normalized to the API's canonical UTC datetime format. |
| 17 | * |
| 18 | * @phpstan-type SetQuotaPayload array{ |
| 19 | * license_key: string, |
| 20 | * domain: string, |
| 21 | * credit_type: string, |
| 22 | * quota?: int, |
| 23 | * period: string, |
| 24 | * first_period_start?: string, |
| 25 | * metadata?: array<string, mixed> |
| 26 | * } |
| 27 | */ |
| 28 | final class SetQuota |
| 29 | { |
| 30 | use InteractsWithDateTime; |
| 31 | |
| 32 | /** |
| 33 | * License key that owns the quota. |
| 34 | * |
| 35 | * @example LWSW-8H9F-5UKA-VR3B-D7SQ-BP9N |
| 36 | */ |
| 37 | public string $licenseKey; |
| 38 | |
| 39 | /** |
| 40 | * Site domain the quota applies to. |
| 41 | * |
| 42 | * @example example.com |
| 43 | */ |
| 44 | public string $domain; |
| 45 | |
| 46 | /** |
| 47 | * Credit type identifier. |
| 48 | * |
| 49 | * @example ai |
| 50 | */ |
| 51 | public string $creditType; |
| 52 | |
| 53 | /** |
| 54 | * Quota amount for the domain. |
| 55 | * |
| 56 | * @example null Uncapped |
| 57 | * @example 0 Blocked |
| 58 | * @example 100 Fixed quota |
| 59 | */ |
| 60 | public ?int $quota; |
| 61 | |
| 62 | /** |
| 63 | * Quota period strategy. |
| 64 | * |
| 65 | * @example lifetime |
| 66 | * @example month |
| 67 | * @example week |
| 68 | */ |
| 69 | public string $period; |
| 70 | |
| 71 | /** |
| 72 | * UTC anchor for period calculations. |
| 73 | * |
| 74 | * @example new DateTimeImmutable('2026-03-01T00:00:00Z') |
| 75 | */ |
| 76 | public ?DateTimeImmutable $firstPeriodStart; |
| 77 | |
| 78 | /** |
| 79 | * Structured metadata passed through to the API. |
| 80 | * |
| 81 | * @var array<string, mixed>|null |
| 82 | * |
| 83 | * @example ['source' => 'portal'] |
| 84 | */ |
| 85 | public ?array $metadata; |
| 86 | |
| 87 | /** |
| 88 | * @param array<string, mixed>|null $metadata |
| 89 | */ |
| 90 | public function __construct( |
| 91 | string $licenseKey, |
| 92 | string $domain, |
| 93 | string $creditType, |
| 94 | ?int $quota = null, |
| 95 | string $period = 'lifetime', |
| 96 | ?DateTimeImmutable $firstPeriodStart = null, |
| 97 | ?array $metadata = null |
| 98 | ) { |
| 99 | $this->licenseKey = $licenseKey; |
| 100 | $this->domain = $domain; |
| 101 | $this->creditType = $creditType; |
| 102 | $this->quota = $quota; |
| 103 | $this->period = $period; |
| 104 | $this->firstPeriodStart = $firstPeriodStart; |
| 105 | $this->metadata = $metadata; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @return SetQuotaPayload |
| 110 | */ |
| 111 | public function toArray(): array { |
| 112 | return array_filter([ |
| 113 | 'license_key' => $this->licenseKey, |
| 114 | 'domain' => $this->domain, |
| 115 | 'credit_type' => $this->creditType, |
| 116 | 'quota' => $this->quota, |
| 117 | 'period' => $this->period, |
| 118 | 'first_period_start' => $this->firstPeriodStart ? $this->formatDateTime($this->firstPeriodStart) : null, |
| 119 | 'metadata' => $this->metadata, |
| 120 | ], static fn ($value): bool => $value !== null); |
| 121 | } |
| 122 | } |
| 123 |