give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Responses
/
Credit
/
BalanceCollection.php
give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Responses
/
Credit
Last commit date
ValueObjects
3 months ago
BalanceCollection.php
3 months ago
DeletePool.php
3 months ago
DeleteQuota.php
3 months ago
LedgerPage.php
3 months ago
PoolCollection.php
3 months ago
QuotaCollection.php
3 months ago
RecordUsage.php
3 months ago
Refund.php
3 months ago
BalanceCollection.php
92 lines
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace Give\Vendors\LiquidWeb\LicensingApiClient\Responses\Credit; |
| 4 | |
| 5 | use Give\Vendors\LiquidWeb\LicensingApiClient\Responses\Contracts\Response; |
| 6 | use Give\Vendors\LiquidWeb\LicensingApiClient\Responses\Credit\ValueObjects\BalanceEntry; |
| 7 | |
| 8 | /** |
| 9 | * Represents the credit balance response across one or more credit types. |
| 10 | * |
| 11 | * @implements Response<array{ |
| 12 | * credits: list<array{ |
| 13 | * credit_type: string, |
| 14 | * remaining: int, |
| 15 | * site_quota: int|null, |
| 16 | * site_used: int, |
| 17 | * site_remaining: int, |
| 18 | * aggregate_total: int, |
| 19 | * aggregate_used: int, |
| 20 | * aggregate_remaining: int, |
| 21 | * aggregate_overage: int, |
| 22 | * pools: list<array{ |
| 23 | * pool_id: int, |
| 24 | * pool_remaining: int, |
| 25 | * priority: int, |
| 26 | * period: string, |
| 27 | * resets_on: string|null, |
| 28 | * expires_at: string|null, |
| 29 | * credits_total?: int, |
| 30 | * credits_used?: int, |
| 31 | * overage?: int, |
| 32 | * overage_limit?: int|null |
| 33 | * }> |
| 34 | * }> |
| 35 | * }> |
| 36 | */ |
| 37 | final class BalanceCollection implements Response |
| 38 | { |
| 39 | /** @var list<BalanceEntry> */ |
| 40 | public array $credits; |
| 41 | |
| 42 | /** |
| 43 | * @param list<BalanceEntry> $credits |
| 44 | */ |
| 45 | private function __construct(array $credits) { |
| 46 | $this->credits = $credits; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @param array{ |
| 51 | * credits: list<array{ |
| 52 | * credit_type: string, |
| 53 | * remaining: int, |
| 54 | * site_quota: int|null, |
| 55 | * site_used: int, |
| 56 | * site_remaining: int, |
| 57 | * aggregate_total: int, |
| 58 | * aggregate_used: int, |
| 59 | * aggregate_remaining: int, |
| 60 | * aggregate_overage: int, |
| 61 | * pools: list<array{ |
| 62 | * pool_id: int, |
| 63 | * pool_remaining: int, |
| 64 | * priority: int, |
| 65 | * period: string, |
| 66 | * resets_on: string|null, |
| 67 | * expires_at: string|null, |
| 68 | * credits_total?: int, |
| 69 | * credits_used?: int, |
| 70 | * overage?: int, |
| 71 | * overage_limit?: int|null |
| 72 | * }> |
| 73 | * }> |
| 74 | * } $attributes |
| 75 | */ |
| 76 | public static function from(array $attributes): self { |
| 77 | return new self(array_map( |
| 78 | static fn (array $credit): BalanceEntry => BalanceEntry::from($credit), |
| 79 | $attributes['credits'] |
| 80 | )); |
| 81 | } |
| 82 | |
| 83 | public function toArray(): array { |
| 84 | return [ |
| 85 | 'credits' => array_map( |
| 86 | static fn (BalanceEntry $credit): array => $credit->toArray(), |
| 87 | $this->credits |
| 88 | ), |
| 89 | ]; |
| 90 | } |
| 91 | } |
| 92 |