PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / trunk
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 All 66 releases
better-payment / includes / Admin / Setup_Wizard.php

Setup_Wizard.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More trunk, at includes/Admin/Setup_Wizard.php

546 lines 31.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Better_Payment\Lite\Admin;
4
5 use Better_Payment\Lite\Classes\Plugin_Usage_Tracker;
6 use Better_Payment\Lite\Traits\Helper as TraitsHelper;
7
8 if (!defined('ABSPATH')) {
9 exit;
10 } // Exit if accessed directly.
11
12 /**
13 * Setup Wizard
14 *
15 * @since 0.0.2
16 */
17 class Setup_Wizard
18 {
19 use TraitsHelper;
20
21 protected $file_version;
22
23 /**
24 * Setup Wizard constructor.
25 *
26 * @since 0.0.2
27 */
28 public function __construct()
29 {
30 $this->file_version = defined('WP_DEBUG') && WP_DEBUG ? time() : BETTER_PAYMENT_VERSION;
31 add_action('admin_enqueue_scripts', array($this, 'setup_wizard_scripts'));
32 add_action('admin_menu', array($this, 'admin_menu'));
33 add_action('wp_ajax_save_setup_wizard_data', [$this, 'save_setup_wizard_data']);
34 add_action( 'wp_ajax_bp_quick_setup_save_tracking', [ $this, 'bp_quick_setup_save_tracking' ] );
35 add_action('in_admin_header', [$this, 'remove_notice'], 1000);
36 }
37
38 /**
39 * Remove all notice in setup wizard page
40 *
41 * @since 0.0.2
42 */
43 public function remove_notice()
44 {
45 if (isset($_GET['page']) && $_GET['page'] == 'better-payment-setup-wizard') {
46 remove_all_actions('admin_notices');
47 remove_all_actions('all_admin_notices');
48 }
49 }
50
51 /**
52 * setup_wizard_scripts
53 * @param $hook
54 * @return array
55 *
56 * @since 0.0.2
57 */
58 public function setup_wizard_scripts($hook)
59 {
60 if (isset($hook) && $hook == 'admin_page_better-payment-setup-wizard') {
61 // Determine the correct file extension based on debug mode
62 $js_ext = file_exists(BETTER_PAYMENT_PATH . '/assets/admin/quick-setup/quick-setup.min.js') ? '.min.js' : '.js';
63 $css_ext = file_exists(BETTER_PAYMENT_PATH . '/assets/admin/quick-setup/quick-setup.min.css') ? '.min.css' : '.css';
64
65 // Enqueue React Quick Setup CSS
66 wp_enqueue_style(
67 'bp-quick-setup-css',
68 BETTER_PAYMENT_ASSETS . '/admin/quick-setup/quick-setup' . $css_ext,
69 array(),
70 $this->file_version
71 );
72
73 // Enqueue React Quick Setup JS with WordPress dependencies
74 wp_enqueue_script(
75 'bp-quick-setup-js',
76 BETTER_PAYMENT_ASSETS . '/admin/quick-setup/quick-setup' . $js_ext,
77 array('wp-element', 'wp-i18n'),
78 $this->file_version,
79 true
80 );
81
82 // Localize script with necessary data
83 wp_localize_script('bp-quick-setup-js', 'betterPaymentObjWizard', array(
84 'admin_nonce' => wp_create_nonce('better_payment_admin_nonce'),
85 'ajaxUrl' => admin_url('admin-ajax.php'),
86 'assetsUrl' => BETTER_PAYMENT_ASSETS . '/admin/quick-setup',
87 'success_image' => BETTER_PAYMENT_ASSETS . '/img/success.gif',
88 'settings' => DB::get_settings(),
89 'is_tracking' => get_option('better_payment_settings_opt_in') === 'yes' ? 1 : 0,
90 'currencies' => $this->get_currency_list(),
91 'is_pro' => defined('BETTER_PAYMENT_PRO_VERSION') && BETTER_PAYMENT_PRO_VERSION ? true : false,
92 'alerts' => [
93 'confirm' => esc_html__('Are you sure?', 'better-payment'),
94 'confirm_description' => esc_html__("You won't be able to revert this!", 'better-payment'),
95 'yes' => esc_html__('Yes, delete it!', 'better-payment'),
96 'no' => esc_html__('No, cancel!', 'better-payment'),
97 ],
98 'messages' => [
99 'success' => esc_html__('Changes saved successfully!', 'better-payment'),
100 'error' => esc_html__('Opps! something went wrong!', 'better-payment'),
101 'no_action_taken' => esc_html__('No action taken!', 'better-payment'),
102 ]
103 ));
104 }
105 return [];
106 }
107
108 /**
109 * Create admin menu for setup wizard
110 *
111 * @since 0.0.2
112 */
113 public function admin_menu()
114 {
115
116 add_submenu_page(
117 "admin.php?page=better-payment-setup-wizard",
118 esc_html__('Better Payment ', 'better-payment'),
119 esc_html__('Better Payment ', 'better-payment'),
120 'manage_options',
121 'better-payment-setup-wizard',
122 [$this, 'render_wizard']
123 );
124 }
125
126 /**
127 * Render tab step
128 *
129 * @since 0.0.2
130 */
131 public function tab_step()
132 {
133 $wizard_column = 'four';
134 ?>
135 <ul class="better-payment-setup-wizard <?php echo esc_attr( $wizard_column ); ?>" data-step="0">
136 <li class="step">
137 <div class="icon">
138 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve">
139 <g>
140 <path class="st0" d="M50,25c0-1.9-1.3-3.8-3-4.4c-1.6-0.6-3.2-2-3.7-3.1c-0.5-1.1-0.3-3.3,0.4-4.9c0.8-1.6,0.3-3.9-1-5.2
141 c-1.3-1.3-3.7-1.8-5.2-1c-1.6,0.8-3.7,0.9-4.9,0.4C31.5,6.2,30,4.6,29.4,3c-0.6-1.7-2.6-3-4.4-3c-1.9,0-3.8,1.3-4.4,3
142 c-0.6,1.7-2,3.3-3.1,3.7c-1.1,0.5-3.3,0.3-4.9-0.4C11,5.5,8.6,6,7.3,7.3C6,8.6,5.5,11,6.3,12.6c0.8,1.6,0.9,3.7,0.4,4.9
143 C6.2,18.6,4.6,20,3,20.6c-1.7,0.6-3,2.6-3,4.4c0,1.9,1.3,3.8,3,4.4c1.7,0.6,3.2,2,3.7,3.1c0.5,1.1,0.3,3.3-0.4,4.9
144 c-0.8,1.6-0.3,3.9,1,5.2c1.3,1.3,3.7,1.8,5.2,1c1.6-0.8,3.7-0.9,4.9-0.4c1.1,0.5,2.6,2.1,3.1,3.7c0.6,1.7,2.6,3,4.4,3
145 c1.9,0,3.8-1.3,4.4-3c0.6-1.6,2-3.3,3.1-3.7c1.1-0.5,3.3-0.3,4.9,0.4c1.6,0.8,3.9,0.3,5.2-1c1.3-1.3,1.8-3.7,1-5.2
146 c-0.8-1.6-0.9-3.7-0.4-4.9c0.5-1.1,2.1-2.6,3.7-3.1C48.7,28.8,50,26.9,50,25L50,25z M25,34.2c-5.1,0-9.2-4.1-9.2-9.2
147 c0-5.1,4.1-9.2,9.2-9.2c5.1,0,9.2,4.1,9.2,9.2C34.2,30.1,30.1,34.2,25,34.2L25,34.2z M25,34.2" />
148 </g>
149 </svg>
150 </div>
151 <div class="name"><?php esc_html_e('Getting Started', 'better-payment'); ?></div>
152 </li>
153 <li class="step">
154 <div class="icon">
155 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve">
156 <path class="st0" d="M48.9,16.6c-0.7-0.7-1.6-1.1-2.6-1.1c-1,0-1.9,0.4-2.6,1.1l-8.8,8.8L24.7,15.1l8.8-8.8c0.7-0.7,1.1-1.6,1.1-2.6
157 c0-1-0.4-1.9-1.1-2.6C32.7,0.4,31.8,0,30.8,0c-1,0-1.9,0.4-2.6,1.1l-8.8,8.8l-5.6-5.6c-0.3-0.3-0.6-0.4-1-0.4c-0.4,0-0.7,0.2-1,0.4
158 c-8,8.8-3.7,28-3.2,29.9l-8.1,8.1c-0.3,0.2-0.4,0.6-0.4,0.9c0,0.4,0.1,0.7,0.4,0.9L5.5,49c0.3,0.3,0.6,0.4,0.9,0.4
159 c0.3,0,0.7-0.1,0.9-0.4l8.1-8.1c3.9,1,8.8,1.6,13.2,1.6c5.2,0,12.3-0.8,16.7-4.8c0.3-0.2,0.4-0.6,0.4-1c0-0.4-0.1-0.7-0.4-1
160 l-5.2-5.2l8.8-8.8C50.4,20.4,50.4,18,48.9,16.6z" />
161 </svg>
162 </div>
163 <div class="name"><?php esc_html_e('PayPal Configuration', 'better-payment'); ?></div>
164 </li>
165 <li class="step">
166 <div class="icon">
167 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve">
168 <path class="st0" d="M48.9,16.6c-0.7-0.7-1.6-1.1-2.6-1.1c-1,0-1.9,0.4-2.6,1.1l-8.8,8.8L24.7,15.1l8.8-8.8c0.7-0.7,1.1-1.6,1.1-2.6
169 c0-1-0.4-1.9-1.1-2.6C32.7,0.4,31.8,0,30.8,0c-1,0-1.9,0.4-2.6,1.1l-8.8,8.8l-5.6-5.6c-0.3-0.3-0.6-0.4-1-0.4c-0.4,0-0.7,0.2-1,0.4
170 c-8,8.8-3.7,28-3.2,29.9l-8.1,8.1c-0.3,0.2-0.4,0.6-0.4,0.9c0,0.4,0.1,0.7,0.4,0.9L5.5,49c0.3,0.3,0.6,0.4,0.9,0.4
171 c0.3,0,0.7-0.1,0.9-0.4l8.1-8.1c3.9,1,8.8,1.6,13.2,1.6c5.2,0,12.3-0.8,16.7-4.8c0.3-0.2,0.4-0.6,0.4-1c0-0.4-0.1-0.7-0.4-1
172 l-5.2-5.2l8.8-8.8C50.4,20.4,50.4,18,48.9,16.6z" />
173 </svg>
174 </div>
175 <div class="name"><?php esc_html_e('Stripe Configuration', 'better-payment'); ?></div>
176 </li>
177 <li class="step">
178 <div class="icon">
179 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50;" xml:space="preserve">
180 <path class="st0" d="M48.5,3.1l-0.3-0.3c-0.9-0.9-2.1-1.4-3.3-1.3c-1.2,0-2.4,0.6-3.3,1.5L16.1,30.9l-0.5,0.2l-0.5-0.2l-6.3-7.4
181 c-0.9-1.1-2.2-1.7-3.6-1.8c-1.4-0.1-2.8,0.5-3.8,1.5c-1.6,1.6-1.8,4.1-0.5,5.9l13.1,18.3c0.7,1,1.9,1.7,3.2,1.7h1.1
182 c2.2,0,4.2-1.1,5.4-2.8L49.1,9.5C50.5,7.5,50.2,4.8,48.5,3.1z" />
183 </svg>
184 </div>
185 <div class="name"><?php esc_html_e('Finalize', 'better-payment'); ?></div>
186 </li>
187 </ul>
188 <?php
189 }
190
191 /**
192 * Tav view content
193 *
194 * @since 0.0.2
195 */
196 public function tab_content($bp_admin_saved_settings)
197 {
198 $bp_admin_saved_settings = DB::get_settings();
199 $currency_list = $this->get_currency_list();
200 ?>
201 <div class="better-payment-setup-body better-payment">
202 <form method="post" id="better-payment-admin-settings-form" class="better-payment-setup-wizard-form" action="#">
203
204 <div id="configuration" class="setup-content active">
205 <div id="general" class="sidebar__tab__content show payment__options better-payment-box">
206 <div class="payment__option">
207 <div class="payment__option__content">
208 <h4><?php esc_html_e('PayPal', 'better-payment'); ?></h4>
209 <p><?php esc_html_e('Enable PayPal if you want to make transaction using PayPal.', 'better-payment'); ?></p>
210 </div>
211 <div class="active__status">
212 <label class="bp-switch">
213 <input type="hidden" name="better_payment_settings_general_general_paypal" value="no">
214 <input type="checkbox" name="better_payment_settings_general_general_paypal" value="yes" <?php echo isset($bp_admin_saved_settings['better_payment_settings_general_general_paypal']) && $bp_admin_saved_settings['better_payment_settings_general_general_paypal'] == 'yes' ? ' checked' : '' ?>>
215 <span class="switch__btn"></span>
216 </label>
217 </div>
218 </div>
219 <div class="payment__option">
220 <div class="payment__option__content">
221 <h4><?php esc_html_e('Stripe', 'better-payment'); ?></h4>
222 <p><?php esc_html_e('Enable Stripe if you want to accept payment via Stripe.', 'better-payment'); ?></p>
223 </div>
224 <div class="active__status">
225 <label class="bp-switch">
226 <input type="hidden" name="better_payment_settings_general_general_stripe" value="no">
227 <input type="checkbox" name="better_payment_settings_general_general_stripe" value="yes" <?php echo isset($bp_admin_saved_settings['better_payment_settings_general_general_stripe']) && $bp_admin_saved_settings['better_payment_settings_general_general_stripe'] == 'yes' ? ' checked' : '' ?>>
228 <span class="switch__btn"></span>
229 </label>
230 </div>
231 </div>
232 <div class="payment__option">
233 <div class="payment__option__content">
234 <h4><?php esc_html_e('Email Notification', 'better-payment'); ?></h4>
235 <p><?php esc_html_e('Enable email notification for each transaction. It sends notification to the website admin and customer (who makes the payment). You can modify email settings as per your need.', 'better-payment'); ?></p>
236 </div>
237 <div class="active__status">
238 <label class="bp-switch">
239 <input type="hidden" name="better_payment_settings_general_general_email" value="no">
240 <input type="checkbox" name="better_payment_settings_general_general_email" value="yes" <?php echo isset($bp_admin_saved_settings['better_payment_settings_general_general_email']) && $bp_admin_saved_settings['better_payment_settings_general_general_email'] == 'yes' ? ' checked' : '' ?>>
241 <span class="switch__btn"></span>
242 </label>
243 </div>
244 </div>
245 <div class="payment__option">
246 <div class="payment__option__content">
247 <h4><?php esc_html_e('Currency', 'better-payment'); ?></h4>
248 <p><?php esc_html_e('Select default currency for each transaction. You can also overwrite this setting from each widget control on elementor page builder.', 'better-payment'); ?></p>
249 </div>
250 <div class="active__status">
251 <div class="bp-select">
252 <select name="better_payment_settings_general_general_currency">
253 <option value="" disabled> <?php esc_html_e('Select Currency', 'better-payment'); ?> </option>
254 <?php foreach ($currency_list as $key => $value){
255 $selected = isset($bp_admin_saved_settings['better_payment_settings_general_general_currency']) && $bp_admin_saved_settings['better_payment_settings_general_general_currency'] == $key?'selected':'';
256 printf( '<option value="%s" %s >%s</option>', esc_attr( $key ), esc_attr( $selected ), esc_html__( $key, 'better-payment' ) );
257 } ?>
258 </select>
259 </div>
260 </div>
261 </div>
262 </div>
263 </div>
264
265 <div id="quick-setup-paypal" class="setup-content quick-setup-paypal better-payment-box">
266 <div class="payment__options ">
267 <div class="payment__option">
268 <div class="payment__option__content">
269 <h4><?php esc_html_e('Live Mode', 'better-payment'); ?></h4>
270 <p><?php esc_html_e('Live mode allows you to process real transactions. It just requires PayPal business email to accept real payments.', 'better-payment'); ?></p>
271 </div>
272 <div class="active__status">
273 <label class="bp-switch">
274 <input type="hidden" name="better_payment_settings_payment_paypal_live_mode" value="no">
275 <input type="checkbox" name="better_payment_settings_payment_paypal_live_mode" value="yes" data-target="better-payment-settings-payment-paypal-live" <?php echo isset($bp_admin_saved_settings['better_payment_settings_payment_paypal_live_mode']) && $bp_admin_saved_settings['better_payment_settings_payment_paypal_live_mode'] == 'yes' ? ' checked' : '' ?>>
276 <span class="switch__btn"></span>
277 </label>
278 </div>
279 </div>
280 <div class="payment__option">
281 <div class="payment__option__content">
282 <h4><?php esc_html_e('Business Email', 'better-payment'); ?></h4>
283 <p><?php esc_html_e('Your PayPal account email address to accept payment via PayPal.', 'better-payment'); ?></p>
284 </div>
285 <div class="active__status input__wrap">
286 <input type="email" class="form__control" name="better_payment_settings_payment_paypal_email" value="<?php echo isset($bp_admin_saved_settings['better_payment_settings_payment_paypal_email']) ? esc_html( $bp_admin_saved_settings['better_payment_settings_payment_paypal_email'] ) : '' ?>">
287 </div>
288 </div>
289 </div>
290 </div>
291
292 <div id="quick-setup-stripe" class="setup-content quick-setup-stripe">
293 <div class="payment__options">
294 <div class="payment__option">
295 <div class="payment__option__content">
296 <h4><?php esc_html_e('Live Mode', 'better-payment'); ?></h4>
297 <p><?php esc_html_e('Live mode allows you to process real transactions. It just requires live Stripe keys (public and secret keys) to accept real payments.', 'better-payment'); ?></p>
298 </div>
299 <div class="active__status">
300 <label class="bp-switch">
301 <input type="hidden" name="better_payment_settings_payment_stripe_live_mode" value="no">
302 <input type="checkbox" name="better_payment_settings_payment_stripe_live_mode" value="yes" data-targettest="bp-stripe-test-key" data-targetlive="bp-stripe-live-key" <?php echo isset($bp_admin_saved_settings['better_payment_settings_payment_stripe_live_mode']) && $bp_admin_saved_settings['better_payment_settings_payment_stripe_live_mode'] == 'yes' ? ' checked' : '' ?>>
303 <span class="switch__btn"></span>
304 </label>
305 </div>
306 </div>
307
308 <?php $better_payment_settings_payment_stripe_live = isset($bp_admin_saved_settings['better_payment_settings_payment_stripe_live_mode']) && $bp_admin_saved_settings['better_payment_settings_payment_stripe_live_mode'] == 'yes'; ?>
309
310 <div class="payment__option bp-stripe-key bp-stripe-live-key <?php echo $better_payment_settings_payment_stripe_live ? 'bp-d-block' : 'bp-d-none' ?>">
311 <div class="payment__option__content">
312 <h4><?php esc_html_e('Live Public Key', 'better-payment'); ?></h4>
313 <p><?php esc_html_e('Stripe live public key is required to make payments via Stripe. For more help visit', 'better-payment'); ?> <a class="color__themeColor" target="_blank" rel="nofollow" href="https://stripe.com/docs/keys">https://stripe.com/docs/keys</a>.</p>
314 </div>
315 <div class="active__status input__wrap">
316 <input type="text" class="form__control mt15" name="better_payment_settings_payment_stripe_live_public" value="<?php echo isset($bp_admin_saved_settings['better_payment_settings_payment_stripe_live_public']) ? esc_attr( $bp_admin_saved_settings['better_payment_settings_payment_stripe_live_public'] ) : '' ?>" type="text" placeholder="<?php //esc_html_e('Live public key', 'better-payment'); ?>">
317 </div>
318 </div>
319 <div class="payment__option bp-stripe-key bp-stripe-live-key <?php echo $better_payment_settings_payment_stripe_live ? 'bp-d-block' : 'bp-d-none' ?>">
320 <div class="payment__option__content">
321 <h4><?php esc_html_e('Live Secret Key', 'better-payment'); ?></h4>
322 <p><?php esc_html_e('Stripe live secret key is required to make payments via Stripe. For more help visit', 'better-payment'); ?> <a class="color__themeColor" target="_blank" rel="nofollow" href="https://stripe.com/docs/keys">https://stripe.com/docs/keys</a>.</p>
323 </div>
324 <div class="active__status input__wrap">
325 <input type="password" class="form__control mt15" name="better_payment_settings_payment_stripe_live_secret" value="<?php echo isset($bp_admin_saved_settings['better_payment_settings_payment_stripe_live_secret']) ? esc_attr( $bp_admin_saved_settings['better_payment_settings_payment_stripe_live_secret'] ) : '' ?>">
326 </div>
327 </div>
328 <div class="payment__option bp-stripe-key bp-stripe-test-key <?php echo $better_payment_settings_payment_stripe_live ? 'bp-d-none' : 'bp-d-block' ?> ">
329 <div class="payment__option__content">
330 <h4><?php esc_html_e('Test Public Key', 'better-payment'); ?></h4>
331 <p><?php esc_html_e('Stripe test public key is required to make payments via Stripe. For more help visit', 'better-payment'); ?> <a class="color__themeColor" target="_blank" rel="nofollow" href="https://stripe.com/docs/keys">https://stripe.com/docs/keys</a>.</p>
332 </div>
333 <div class="active__status input__wrap">
334 <input type="text" class="form__control mt15" name="better_payment_settings_payment_stripe_test_public" value="<?php echo isset($bp_admin_saved_settings['better_payment_settings_payment_stripe_test_public']) ? esc_attr( $bp_admin_saved_settings['better_payment_settings_payment_stripe_test_public'] ) : '' ?>">
335 </div>
336 </div>
337 <div class="payment__option bp-stripe-key bp-stripe-test-key <?php echo $better_payment_settings_payment_stripe_live ? 'bp-d-none' : 'bp-d-block' ?> ">
338 <div class="payment__option__content">
339 <h4><?php esc_html_e('Test Secret Key', 'better-payment'); ?></h4>
340 <p><?php esc_html_e('Stripe test secret key is required to make payments via Stripe. For more help visit', 'better-payment'); ?> <a class="color__themeColor" target="_blank" rel="nofollow" href="https://stripe.com/docs/keys">https://stripe.com/docs/keys</a>.</p>
341 </div>
342 <div class="active__status input__wrap">
343 <input type="password" class="form__control mt15" name="better_payment_settings_payment_stripe_test_secret" value="<?php echo isset($bp_admin_saved_settings['better_payment_settings_payment_stripe_test_secret']) ? esc_attr( $bp_admin_saved_settings['better_payment_settings_payment_stripe_test_secret'] ) : '' ?>">
344 </div>
345 </div>
346 </div>
347 </div>
348
349 <div id="finalize" class="setup-content better-payment-box">
350 <header class="pb31 text-center">
351 <div class="bp-container">
352 <div class="bp-row">
353 <div class="bp-col">
354 <div class="logo">
355 <a href="javascript:void(0)"><img src="<?php echo esc_url( BETTER_PAYMENT_ASSETS . '/img/logo.svg' ); ?>" alt="Better Payment logo"></a>
356 </div>
357 </div>
358 </div>
359 </div>
360 </header>
361 <h2 class="text-center"><?php esc_html_e('Great Job! Your Configuration is Complete ', 'better-payment'); ?>🎉</h2>
362 <p> <input class="better_payment_settings_opt_in" type="checkbox" name="better_payment_settings_opt_in" value="yes" <?php echo isset($bp_admin_saved_settings['better_payment_settings_opt_in']) && $bp_admin_saved_settings['better_payment_settings_opt_in'] == 'yes' ? ' checked' : '' ?>>
363 <label for="better_payment_settings_opt_in"><?php esc_html_e('Share non-sensitive diagnostic data and plugin usage information.', 'better-payment'); ?></label>
364 </p>
365 <p><?php esc_html_e('What do we collect? We collect non-sensitive diagnostic data and plugin usage information. Your site URL, WordPress & PHP version, plugins & themes and email address to send you the discount coupon. This data lets us make sure this plugin always stays compatible with the most popular plugins and themes. No spam, we promise.', 'better-payment'); ?></p>
366 </div>
367 </form>
368 </div>
369 <?php
370 }
371
372 /**
373 * Footer content
374 *
375 * @since 0.0.1
376 */
377 public function setup_wizard_footer()
378 {
379 ?>
380 <div class="better-payment better-payment-setup-footer">
381 <button id="better-payment-prev" class="button button__active better-payment-admin-settings-button"><?php esc_html_e('< Previous', 'better-payment') ?></button>
382 <button id="better-payment-next" class="button button__active better-payment-admin-settings-button"><?php esc_html_e('Next >', 'better-payment') ?></button>
383 <button id="better-payment-save" style="display: none" class="button button__active better-payment-admin-settings-button better-payment-setup-wizard-save"><?php esc_html_e('Finish', 'better-payment') ?></button>
384 </div>
385 <?php
386 }
387
388 /**
389 * render_wizard
390 *
391 * @since 0.0.1
392 */
393 public function render_wizard()
394 {
395 ?>
396 <div class="better-payment-setup-wizard-wrap">
397 <?php
398 // $bp_admin_saved_settings = DB::get_settings();
399
400 // $this->change_site_title();
401 // $this->tab_step();
402 // $this->tab_content($bp_admin_saved_settings);
403 // $this->setup_wizard_footer();
404 include BETTER_PAYMENT_ADMIN_VIEWS_PATH . '/better-payment-quick-setup.php';
405 ?>
406 </div>
407 <?php
408 }
409
410 public function bp_quick_setup_save_tracking() {
411 // Verify the Nonce
412 if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'better_payment_admin_nonce')) {
413 wp_send_json_error( __( 'Nonce verification failed.', 'better-payment' ) );
414 return;
415 }
416
417 if (!current_user_can('manage_options')) {
418 wp_send_json_error( __( 'Insufficient permissions.', 'better-payment' ) );
419 return;
420 }
421
422 $context = isset( $_POST['context'] ) ? sanitize_key( wp_unslash( $_POST['context'] ) ) : 'proceed';
423
424 if ( isset( $_POST[ 'is_tracking' ] ) && $_POST[ 'is_tracking' ] === 'true' ) {
425 /**
426 * `better_payment_settings_opt_in` is NOT the tracking gate — that is
427 * `wpins_allow_tracking`, written by wpins_process() below. This option
428 * is wizard UI state: it is localized as `is_tracking` (see
429 * setup_wizard_scripts()) and makes QuickSetupWizard open on the
430 * Settings step with back-navigation to Start disabled.
431 *
432 * So the Skip path deliberately does not write it. Skip must leave the
433 * wizard behaving exactly as it does today — Start screen shown, Back
434 * still available — while still turning tracking on.
435 *
436 * @since 2.3.2
437 */
438 if ( 'skip' !== $context ) {
439 update_option('better_payment_settings_opt_in', 'yes');
440 }
441
442 self::wpins_process();
443 wp_send_json_success( __( 'Tracking data saved successfully.', 'better-payment' ) );
444 } else {
445 wp_send_json_error( __( 'Invalid tracking parameter.', 'better-payment' ) );
446 }
447 }
448
449 /**
450 * Save setup wizard data
451 *
452 * @since 0.0.1
453 */
454 public static function save_setup_wizard_data()
455 {
456 /**
457 * Verify the Nonce
458 */
459 if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'better_payment_admin_nonce')) {
460 return;
461 }
462
463 if (!current_user_can('manage_options')) {
464 return;
465 }
466
467 try{
468 Settings::save_default_settings(1);
469 Settings::save_settings(json_decode(stripslashes($_POST['form_data']), true));
470
471 update_option( 'better_payment_setup_wizard', 'complete' );
472
473 // if (!did_action('elementor/loaded')) {
474 // wp_send_json_success( [ 'redirect_url' => admin_url() ] );
475 // }else {
476 wp_send_json_success( [ 'redirect_url' => admin_url( 'admin.php?page=better-payment-admin&tab=dashboard' ) ] );
477 // }
478 }catch (\Exception $e) {
479 wp_send_json_error($e->getMessage());
480 }
481
482 die;
483 }
484
485 /**
486 * WPIns process
487 *
488 * The single tracking-activation routine. Every path that turns usage
489 * tracking on goes through here — the wizard's "Proceed To Next Step" and
490 * "Skip It" buttons, and the automatic opt-in for fresh installs in
491 * Traits\Helper::maybe_auto_enable_usage_tracking().
492 *
493 * @param bool $force_send Send the payload immediately. True for the wizard
494 * buttons, which run inside an AJAX request. Pass
495 * FALSE from anything that runs during a page render:
496 * send_data() posts with `blocking => true` and a 30s
497 * timeout, so a forced send there would stall the
498 * response. Consent alone is enough — the caller's
499 * Plugin_Usage_Tracker::init() schedules the daily
500 * event and the first run sends.
501 *
502 * @return void
503 * @since 0.0.1
504 */
505 public static function wpins_process( $force_send = true ){
506 $plugin_name = basename( BETTER_PAYMENT_FILE, '.php' );
507
508 if ( class_exists( '\Better_Payment\Lite\Classes\Plugin_Usage_Tracker' ) ){
509 $tracker = Plugin_Usage_Tracker::get_instance( BETTER_PAYMENT_FILE, [
510 'opt_in' => true,
511 'goodbye_form' => true,
512 'item_id' => '64e1f724b5e14edb343e'
513 ] );
514 $tracker->set_is_tracking_allowed( true );
515
516 if ( $force_send ) {
517 $tracker->do_tracking( true );
518 }
519 }
520 }
521
522 /**
523 * Redirect
524 *
525 * @since 0.0.1
526 */
527 public static function redirect()
528 {
529 update_option('better_payment_setup_wizard', 'init');
530 wp_redirect(admin_url('admin.php?page=better-payment-setup-wizard'));
531 }
532
533 /**
534 * Site title
535 *
536 * @since 0.0.1
537 */
538 public function change_site_title()
539 {
540 ?>
541 <script>
542 document.title = "<?php esc_html_e('Quick Setup Wizard - Better Payment', 'better-payment'); ?>"
543 </script>
544 <?php
545 }
546 }