PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.4.1
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.4.1
2.4.1 2.4.0 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 All 68 releases
← All changes | includes/Admin/Setup_Wizard.php +122 -382 1.0.3 → 2.4.1 View file →
@@ -2,8 +2,9 @@
2 2
3 3 namespace Better_Payment\Lite\Admin;
4 4
5 5 use Better_Payment\Lite\Classes\Plugin_Usage_Tracker;
6 +use Better_Payment\Lite\Traits\Helper as TraitsHelper;
6 7
7 8 if (!defined('ABSPATH')) {
8 9 exit;
9 10 } // Exit if accessed directly.
@@ -10,12 +11,19 @@
10 11
11 12 /**
12 13 * Setup Wizard
13 14 *
15 + * The wizard UI is the React quick-setup app (src/admin/quick-setup), mounted by
16 + * views/better-payment-quick-setup.php. The PHP-rendered steps, footer and their
17 + * jQuery script (src/js/setup-wizard.js) predated it and were no longer called,
18 + * so they have been removed.
19 + *
14 20 * @since 0.0.2
15 21 */
16 22 class Setup_Wizard
17 23 {
24 + use TraitsHelper;
25 +
18 26 protected $file_version;
19 27
20 28 /**
21 29 * Setup Wizard constructor.
@@ -26,15 +34,16 @@
26 34 {
27 35 $this->file_version = defined('WP_DEBUG') && WP_DEBUG ? time() : BETTER_PAYMENT_VERSION;
28 36 add_action('admin_enqueue_scripts', array($this, 'setup_wizard_scripts'));
29 37 add_action('admin_menu', array($this, 'admin_menu'));
30 - add_action('wp_ajax_save_setup_wizard_data', [$this, 'save_setup_wizard_data']);
38 + add_action('wp_ajax_save_setup_wizard_data', [$this, 'save_setup_wizard_data']);
39 + add_action( 'wp_ajax_bp_quick_setup_save_tracking', [ $this, 'bp_quick_setup_save_tracking' ] );
31 40 add_action('in_admin_header', [$this, 'remove_notice'], 1000);
32 41 }
33 42
34 43 /**
35 44 * Remove all notice in setup wizard page
36 - *
45 + *
37 46 * @since 0.0.2
38 47 */
39 48 public function remove_notice()
40 49 {
@@ -47,45 +56,47 @@
47 56 /**
48 57 * setup_wizard_scripts
49 58 * @param $hook
50 59 * @return array
51 - *
60 + *
52 61 * @since 0.0.2
53 62 */
54 63 public function setup_wizard_scripts($hook)
55 64 {
56 65 if (isset($hook) && $hook == 'admin_page_better-payment-setup-wizard') {
57 - //Styles
58 - wp_register_style('jquery-ui', '//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.min.css');
59 - wp_enqueue_style('jquery-ui');
66 + // Determine the correct file extension based on debug mode
67 + $js_ext = file_exists(BETTER_PAYMENT_PATH . '/assets/admin/quick-setup/quick-setup.min.js') ? '.min.js' : '.js';
68 + $css_ext = file_exists(BETTER_PAYMENT_PATH . '/assets/admin/quick-setup/quick-setup.min.css') ? '.min.css' : '.css';
60 69
61 - wp_enqueue_style('bp-setup-wizard-style', BETTER_PAYMENT_ASSETS . '/css/setup-wizard.min.css', null, $this->file_version);
62 - wp_enqueue_style('bp-settings-style', BETTER_PAYMENT_ASSETS . '/css/style.min.css', null, $this->file_version);
63 - wp_enqueue_style('bp-icon-admin', BETTER_PAYMENT_ASSETS . '/icon/style.min.css');
64 - wp_enqueue_style('sweetalert2-css', BETTER_PAYMENT_ASSETS . '/vendor/sweetalert2/css/sweetalert2.min.css');
70 + // Enqueue React Quick Setup CSS
71 + wp_enqueue_style(
72 + 'bp-quick-setup-css',
73 + BETTER_PAYMENT_ASSETS . '/admin/quick-setup/quick-setup' . $css_ext,
74 + array(),
75 + $this->file_version
76 + );
65 77
66 - //Scripts
67 - wp_enqueue_script('bp-setup-wizard-js', BETTER_PAYMENT_ASSETS . '/js/setup-wizard.min.js', null, $this->file_version);
68 -
69 - wp_localize_script('bp-setup-wizard-js', 'betterPaymentObjWizard', array(
70 - 'nonce' => wp_create_nonce('better_payment_admin_nonce'),
71 - 'success_image' => BETTER_PAYMENT_ASSETS . '/img/success.gif',
72 - 'alerts' => [
73 - 'confirm' => esc_html__('Are you sure?', 'better-payment'),
74 - 'confirm_description' => esc_html__("You won't be able to revert this!", 'better-payment'),
75 - 'yes' => esc_html__('Yes, delete it!', 'better-payment'),
76 - 'no' => esc_html__('No, cancel!', 'better-payment'),
77 - ],
78 - 'messages' => [
79 - 'success' => esc_html__('Changes saved successfully!', 'better-payment'),
80 - 'error' => esc_html__('Opps! something went wrong!', 'better-payment'),
81 - 'no_action_taken' => esc_html__('No action taken!', 'better-payment'),
82 - ]
78 + // Enqueue React Quick Setup JS with WordPress dependencies
79 + wp_enqueue_script(
80 + 'bp-quick-setup-js',
81 + BETTER_PAYMENT_ASSETS . '/admin/quick-setup/quick-setup' . $js_ext,
82 + // wp-hooks: the PayPal step's refund-credentials slot, which Pro fills (utils/proHandoff.js).
83 + array('wp-element', 'wp-i18n', 'wp-hooks'),
84 + $this->file_version,
85 + true
86 + );
87 +
88 + // Localize script with the data the React wizard reads.
89 + wp_localize_script('bp-quick-setup-js', 'betterPaymentObjWizard', array(
90 + 'admin_nonce' => wp_create_nonce('better_payment_admin_nonce'),
91 + 'ajaxUrl' => admin_url('admin-ajax.php'),
92 + 'settings' => DB::get_settings(),
93 + 'is_tracking' => get_option('better_payment_settings_opt_in') === 'yes' ? 1 : 0,
94 + 'currencies' => $this->get_currency_list(),
95 + 'is_pro' => defined('BETTER_PAYMENT_PRO_VERSION') && BETTER_PAYMENT_PRO_VERSION ? true : false,
96 + // Arrives as '1' / '' (wp_localize_script casts scalars); read it with parseProEnabled().
97 + 'pro_enabled' => \Better_Payment\Lite\Classes\ProCompatibility::pro_enabled(),
83 98 ));
84 -
85 - wp_enqueue_script('bp-setup-wizard-localize');
86 -
87 - wp_enqueue_script('sweetalert2-js', BETTER_PAYMENT_ASSETS . '/vendor/sweetalert2/js/sweetalert2.min.js', array('jquery'), BETTER_PAYMENT_VERSION, true);
88 99 }
89 100 return [];
90 101 }
91 102
@@ -90,9 +101,9 @@
90 101 }
91 102
92 103 /**
93 104 * Create admin menu for setup wizard
94 - *
105 + *
95 106 * @since 0.0.2
96 107 */
97 108 public function admin_menu()
98 109 {
@@ -97,9 +108,9 @@
97 108 public function admin_menu()
98 109 {
99 110
100 111 add_submenu_page(
101 - null,
112 + "admin.php?page=better-payment-setup-wizard",
102 113 esc_html__('Better Payment ', 'better-payment'),
103 114 esc_html__('Better Payment ', 'better-payment'),
104 115 'manage_options',
105 116 'better-payment-setup-wizard',
@@ -107,327 +118,65 @@
107 118 );
108 119 }
109 120
110 121 /**
111 - * Render tab step
112 - *
113 - * @since 0.0.2
114 - */
115 - public function tab_step()
116 - {
117 - $wizard_column = 'four';
118 - ?>
119 - <ul class="better-payment-setup-wizard <?php echo esc_attr( $wizard_column ); ?>" data-step="0">
120 - <li class="step">
121 - <div class="icon">
122 - <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">
123 - <g>
124 - <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
125 - 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
126 - 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
127 - 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
128 - 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
129 - 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
130 - 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
131 - 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" />
132 - </g>
133 - </svg>
134 - </div>
135 - <div class="name"><?php esc_html_e('Getting Started', 'better-payment'); ?></div>
136 - </li>
137 - <li class="step">
138 - <div class="icon">
139 - <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">
140 - <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
141 -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
142 -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
143 -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
144 -l-5.2-5.2l8.8-8.8C50.4,20.4,50.4,18,48.9,16.6z" />
145 - </svg>
146 - </div>
147 - <div class="name"><?php esc_html_e('PayPal Configuration', 'better-payment'); ?></div>
148 - </li>
149 - <li class="step">
150 - <div class="icon">
151 - <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">
152 - <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
153 -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
154 -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
155 -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
156 -l-5.2-5.2l8.8-8.8C50.4,20.4,50.4,18,48.9,16.6z" />
157 - </svg>
158 - </div>
159 - <div class="name"><?php esc_html_e('Stripe Configuration', 'better-payment'); ?></div>
160 - </li>
161 - <li class="step">
162 - <div class="icon">
163 - <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">
164 - <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
165 -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
166 -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" />
167 - </svg>
168 - </div>
169 - <div class="name"><?php esc_html_e('Finalize', 'better-payment'); ?></div>
170 - </li>
171 - </ul>
172 - <?php
173 - }
174 -
175 - /**
176 - * Get currency list
122 + * render_wizard
177 123 *
178 - * @since 0.0.2
179 - */
180 - public function get_currency_list(){
181 - $currency_list = [
182 - 'AUD' => 'AUD',
183 - 'CAD' => 'CAD',
184 - 'CZK' => 'CZK',
185 - 'DKK' => 'DKK',
186 - 'EUR' => 'EUR',
187 - 'HKD' => 'HKD',
188 - 'HUF' => 'HUF',
189 - 'ILS' => 'ILS',
190 - 'JPY' => 'JPY',
191 - 'MXN' => 'MXN',
192 - 'NOK' => 'NOK',
193 - 'NZD' => 'NZD',
194 - 'PHP' => 'PHP',
195 - 'PLN' => 'PLN',
196 - 'GBP' => 'GBP',
197 - 'RUB' => 'RUB',
198 - 'SGD' => 'SGD',
199 - 'SEK' => 'SEK',
200 - 'CHF' => 'CHF',
201 - 'TWD' => 'TWD',
202 - 'THB' => 'THB',
203 - 'USD' => 'USD'
204 - ];
205 -
206 - return $currency_list;
207 - }
208 -
209 - /**
210 - * Tav view content
211 - *
212 - * @since 0.0.2
213 - */
214 - public function tab_content($bp_admin_saved_settings)
215 - {
216 - $bp_admin_saved_settings = DB::get_settings();
217 - $currency_list = $this->get_currency_list();
218 - ?>
219 - <div class="better-payment-setup-body better-payment">
220 - <form method="post" id="better-payment-admin-settings-form" class="better-payment-setup-wizard-form" action="#">
221 -
222 - <div id="configuration" class="setup-content active">
223 - <div id="general" class="sidebar__tab__content show payment__options better-payment-box">
224 - <div class="payment__option">
225 - <div class="payment__option__content">
226 - <h4><?php esc_html_e('PayPal', 'better-payment'); ?></h4>
227 - <p><?php esc_html_e('Enable PayPal if you want to make transaction using PayPal.', 'better-payment'); ?></p>
228 - </div>
229 - <div class="active__status">
230 - <label class="bp-switch">
231 - <input type="hidden" name="better_payment_settings_general_general_paypal" value="no">
232 - <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' : '' ?>>
233 - <span class="switch__btn"></span>
234 - </label>
235 - </div>
236 - </div>
237 - <div class="payment__option">
238 - <div class="payment__option__content">
239 - <h4><?php esc_html_e('Stripe', 'better-payment'); ?></h4>
240 - <p><?php esc_html_e('Enable Stripe if you want to accept payment via Stripe.', 'better-payment'); ?></p>
241 - </div>
242 - <div class="active__status">
243 - <label class="bp-switch">
244 - <input type="hidden" name="better_payment_settings_general_general_stripe" value="no">
245 - <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' : '' ?>>
246 - <span class="switch__btn"></span>
247 - </label>
248 - </div>
249 - </div>
250 - <div class="payment__option">
251 - <div class="payment__option__content">
252 - <h4><?php esc_html_e('Email Notification', 'better-payment'); ?></h4>
253 - <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>
254 - </div>
255 - <div class="active__status">
256 - <label class="bp-switch">
257 - <input type="hidden" name="better_payment_settings_general_general_email" value="no">
258 - <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' : '' ?>>
259 - <span class="switch__btn"></span>
260 - </label>
261 - </div>
262 - </div>
263 - <div class="payment__option">
264 - <div class="payment__option__content">
265 - <h4><?php esc_html_e('Currency', 'better-payment'); ?></h4>
266 - <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>
267 - </div>
268 - <div class="active__status">
269 - <div class="bp-select">
270 - <select name="better_payment_settings_general_general_currency">
271 - <option value="" disabled> <?php esc_html_e('Select Currency', 'better-payment'); ?> </option>
272 - <?php foreach ($currency_list as $key => $value){
273 - $selected = isset($bp_admin_saved_settings['better_payment_settings_general_general_currency']) && $bp_admin_saved_settings['better_payment_settings_general_general_currency'] == $key?'selected':'';
274 - printf( '<option value="%s" %s >%s</option>', esc_attr( $key ), esc_attr( $selected ), esc_html__( $key, 'better-payment' ) );
275 - } ?>
276 - </select>
277 - </div>
278 - </div>
279 - </div>
280 - </div>
281 - </div>
282 -
283 - <div id="quick-setup-paypal" class="setup-content quick-setup-paypal better-payment-box">
284 - <div class="payment__options ">
285 - <div class="payment__option">
286 - <div class="payment__option__content">
287 - <h4><?php esc_html_e('Live Mode', 'better-payment'); ?></h4>
288 - <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>
289 - </div>
290 - <div class="active__status">
291 - <label class="bp-switch">
292 - <input type="hidden" name="better_payment_settings_payment_paypal_live_mode" value="no">
293 - <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' : '' ?>>
294 - <span class="switch__btn"></span>
295 - </label>
296 - </div>
297 - </div>
298 - <div class="payment__option">
299 - <div class="payment__option__content">
300 - <h4><?php esc_html_e('Business Email', 'better-payment'); ?></h4>
301 - <p><?php esc_html_e('Your PayPal account email address to accept payment via PayPal.', 'better-payment'); ?></p>
302 - </div>
303 - <div class="active__status input__wrap">
304 - <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'] ) : '' ?>">
305 - </div>
306 - </div>
307 - </div>
308 - </div>
309 -
310 - <div id="quick-setup-stripe" class="setup-content quick-setup-stripe">
311 - <div class="payment__options">
312 - <div class="payment__option">
313 - <div class="payment__option__content">
314 - <h4><?php esc_html_e('Live Mode', 'better-payment'); ?></h4>
315 - <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>
316 - </div>
317 - <div class="active__status">
318 - <label class="bp-switch">
319 - <input type="hidden" name="better_payment_settings_payment_stripe_live_mode" value="no">
320 - <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' : '' ?>>
321 - <span class="switch__btn"></span>
322 - </label>
323 - </div>
324 - </div>
325 -
326 - <?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'; ?>
327 -
328 - <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' ?>">
329 - <div class="payment__option__content">
330 - <h4><?php esc_html_e('Live Public Key', 'better-payment'); ?></h4>
331 - <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>
332 - </div>
333 - <div class="active__status input__wrap">
334 - <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'); ?>">
335 - </div>
336 - </div>
337 - <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' ?>">
338 - <div class="payment__option__content">
339 - <h4><?php esc_html_e('Live Secret Key', 'better-payment'); ?></h4>
340 - <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>
341 - </div>
342 - <div class="active__status input__wrap">
343 - <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'] ) : '' ?>">
344 - </div>
345 - </div>
346 - <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' ?> ">
347 - <div class="payment__option__content">
348 - <h4><?php esc_html_e('Test Public Key', 'better-payment'); ?></h4>
349 - <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>
350 - </div>
351 - <div class="active__status input__wrap">
352 - <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'] ) : '' ?>">
353 - </div>
354 - </div>
355 - <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' ?> ">
356 - <div class="payment__option__content">
357 - <h4><?php esc_html_e('Test Secret Key', 'better-payment'); ?></h4>
358 - <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>
359 - </div>
360 - <div class="active__status input__wrap">
361 - <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'] ) : '' ?>">
362 - </div>
363 - </div>
364 - </div>
365 - </div>
366 -
367 - <div id="finalize" class="setup-content better-payment-box">
368 - <header class="pb31 text-center">
369 - <div class="bp-container">
370 - <div class="bp-row">
371 - <div class="bp-col">
372 - <div class="logo">
373 - <a href="javascript:void(0)"><img src="<?php echo esc_url( BETTER_PAYMENT_ASSETS . '/img/logo.svg' ); ?>" alt="Better Payment logo"></a>
374 - </div>
375 - </div>
376 - </div>
377 - </div>
378 - </header>
379 - <h2 class="text-center"><?php esc_html_e('Great Job! Your Configuration is Complete ', 'better-payment'); ?>🎉</h2>
380 - <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' : '' ?>>
381 - <label for="better_payment_settings_opt_in"><?php esc_html_e('Share non-sensitive diagnostic data and plugin usage information.', 'better-payment'); ?></label>
382 - </p>
383 - <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>
384 - </div>
385 - </form>
386 - </div>
387 - <?php
388 - }
389 -
390 - /**
391 - * Footer content
392 - *
393 124 * @since 0.0.1
394 125 */
395 - public function setup_wizard_footer()
396 - {
397 - ?>
398 - <div class="better-payment better-payment-setup-footer">
399 - <button id="better-payment-prev" class="button button__active better-payment-admin-settings-button"><?php esc_html_e('< Previous', 'better-payment') ?></button>
400 - <button id="better-payment-next" class="button button__active better-payment-admin-settings-button"><?php esc_html_e('Next >', 'better-payment') ?></button>
401 - <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>
402 - </div>
403 - <?php
404 - }
405 -
406 - /**
407 - * render_wizard
408 - *
409 - * @since 0.0.1
410 - */
411 126 public function render_wizard()
412 127 {
413 128 ?>
414 129 <div class="better-payment-setup-wizard-wrap">
415 130 <?php
416 - $bp_admin_saved_settings = DB::get_settings();
417 -
418 - $this->change_site_title();
419 - $this->tab_step();
420 - $this->tab_content($bp_admin_saved_settings);
421 - $this->setup_wizard_footer();
131 + include BETTER_PAYMENT_ADMIN_VIEWS_PATH . '/better-payment-quick-setup.php';
422 132 ?>
423 133 </div>
424 134 <?php
425 135 }
426 136
137 + public function bp_quick_setup_save_tracking() {
138 + // Verify the Nonce
139 + if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'better_payment_admin_nonce')) {
140 + wp_send_json_error( __( 'Nonce verification failed.', 'better-payment' ) );
141 + return;
142 + }
143 +
144 + if (!current_user_can('manage_options')) {
145 + wp_send_json_error( __( 'Insufficient permissions.', 'better-payment' ) );
146 + return;
147 + }
148 +
149 + $context = isset( $_POST['context'] ) ? sanitize_key( wp_unslash( $_POST['context'] ) ) : 'proceed';
150 +
151 + if ( isset( $_POST[ 'is_tracking' ] ) && $_POST[ 'is_tracking' ] === 'true' ) {
152 + /**
153 + * `better_payment_settings_opt_in` is NOT the tracking gate — that is
154 + * `wpins_allow_tracking`, written by wpins_process() below. This option
155 + * is wizard UI state: it is localized as `is_tracking` (see
156 + * setup_wizard_scripts()) and makes QuickSetupWizard open on the
157 + * Settings step with back-navigation to Start disabled.
158 + *
159 + * So the Skip path deliberately does not write it. Skip must leave the
160 + * wizard behaving exactly as it does today — Start screen shown, Back
161 + * still available — while still turning tracking on.
162 + *
163 + * @since 2.3.2
164 + */
165 + if ( 'skip' !== $context ) {
166 + update_option('better_payment_settings_opt_in', 'yes');
167 + }
168 +
169 + self::wpins_process();
170 + wp_send_json_success( __( 'Tracking data saved successfully.', 'better-payment' ) );
171 + } else {
172 + wp_send_json_error( __( 'Invalid tracking parameter.', 'better-payment' ) );
173 + }
174 + }
175 +
427 176 /**
428 177 * Save setup wizard data
429 - *
178 + *
430 179 * @since 0.0.1
431 180 */
432 181 public static function save_setup_wizard_data()
433 182 {
@@ -437,52 +186,54 @@
437 186 if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'better_payment_admin_nonce')) {
438 187 return;
439 188 }
440 189
190 + if (!current_user_can('manage_options')) {
191 + return;
192 + }
193 +
441 194 try{
442 195 Settings::save_default_settings(1);
443 - Settings::save_settings($_POST['form_data']);
444 -
445 - $posted_field_opt_in_val = '';
446 - foreach ($_POST['form_data'] as $posted_field) {
447 - $posted_field_name = sanitize_key($posted_field['name']);
448 - $posted_field_value = sanitize_key($posted_field['value']);
449 -
450 - if('better_payment_settings_opt_in' === $posted_field_name){
451 - $posted_field_opt_in_val = $posted_field_value;
452 - break;
453 - }
454 - }
196 + Settings::save_settings(json_decode(stripslashes($_POST['form_data']), true));
455 197
456 - if ( 'yes' === $posted_field_opt_in_val ) {
457 - self::wpins_process();
458 - }
459 -
460 198 update_option( 'better_payment_setup_wizard', 'complete' );
461 199
462 - if (!did_action('elementor/loaded')) {
463 - wp_send_json_success( [ 'redirect_url' => admin_url() ] );
464 - }else {
465 - wp_send_json_success( [ 'redirect_url' => admin_url( 'admin.php?page=better-payment-settings' ) ] );
466 - }
200 + // if (!did_action('elementor/loaded')) {
201 + // wp_send_json_success( [ 'redirect_url' => admin_url() ] );
202 + // }else {
203 + wp_send_json_success( [ 'redirect_url' => admin_url( 'admin.php?page=better-payment-admin&tab=dashboard' ) ] );
204 + // }
467 205 }catch (\Exception $e) {
468 - wp_send_json_error($e->getMessage());
206 + wp_send_json_error($e->getMessage());
469 207 }
470 -
208 +
471 209 die;
472 210 }
473 211
474 212 /**
475 213 * WPIns process
476 - *
214 + *
215 + * The single tracking-activation routine. Every path that turns usage
216 + * tracking on goes through here — the wizard's "Proceed To Next Step" and
217 + * "Skip It" buttons, and the automatic opt-in for fresh installs in
218 + * Traits\Helper::maybe_auto_enable_usage_tracking().
219 + *
220 + * @param bool $force_send Send the payload immediately. True for the wizard
221 + * buttons, which run inside an AJAX request. Pass
222 + * FALSE from anything that runs during a page render:
223 + * send_data() posts with `blocking => true` and a 30s
224 + * timeout, so a forced send there would stall the
225 + * response. Consent alone is enough — the caller's
226 + * Plugin_Usage_Tracker::init() schedules the daily
227 + * event and the first run sends.
228 + *
229 + * @return void
477 230 * @since 0.0.1
478 231 */
479 - public static function wpins_process(){
232 + public static function wpins_process( $force_send = true ){
480 233 $plugin_name = basename( BETTER_PAYMENT_FILE, '.php' );
481 -
482 - require_once BETTER_PAYMENT_PATH . 'includes/class-better-payment-plugin-usage-tracker.php';
483 234
484 - if ( class_exists( 'Plugin_Usage_Tracker' ) ){
235 + if ( class_exists( '\Better_Payment\Lite\Classes\Plugin_Usage_Tracker' ) ){
485 236 $tracker = Plugin_Usage_Tracker::get_instance( BETTER_PAYMENT_FILE, [
486 237 'opt_in' => true,
487 238 'goodbye_form' => true,
488 239 'item_id' => '64e1f724b5e14edb343e'
@@ -487,15 +238,18 @@
487 238 'goodbye_form' => true,
488 239 'item_id' => '64e1f724b5e14edb343e'
489 240 ] );
490 241 $tracker->set_is_tracking_allowed( true );
491 - $tracker->do_tracking( true );
242 +
243 + if ( $force_send ) {
244 + $tracker->do_tracking( true );
245 + }
492 246 }
493 247 }
494 248
495 249 /**
496 250 * Redirect
497 - *
251 + *
498 252 * @since 0.0.1
499 253 */
500 254 public static function redirect()
501 255 {
@@ -501,19 +255,5 @@
501 255 {
502 256 update_option('better_payment_setup_wizard', 'init');
503 257 wp_redirect(admin_url('admin.php?page=better-payment-setup-wizard'));
504 258 }
505 -
506 - /**
507 - * Site title
508 - *
509 - * @since 0.0.1
510 - */
511 - public function change_site_title()
512 - {
513 - ?>
514 - <script>
515 - document.title = "<?php esc_html_e('Quick Setup Wizard - Better Payment', 'better-payment'); ?>"
516 - </script>
517 - <?php
518 - }
519 -}
259 +}