gatewaySlug = $gatewaySlug; $this->methodHandler = $methodHandler; parent::__construct(); } public function setCustomStyles($styles) { $this->customStyles = $styles; } public static function getDefaults() { return [ 'is_active' => 'no' ]; } public function get($key = null) { if ($key === 'is_active') { return 'no'; } if ($key) { return isset($this->settings[$key]) ? $this->settings[$key] : null; } return $this->settings; } /** * Validate addon configuration * * @param array $config * @return array|\WP_Error */ public function validateAddonConfig($config) { $requiredKeys = ['title', 'description', 'addon_slug', 'addon_file', 'addon_source']; foreach ($requiredKeys as $key) { if (empty($config[$key])) { return new \WP_Error( 'missing_config', sprintf(__('Missing required configuration key: %s', 'fluent-cart'), $key) ); } } // Validate addon_source structure if (!is_array($config['addon_source']) || empty($config['addon_source']['type'])) { return new \WP_Error( 'invalid_source', __('Invalid addon_source configuration', 'fluent-cart') ); } return $config; } public function getMode() { return 'test'; } public function isActive(): bool { return false; } protected function getAddonNoticeStyles() { $defaults = [ 'light' => [ 'primary_gradient' => 'linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%)', 'text_primary' => '#1e293b', 'text_secondary' => '#475569', 'text_muted' => '#64748b', 'icon_bg' => '#dbeafe', 'icon_color' => '#3b82f6', 'feature_icon' => '#10b981', 'status_warning' => '#f59e0b', 'status_info' => '#3b82f6', 'status_success' => '#10b981', 'button_primary_bg' => '#3b82f6', 'button_primary_text' => '#ffffff', 'button_success_bg' => '#10b981', 'button_success_text' => '#ffffff', 'border_color' => '#e2e8f0', 'feature_bg' => '#ffffff', 'status_bg' => '#ffffff' ], 'dark' => [ 'primary_gradient' => 'linear-gradient(135deg, #1e293b 0%, #0f172a 100%)', 'text_primary' => '#f1f5f9', 'text_secondary' => '#cbd5e1', 'text_muted' => '#94a3b8', 'icon_bg' => 'rgba(59, 130, 246, 0.15)', 'icon_color' => '#60a5fa', 'feature_icon' => '#34d399', 'status_warning' => '#fbbf24', 'status_info' => '#60a5fa', 'status_success' => '#34d399', 'button_primary_bg' => '#3b82f6', 'button_primary_text' => '#ffffff', 'button_success_bg' => '#10b981', 'button_success_text' => '#ffffff', 'border_color' => '#334155', 'feature_bg' => 'rgba(15, 23, 42, 0.5)', 'status_bg' => 'rgba(15, 23, 42, 0.5)' ] ]; if (!empty($this->customStyles)) { $defaults['light'] = array_merge($defaults['light'], $this->customStyles['light'] ?? []); $defaults['dark'] = array_merge($defaults['dark'], $this->customStyles['dark'] ?? []); } return $defaults; } protected function renderIcon($svgPath, $styles = '') { return ''; } protected function renderFeatureItem($text, $mode = 'light') { $styles = $this->getAddonNoticeStyles()[$mode]; $checkIcon = $this->renderIcon( 'M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z', 'width: 18px; height: 18px; fill: ' . $styles['feature_icon'] . '; margin-right: 10px; flex-shrink: 0;' ); return '
' . $checkIcon . '' . esc_html($text) . '' . '
'; } protected function renderInstallButton($addonSlug, $addonFile, $addonSource, $repoLink, $mode = 'light') { $styles = $this->getAddonNoticeStyles()[$mode]; $downloadIcon = 'M13 10H18L12 16L6 10H11V3H13V10M4 19H20V12H22V20C22 20.5304 21.7893 21.0391 21.4142 21.4142C21.0391 21.7893 20.5304 22 20 22H4C3.46957 22 2.96086 21.7893 2.58579 21.4142C2.21071 21.0391 2 20.5304 2 20V12H4V19Z'; $buttonLabel = defined('FLUENTCART_PRO_PLUGIN_VERSION') ? __('Install & Activate', 'fluent-cart') : __('Download', 'fluent-cart'); return ''; } protected function renderActivateButton($addonFile, $mode = 'light') { $styles = $this->getAddonNoticeStyles()[$mode]; $checkIcon = 'M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z'; return ''; } protected function renderActiveBadge() { $styles = $this->getAddonNoticeStyles(); $checkIcon = 'M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z'; return '' . $this->renderIcon($checkIcon, 'width: 16px; height: 16px; margin-right: 6px; fill: #166534;') . __('Active', 'fluent-cart') . ''; } /** * Generate addon notice HTML * * @param array $config Configuration array with: * - title: Gateway title * - description: Gateway description * - features: Array of feature strings * - icon_path: SVG path for the gateway icon * - addon_slug: Plugin slug * - addon_file: Plugin file path * - addon_source: Array with 'type' and 'link' * * @return string HTML for the addon notice */ public function generateAddonNotice($config) { // Validate configuration before proceeding $validation = $this->validateAddonConfig($config); if (is_wp_error($validation)) { return '
' . '

' . esc_html($validation->get_error_message()) . '

' . '
'; } $allStyles = $this->getAddonNoticeStyles(); // Get addon status $addonStatus = PaymentAddonManager::getAddonStatus( $config['addon_slug'], $config['addon_file'] ); $isInstalled = $addonStatus['is_installed'] ?? false; $isActive = $addonStatus['is_active'] ?? false; $footerText = $config['footer_text'] ?? __('Free addon - Click the button above to get started', 'fluent-cart'); $html = ''; // Render both light and dark mode versions foreach (['light', 'dark'] as $mode) { $styles = $allStyles[$mode]; // Determine status and action button for this mode $proRequired = !empty($config['pro_required']) && !defined('FLUENTCART_PRO_PLUGIN_VERSION'); if ($proRequired) { $statusMessage = __('Requires Pro', 'fluent-cart'); $statusColor = $styles['status_warning']; $upgradeUrl = esc_url($config['repo_link'] ?? Helper::getUpgradeUrl('feature_lock_gateway_' . $this->gatewaySlug)); $actionButton = '' . $this->renderIcon('M12 1L3 5v6c0 5.55 3.84 10.74 9 12 5.16-1.26 9-6.45 9-12V5l-9-4zm0 4l5 2.18V11c0 3.5-2.33 6.79-5 7.93-2.67-1.14-5-4.43-5-7.93V7.18L12 5z', 'width: 16px; height: 16px; margin-right: 6px; fill: ' . $styles['button_primary_text'] . ';') . __('Upgrade to Pro', 'fluent-cart') . ''; } elseif (!$isInstalled) { $statusMessage = __('Not Installed', 'fluent-cart'); $statusColor = $styles['status_warning']; $actionButton = $this->renderInstallButton( $config['addon_slug'], $config['addon_file'], $config['addon_source'], $config['repo_link'] ?? '', $mode ); } elseif ($isInstalled && !$isActive) { $statusMessage = __('Installed - Not Active', 'fluent-cart'); $statusColor = $styles['status_info']; $actionButton = $this->renderActivateButton($config['addon_file'], $mode); } else { $statusMessage = __('Active', 'fluent-cart'); $statusColor = $styles['status_success']; $actionButton = $this->renderActiveBadge(); } $modeClass = $mode === 'dark' ? 'fct-addon-notice-dark' : 'fct-addon-notice-light'; $displayStyle = $mode === 'dark' ? 'display: none;' : ''; // Build notice HTML $html .= '
'; // Icon $html .= '
'; $html .= $this->renderIcon($config['icon_path'], 'width: 32px; height: 32px; fill: ' . $styles['icon_color'] . ';'); $html .= '
'; // Title $html .= '

' . esc_html($config['title']) . '

'; // Description $html .= '

' . esc_html($config['description']) . '

'; // Features if (!empty($config['features'])) { $html .= '
'; foreach ($config['features'] as $feature) { $html .= $this->renderFeatureItem($feature, $mode); } $html .= '
'; } // Status & Action $html .= '
'; $html .= '
'; $html .= '
'; $html .= '' . esc_html($statusMessage) . ''; $html .= '
'; $html .= '
' . $actionButton . '
'; $html .= '
'; // Footer $html .= '

' . esc_html($footerText) . '

'; $html .= '
'; } // Add CSS to toggle between light/dark modes $html .= ''; return $html; } }