-
app/Services/PricingService.php
Open in GitHubuse Illuminate\Support\Arr; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Http; class PricingService { protected $config; protected $region = 'us-ohio'; protected $apiKey; public function __construct() { $this->config = Config::get('laracloud'); $this->apiKey = env('OPENAI_API_KEY'); } // ... public function getPostgresMinCpu(): float { return Arr::get($this->config, "database.{$this->region}.postgres.min_cpu", 0.25); } public function getMySqlDefaultSizeKey(): ?string { $sizes = $this->getAvailableMySqlSizes(); return !empty($sizes) ? array_key_first($sizes) : null; } public function getKvDefaultTierKey(): ?string { $tiers = $this->getAvailableKvTiers(); return !empty($tiers) ? array_key_first($tiers) : null; } public function getComputeDefaultSizeKey(): ?string { $sizes = Arr::get($this->config, "compute.{$this->region}", []); return !empty($sizes) ? array_key_first($sizes) : null; } // ... }
-
app/Livewire/PricingCalculator.php
Open in GitHubuse App\Services\PricingService; use Livewire\Component; use Livewire\Attributes\Title; use Livewire\Attributes\Computed; use Illuminate\Validation\Rule; use Illuminate\Support\Facades\Validator; use Livewire\Attributes\On; class PricingCalculator extends Component { protected PricingService $pricingService; // ... public string $webComputeSize; public string $workerComputeSize; public ?string $mysqlDatabaseSize; public float $postgresComputeUnits; public string $kvTier; // ... public function boot(PricingService $pricingService) { $this->pricingService = $pricingService; } public function mount() { // Initialize properties using the service $this->webComputeSize = $this->pricingService->getComputeDefaultSizeKey(); $this->workerComputeSize = $this->pricingService->getComputeDefaultSizeKey(); $this->mysqlDatabaseSize = $this->pricingService->getMySqlDefaultSizeKey(); $this->postgresComputeUnits = $this->pricingService->getPostgresMinCpu(); $this->kvTier = $this->pricingService->getKvDefaultTierKey(); $this->resetUsageToPlanDefaults(); } // ... }