*/ private array $requiredScopes; /** @param list $requiredScopes */ public function __construct(array $requiredScopes) { $this->requiredScopes = $requiredScopes; } public function isAvailable(): bool { return class_exists(\Aivie\MarketingAutomation\Aivie\ConnectionFacade::class); } public function isConnected(): bool { return $this->isAvailable() && $this->facade()->is_connected(); } public function isReady(): bool { return $this->isConnected() && $this->facade()->has_scopes($this->requiredScopes); } public function baseUrl(): string { if (! $this->isReady()) { return ''; } return (string) $this->facade()->issuer(); } public function settingsUrl(): string { if ($this->isAvailable()) { return $this->facade()::settings_url(); } return admin_url('options-general.php?page=aivie-marketing-automation'); } /** * @return array{base_url: string, access_token: string, source: string}|\WP_Error */ public function credentials(): array|\WP_Error { if (! $this->isAvailable()) { return new \WP_Error( 'aivie_wc_shared_plugin_unavailable', __('Aivie Marketing Automation is not available.', 'aivie-for-woocommerce') ); } $snapshot = $this->facade()->snapshot($this->requiredScopes); if (is_wp_error($snapshot)) { return $snapshot; } return [ 'base_url' => $snapshot['issuer'], 'access_token' => $snapshot['access_token'], 'source' => 'shared', ]; } private function facade(): \Aivie\MarketingAutomation\Aivie\ConnectionFacade { return new \Aivie\MarketingAutomation\Aivie\ConnectionFacade(); } }