PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.1
1.6.5 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 All 48 releases
fluent-cart / app / Modules / PaymentMethods / PromoGateways / Pro / PromoGatewaySettings.php

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

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