give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Responses
/
Credit
/
Refund.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
Refund.php
80 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 | |
| 7 | /** |
| 8 | * Represents a successful credit refund response. |
| 9 | * |
| 10 | * @implements Response<array{ |
| 11 | * credits_refunded: int, |
| 12 | * pool_remaining: int, |
| 13 | * site_remaining: int|null, |
| 14 | * pool_breakdown: array<array-key, int> |
| 15 | * }> |
| 16 | */ |
| 17 | final class Refund implements Response |
| 18 | { |
| 19 | public int $creditsRefunded; |
| 20 | |
| 21 | public int $poolRemaining; |
| 22 | |
| 23 | public ?int $siteRemaining; |
| 24 | |
| 25 | /** |
| 26 | * @var array<int, int> |
| 27 | */ |
| 28 | public array $poolBreakdown; |
| 29 | |
| 30 | /** |
| 31 | * @param array<int, int> $poolBreakdown |
| 32 | */ |
| 33 | private function __construct(int $creditsRefunded, int $poolRemaining, ?int $siteRemaining, array $poolBreakdown) { |
| 34 | $this->creditsRefunded = $creditsRefunded; |
| 35 | $this->poolRemaining = $poolRemaining; |
| 36 | $this->siteRemaining = $siteRemaining; |
| 37 | $this->poolBreakdown = $poolBreakdown; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @param array{ |
| 42 | * credits_refunded: int, |
| 43 | * pool_remaining: int, |
| 44 | * site_remaining: int|null, |
| 45 | * pool_breakdown: array<array-key, int> |
| 46 | * } $attributes |
| 47 | */ |
| 48 | public static function from(array $attributes): self { |
| 49 | $poolBreakdown = []; |
| 50 | |
| 51 | foreach ($attributes['pool_breakdown'] as $poolId => $creditsRefunded) { |
| 52 | $poolBreakdown[(int) $poolId] = $creditsRefunded; |
| 53 | } |
| 54 | |
| 55 | return new self( |
| 56 | $attributes['credits_refunded'], |
| 57 | $attributes['pool_remaining'], |
| 58 | $attributes['site_remaining'], |
| 59 | $poolBreakdown |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @return array{ |
| 65 | * credits_refunded: int, |
| 66 | * pool_remaining: int, |
| 67 | * site_remaining: int|null, |
| 68 | * pool_breakdown: array<int, int> |
| 69 | * } |
| 70 | */ |
| 71 | public function toArray(): array { |
| 72 | return [ |
| 73 | 'credits_refunded' => $this->creditsRefunded, |
| 74 | 'pool_remaining' => $this->poolRemaining, |
| 75 | 'site_remaining' => $this->siteRemaining, |
| 76 | 'pool_breakdown' => $this->poolBreakdown, |
| 77 | ]; |
| 78 | } |
| 79 | } |
| 80 |