PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Modules / PaymentMethods / PromoGateways / Pro / PromoGatewaySettings.php

PromoGatewaySettings.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Modules/PaymentMethods/PromoGateways/Pro/PromoGatewaySettings.php

255 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Modules\PaymentMethods\PromoGateways\Pro;
4
5 use FluentCart\App\Helpers\Helper;
6 use FluentCart\App\Modules\PaymentMethods\Core\BaseGatewaySettings;
7 use FluentCart\Framework\Support\Arr;
8
9 class PromoGatewaySettings extends BaseGatewaySettings
10 {
11 protected $gatewaySlug;
12 protected $customStyles = [];
13
14 public function __construct($gatewaySlug)
15 {
16 $this->gatewaySlug = $gatewaySlug;
17 $this->methodHandler = 'fluent_cart_payment_settings_promo_gateway';
18 parent::__construct();
19 }
20
21 public static function getDefaults()
22 {
23 return [
24 'is_active' => 'no'
25 ];
26 }
27
28 public function get($key = null)
29 {
30 if ($key === 'is_active') {
31 return 'no';
32 }
33
34 if ($key) {
35 return isset($this->settings[$key]) ? $this->settings[$key] : null;
36 }
37
38 return $this->settings;
39 }
40
41 public function getMode()
42 {
43 return 'test';
44 }
45
46 public function isActive(): bool
47 {
48 return false;
49 }
50
51 public function setCustomStyles($styles)
52 {
53 $this->customStyles = $styles;
54 }
55
56 protected function getPromoNoticeStyles()
57 {
58 $defaults = [
59 'light' => [
60 'primary_gradient' => 'linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%)',
61 'text_primary' => '#1e293b',
62 'text_secondary' => '#475569',
63 'text_muted' => '#64748b',
64 'icon_bg' => '#e0e7ff',
65 'icon_color' => '#6366f1',
66 'feature_icon' => '#10b981',
67 'button_bg' => '#6366f1',
68 'button_text' => '#ffffff',
69 'border_color' => '#e2e8f0',
70 'feature_bg' => '#ffffff'
71 ],
72 'dark' => [
73 'primary_gradient' => 'linear-gradient(135deg, #1e293b 0%, #0f172a 100%)',
74 'text_primary' => '#f1f5f9',
75 'text_secondary' => '#cbd5e1',
76 'text_muted' => '#94a3b8',
77 'icon_bg' => 'rgba(99, 102, 241, 0.15)',
78 'icon_color' => '#818cf8',
79 'feature_icon' => '#34d399',
80 'button_bg' => '#6366f1',
81 'button_text' => '#ffffff',
82 'border_color' => '#334155',
83 'feature_bg' => 'rgba(15, 23, 42, 0.5)'
84 ]
85 ];
86
87 if (!empty($this->customStyles)) {
88 $defaults['light'] = array_merge($defaults['light'], $this->customStyles['light'] ?? []);
89 $defaults['dark'] = array_merge($defaults['dark'], $this->customStyles['dark'] ?? []);
90 }
91
92 return $defaults;
93 }
94
95 /**
96 * Render SVG icon
97 */
98 protected function renderIcon($svgPath, $styles = '')
99 {
100 return '<svg style="' . $styles . '" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="' . $svgPath . '"/></svg>';
101 }
102
103 /**
104 * Render a feature list item with checkmark
105 */
106 protected function renderFeatureItem($text, $mode = 'light')
107 {
108 $styles = $this->getPromoNoticeStyles()[$mode];
109 $checkIcon = $this->renderIcon(
110 'M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z',
111 'width: 18px; height: 18px; fill: ' . $styles['feature_icon'] . '; margin-right: 10px; flex-shrink: 0;'
112 );
113
114 return '<div style="display: flex; align-items: center; margin-bottom: 10px;">'
115 . $checkIcon
116 . '<span style="font-size: 14px; color: ' . $styles['text_secondary'] . ';">' . esc_html($text) . '</span>'
117 . '</div>';
118 }
119
120 /**
121 * Check if FluentCart Pro is installed
122 */
123 protected function isProInstalled()
124 {
125 if (!function_exists('get_plugins')) {
126 require_once ABSPATH . 'wp-admin/includes/plugin.php';
127 }
128
129 $all_plugins = get_plugins();
130 return isset($all_plugins['fluent-cart-pro/fluent-cart-pro.php']);
131 }
132
133 /**
134 * Check if FluentCart Pro is active
135 */
136 protected function isProActive()
137 {
138 if (!function_exists('is_plugin_active')) {
139 require_once ABSPATH . 'wp-admin/includes/plugin.php';
140 }
141
142 return is_plugin_active('fluent-cart-pro/fluent-cart-pro.php');
143 }
144
145 /**
146 * Render upgrade or activate button
147 */
148 protected function renderActionButton($mode = 'light')
149 {
150 $styles = $this->getPromoNoticeStyles()[$mode];
151
152 // If Pro is installed but not active, show activate button
153 if ($this->isProInstalled() && !$this->isProActive()) {
154 return '<button class="fct-activate-addon-btn" data-addon-file="fluent-cart-pro/fluent-cart-pro.php" style="display: inline-block; background: ' . $styles['button_bg'] . '; color: ' . $styles['button_text'] . '; padding: 12px 28px; border-radius: 6px; text-decoration: none; font-weight: 500; font-size: 15px; transition: all 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); border: none; cursor: pointer;">'
155 . __('Activate FluentCart Pro', 'fluent-cart')
156 . '</button>';
157 }
158
159 // Otherwise show upgrade button
160 $upgradeUrl = Helper::getUpgradeUrl('feature_lock_gateway_' . $this->gatewaySlug);
161
162 return '<a href="' . esc_url($upgradeUrl) . '" target="_blank" style="display: inline-block; background: ' . $styles['button_bg'] . '; color: ' . $styles['button_text'] . '; padding: 12px 28px; border-radius: 6px; text-decoration: none; font-weight: 500; font-size: 15px; transition: all 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);">'
163 . __('Upgrade to FluentCart Pro', 'fluent-cart') . ''
164 . '</a>';
165 }
166
167 /**
168 * Generate upgrade to pro notice HTML
169 *
170 * @param array $config Configuration array with:
171 * - title: Gateway title
172 * - description: Gateway description
173 * - features: Array of feature strings
174 * - icon_path: SVG path for the gateway icon
175 * - footer_text: Optional footer text
176 * @return string HTML for the upgrade notice
177 */
178 public function generateUpgradeNotice($config)
179 {
180 $allStyles = $this->getPromoNoticeStyles();
181
182 // Determine footer text based on Pro status
183 $defaultFooterText = __('Unlock all premium payment gateways and features', 'fluent-cart');
184 if ($this->isProInstalled() && !$this->isProActive()) {
185 $defaultFooterText = __('FluentCart Pro is installed - Activate to unlock all premium features', 'fluent-cart');
186 }
187
188 $footerText = Arr::get($config, 'footer_text') ? Arr::get($config, 'footer_text') : $defaultFooterText;
189
190 $html = '';
191
192 foreach (['light', 'dark'] as $mode) {
193 $styles = $allStyles[$mode];
194 $modeClass = $mode === 'dark' ? 'fct-promo-notice-dark' : 'fct-promo-notice-light';
195 $displayStyle = $mode === 'dark' ? 'display: none;' : '';
196
197 $html .= '<div class="fct-promo-notice ' . $modeClass . '" style="' . $displayStyle . ' background: ' . $styles['primary_gradient'] . '; border: 1px solid ' . $styles['border_color'] . '; border-radius: 8px; padding: 28px; color: ' . $styles['text_primary'] . '; text-align: center; margin: 20px 0;">';
198
199 // Icon
200 $html .= '<div style="background: ' . $styles['icon_bg'] . '; width: 64px; height: 64px; border-radius: 12px; margin: 0 auto 20px; display: flex; align-items: center; justify-content: center;">';
201 $html .= $this->renderIcon($config['icon_path'], 'width: 32px; height: 32px; fill: ' . $styles['icon_color'] . ';');
202 $html .= '</div>';
203
204 // Title
205 $html .= '<h3 style="margin: 0 0 8px 0; font-size: 20px; font-weight: 600; color: ' . $styles['text_primary'] . ';">'
206 . esc_html($config['title'])
207 . '</h3>';
208
209 // Description
210 $html .= '<p style="margin: 0 0 20px 0; font-size: 14px; color: ' . $styles['text_secondary'] . '; line-height: 1.6;">'
211 . esc_html($config['description'])
212 . '</p>';
213
214 // Features
215 if (!empty($config['features'])) {
216 $html .= '<div style="background: ' . $styles['feature_bg'] . '; border: 1px solid ' . $styles['border_color'] . '; border-radius: 6px; padding: 18px; margin: 20px 0; text-align: left;">';
217 foreach ($config['features'] as $feature) {
218 $html .= $this->renderFeatureItem($feature, $mode);
219 }
220 $html .= '</div>';
221 }
222
223 // Action Button (Upgrade or Activate)
224 $html .= '<div style="margin: 24px 0 16px 0;">' . $this->renderActionButton($mode) . '</div>';
225
226 // Footer
227 $html .= '<p style="margin: 0; font-size: 12px; color: ' . $styles['text_muted'] . ';">'
228 . esc_html($footerText)
229 . '</p>';
230
231 $html .= '</div>';
232 }
233
234 // Add CSS to toggle between light/dark modes
235 $html .= '<style>
236 @media (prefers-color-scheme: dark) {
237 .fct-promo-notice-light { display: none !important; }
238 .fct-promo-notice-dark { display: block !important; }
239 }
240 html.dark .fct-promo-notice-light,
241 body.dark .fct-promo-notice-light,
242 [data-theme="dark"] .fct-promo-notice-light {
243 display: none !important;
244 }
245 html.dark .fct-promo-notice-dark,
246 body.dark .fct-promo-notice-dark,
247 [data-theme="dark"] .fct-promo-notice-dark {
248 display: block !important;
249 }
250 </style>';
251
252 return $html;
253 }
254 }
255