Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| GetBillingPlanPageQuery | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace ImovelZapAi\Billing\Application\Queries; |
| 6 | |
| 7 | use ImovelZapAi\Organizations\Application\Actions\EnsureOrganizationBootstrapAction; |
| 8 | use ImovelZapAi\Organizations\Application\Queries\GetOrganizationPlanUsageQuery; |
| 9 | use ImovelZapAi\Organizations\Infrastructure\Persistence\Eloquent\SubscriptionPlanModel; |
| 10 | |
| 11 | final class GetBillingPlanPageQuery |
| 12 | { |
| 13 | public function __construct( |
| 14 | private readonly EnsureOrganizationBootstrapAction $bootstrap, |
| 15 | private readonly GetOrganizationPlanUsageQuery $usageQuery, |
| 16 | private readonly \ImovelZapAi\Billing\Application\Actions\SeedCapacityPlansAction $seedPlans, |
| 17 | ) {} |
| 18 | |
| 19 | /** |
| 20 | * @return array<string, mixed> |
| 21 | */ |
| 22 | public function execute(string $tenantId): array |
| 23 | { |
| 24 | $this->seedPlans->execute(); |
| 25 | $this->bootstrap->execute($tenantId); |
| 26 | |
| 27 | $usage = $this->usageQuery->execute($tenantId); |
| 28 | |
| 29 | $catalog = SubscriptionPlanModel::query() |
| 30 | ->where('is_active', true) |
| 31 | ->orderBy('sort_order') |
| 32 | ->orderBy('name') |
| 33 | ->get(); |
| 34 | |
| 35 | return array_merge($usage, [ |
| 36 | 'catalog' => $catalog, |
| 37 | 'billing_enabled' => (bool) config('billing.enabled', true), |
| 38 | 'default_cycle' => (string) config('billing.default_cycle', 'monthly'), |
| 39 | ]); |
| 40 | } |
| 41 | } |