PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.2.0
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.2.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 1.0.5 1.0.6 All 66 releases
better-payment / includes / Traits / Helper.php

Helper.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.2.0, at includes/Traits/Helper.php

872 lines 24.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\Traits;
4
5 use Better_Payment\Lite\Classes\Plugin_Usage_Tracker;
6
7 /**
8 * Exit if accessed directly
9 */
10 if (!defined('ABSPATH')) {
11 exit;
12 }
13
14 /**
15 * Helper trait
16 *
17 * @since 0.0.1
18 */
19 trait Helper
20 {
21 use Elements, ElementorHelper, WordPressHelper, TemplateQuery;
22
23 public function bp_template_render($filePath, $variables = array(), $print = true)
24 {
25 $output = NULL;
26
27 if (file_exists($filePath)) {
28 // Extract the variables to a local namespace
29 extract($variables);
30
31 // Start output buffering
32 ob_start();
33
34 // Include the template file
35 include $filePath;
36
37 // End buffering and return its contents
38 $output = ob_get_clean();
39 }
40
41 if ( $print ) {
42 print $output;
43 }
44
45 return $output;
46 }
47
48 /**
49 * List of allowed html tag for wp_kses
50 *
51 * bp_allowed_tags
52 * @return array
53 */
54 public function bp_allowed_tags() {
55 return [
56 'a' => [
57 'href' => [],
58 'title' => [],
59 'class' => [],
60 'rel' => [],
61 'id' => [],
62 'style' => [],
63 'target' => [],
64 ],
65 'q' => [
66 'cite' => [],
67 'class' => [],
68 'id' => [],
69 ],
70 'img' => [
71 'src' => [],
72 'alt' => [],
73 'height' => [],
74 'width' => [],
75 'class' => [],
76 'id' => [],
77 'style' => []
78 ],
79 'span' => [
80 'class' => [],
81 'id' => [],
82 'style' => []
83 ],
84 'dfn' => [
85 'class' => [],
86 'id' => [],
87 'style' => []
88 ],
89 'time' => [
90 'datetime' => [],
91 'class' => [],
92 'id' => [],
93 'style' => [],
94 ],
95 'cite' => [
96 'title' => [],
97 'class' => [],
98 'id' => [],
99 'style' => [],
100 ],
101 'hr' => [
102 'class' => [],
103 'id' => [],
104 'style' => [],
105 ],
106 'b' => [
107 'class' => [],
108 'id' => [],
109 'style' => [],
110 ],
111 'p' => [
112 'class' => [],
113 'id' => [],
114 'style' => []
115 ],
116 'i' => [
117 'class' => [],
118 'id' => [],
119 'style' => []
120 ],
121 'u' => [
122 'class' => [],
123 'id' => [],
124 'style' => []
125 ],
126 's' => [
127 'class' => [],
128 'id' => [],
129 'style' => [],
130 ],
131 'br' => [],
132 'em' => [
133 'class' => [],
134 'id' => [],
135 'style' => []
136 ],
137 'code' => [
138 'class' => [],
139 'id' => [],
140 'style' => [],
141 ],
142 'mark' => [
143 'class' => [],
144 'id' => [],
145 'style' => [],
146 ],
147 'small' => [
148 'class' => [],
149 'id' => [],
150 'style' => []
151 ],
152 'abbr' => [
153 'title' => [],
154 'class' => [],
155 'id' => [],
156 'style' => [],
157 ],
158 'strong' => [
159 'class' => [],
160 'id' => [],
161 'style' => []
162 ],
163 'del' => [
164 'class' => [],
165 'id' => [],
166 'style' => []
167 ],
168 'ins' => [
169 'class' => [],
170 'id' => [],
171 'style' => []
172 ],
173 'sub' => [
174 'class' => [],
175 'id' => [],
176 'style' => [],
177 ],
178 'sup' => [
179 'class' => [],
180 'id' => [],
181 'style' => [],
182 ],
183 'div' => [
184 'class' => [],
185 'id' => [],
186 'style' => []
187 ],
188 'strike' => [
189 'class' => [],
190 'id' => [],
191 'style' => [],
192 ],
193 'acronym' => [],
194 'h1' => [
195 'class' => [],
196 'id' => [],
197 'style' => [],
198 ],
199 'h2' => [
200 'class' => [],
201 'id' => [],
202 'style' => [],
203 ],
204 'h3' => [
205 'class' => [],
206 'id' => [],
207 'style' => [],
208 ],
209 'h4' => [
210 'class' => [],
211 'id' => [],
212 'style' => [],
213 ],
214 'h5' => [
215 'class' => [],
216 'id' => [],
217 'style' => [],
218 ],
219 'h6' => [
220 'class' => [],
221 'id' => [],
222 'style' => [],
223 ],
224 'button' => [
225 'class' => [],
226 'id' => [],
227 'style' => [],
228 'data-paypal-info' => [],
229 ],
230 'center' => [
231 'class' => [],
232 'id' => [],
233 'style' => [],
234 ],
235 'ul' => [
236 'class' => [],
237 'id' => [],
238 'style' => [],
239 ],
240 'ol' => [
241 'class' => [],
242 'id' => [],
243 'style' => [],
244 ],
245 'li' => [
246 'class' => [],
247 'id' => [],
248 'style' => [],
249 ],
250 'table' => [
251 'class' => [],
252 'id' => [],
253 'style' => [],
254 'dir' => [],
255 'align' => [],
256 ],
257 'thead' => [
258 'class' => [],
259 'id' => [],
260 'style' => [],
261 'align' => [],
262 ],
263 'tbody' => [
264 'class' => [],
265 'id' => [],
266 'style' => [],
267 'align' => [],
268 ],
269 'tfoot' => [
270 'class' => [],
271 'id' => [],
272 'style' => [],
273 'align' => [],
274 ],
275 'th' => [
276 'class' => [],
277 'id' => [],
278 'style' => [],
279 'align' => [],
280 'colspan' => [],
281 'rowspan' => [],
282 ],
283 'tr' => [
284 'class' => [],
285 'id' => [],
286 'style' => [],
287 'align' => [],
288 ],
289 'td' => [
290 'class' => [],
291 'id' => [],
292 'style' => [],
293 'align' => [],
294 'colspan' => [],
295 'rowspan' => [],
296 ],
297 ];
298 }
299
300 /**
301 * Optional usage tracker
302 *
303 * @since v1.1.1
304 */
305 public function start_plugin_tracking()
306 {
307 $tracker = Plugin_Usage_Tracker::get_instance( BETTER_PAYMENT_FILE, [
308 'opt_in' => true,
309 'goodbye_form' => true,
310 'item_id' => '64e1f724b5e14edb343e'
311 ] );
312 $tracker->set_notice_options(array(
313 'notice' => 'Want to help make <strong>Better Payment</strong> even more awesome? You can get a <strong>10% discount coupon</strong> for Pro upgrade if you allow.',
314 'extra_notice' => 'We collect non-sensitive diagnostic data and plugin usage information.
315 Your site URL, WordPress & PHP version, plugins & themes and email address to send you the
316 discount coupon. This data lets us make sure this plugin always stays compatible with the most
317 popular plugins and themes. No spam, I promise.',
318 ));
319 $tracker->init();
320 }
321
322 /**
323 * List of currencies not supported by paypal or stripe
324 *
325 * @since v1.3.1
326 */
327 public function bp_unsupported_currencies( $method = '' ) {
328 $method = sanitize_text_field( strtolower( $method ) );
329 $all_currencies = [
330 'paypal' => [
331 'AED',
332 'BGN',
333 'BAM',
334 'KES',
335 'NGN',
336 'RON',
337 'RSD',
338 'ZAR',
339 'GHS',
340 ],
341 'stripe' => [],
342 ];
343
344 return !empty( $all_currencies[ $method ] ) ? $all_currencies[ $method ] : [];
345 }
346
347 /**
348 * List of currencies supported by paystack
349 *
350 * @since v1.3.1
351 */
352 public function bp_supported_currencies( $method = '' ) {
353 $method = sanitize_text_field( strtolower( $method ) );
354 $supported_currencies = [
355 'paystack' => [
356 'GHS',
357 'KES',
358 'NGN',
359 'USD',
360 'ZAR'
361 ],
362 ];
363
364 return !empty( $supported_currencies[ $method ] ) ? $supported_currencies[ $method ] : [];
365 }
366
367 /**
368 * Get comprehensive currency data
369 *
370 * @since 0.0.2
371 * @return array Array of currency data with codes, names, and symbols
372 */
373 private function get_currency_data() {
374 return [
375 'USD' => ['name' => 'US Dollar', 'symbol' => '$'],
376 'EUR' => ['name' => 'Euro', 'symbol' => ''],
377 'GBP' => ['name' => 'British Pound', 'symbol' => '£'],
378 'AED' => ['name' => 'UAE Dirham', 'symbol' => 'د.إ'],
379 'AUD' => ['name' => 'Australian Dollar', 'symbol' => '$'],
380 'BGN' => ['name' => 'Bulgarian Lev', 'symbol' => 'лв'],
381 'BAM' => ['name' => 'Bosnia and Herzegovina Convertible Mark', 'symbol' => 'KM'],
382 'CAD' => ['name' => 'Canadian Dollar', 'symbol' => '$'],
383 'CHF' => ['name' => 'Swiss Franc', 'symbol' => 'CHF'],
384 'CZK' => ['name' => 'Czech Koruna', 'symbol' => ''],
385 'DKK' => ['name' => 'Danish Krone', 'symbol' => 'kr'],
386 'GHS' => ['name' => 'Ghanaian Cedi', 'symbol' => ''],
387 'HKD' => ['name' => 'Hong Kong Dollar', 'symbol' => '$'],
388 'HUF' => ['name' => 'Hungarian Forint', 'symbol' => 'ft'],
389 'ILS' => ['name' => 'Israeli Shekel', 'symbol' => ''],
390 'JPY' => ['name' => 'Japanese Yen', 'symbol' => '¥'],
391 'KES' => ['name' => 'Kenyan Shilling', 'symbol' => 'Ksh.'],
392 'MXN' => ['name' => 'Mexican Peso', 'symbol' => '$'],
393 'MYR' => ['name' => 'Malaysian Ringgit', 'symbol' => 'MYR'],
394 'NGN' => ['name' => 'Nigerian Naira', 'symbol' => ''],
395 'NOK' => ['name' => 'Norwegian Krone', 'symbol' => 'kr'],
396 'NZD' => ['name' => 'New Zealand Dollar', 'symbol' => '$'],
397 'PHP' => ['name' => 'Philippine Peso', 'symbol' => ''],
398 'PLN' => ['name' => 'Polish Zloty', 'symbol' => ''],
399 'RON' => ['name' => 'Romanian Leu', 'symbol' => 'lei'],
400 'RSD' => ['name' => 'Serbian Dinar', 'symbol' => 'din.'],
401 'RUB' => ['name' => 'Russian Ruble', 'symbol' => ''],
402 'SEK' => ['name' => 'Swedish Krona', 'symbol' => 'kr'],
403 'SGD' => ['name' => 'Singapore Dollar', 'symbol' => '$'],
404 'THB' => ['name' => 'Thai Baht', 'symbol' => '฿'],
405 'TRY' => ['name' => 'Turkish Lira', 'symbol' => ''],
406 'TWD' => ['name' => 'Taiwan Dollar', 'symbol' => '$'],
407 'ZAR' => ['name' => 'South African Rand', 'symbol' => 'R'],
408 ];
409 }
410
411 /**
412 * Get currency symbols list
413 *
414 * @since 0.0.2
415 * @return array Array of currency codes and their symbols
416 */
417 public function get_currency_symbols_list() {
418 $currency_data = $this->get_currency_data();
419 $symbols = [];
420
421 foreach ($currency_data as $code => $data) {
422 $symbols[$code] = $data['symbol'];
423 }
424
425 return $symbols;
426 }
427
428 /**
429 * Get currency list
430 *
431 * @since 0.0.2
432 * @return array Array of currency codes as key-value pairs
433 */
434 public function get_currency_list() {
435 $currency_data = $this->get_currency_data();
436 $currency_list = [];
437
438 foreach ($currency_data as $code => $data) {
439 $currency_list[$code] = $code;
440 }
441
442 return $currency_list;
443 }
444
445 /**
446 * Get currency names list
447 *
448 * @since 0.0.2
449 * @return array Array of currency codes and their full names
450 */
451 public function get_currency_names_list() {
452 $currency_data = $this->get_currency_data();
453 $names = [];
454
455 foreach ($currency_data as $code => $data) {
456 $names[$code] = $data['name'];
457 }
458
459 return $names;
460 }
461
462 /**
463 * Get currency symbol by code
464 *
465 * @since 0.0.2
466 * @param string $currency_code The currency code (e.g., 'USD', 'EUR')
467 * @return string The currency symbol or the code if symbol not found
468 */
469 public function get_currency_symbol($currency_code) {
470 $currency_data = $this->get_currency_data();
471
472 if (isset($currency_data[$currency_code])) {
473 return $currency_data[$currency_code]['symbol'];
474 }
475
476 return $currency_code; // Fallback to currency code
477 }
478
479 /**
480 * Get currency name by code
481 *
482 * @since 0.0.2
483 * @param string $currency_code The currency code (e.g., 'USD', 'EUR')
484 * @return string The currency name or the code if name not found
485 */
486 public function get_currency_name($currency_code) {
487 $currency_data = $this->get_currency_data();
488
489 if (isset($currency_data[$currency_code])) {
490 return $currency_data[$currency_code]['name'];
491 }
492
493 return $currency_code; // Fallback to currency code
494 }
495
496 /**
497 * Widget settings
498 *
499 * @since 1.0.0
500 */
501 public function get_elementor_widget_settings( $page_id, $widget_id ) {
502 $settings = [];
503
504 // First, check for Gutenberg block settings stored in transient.
505 // This is used when the form is rendered via a Gutenberg block.
506 $transient_key = 'bp_block_settings_' . $page_id . '_' . $widget_id;
507 $block_settings = get_transient( $transient_key );
508 if ( ! empty( $block_settings ) && is_array( $block_settings ) ) {
509 return $block_settings;
510 }
511
512 // Fallback to Elementor widget settings.
513 if ( class_exists( '\Elementor\Plugin' ) && ! empty( \Elementor\Plugin::$instance ) ) {
514 $document = \Elementor\Plugin::$instance->documents->get( $page_id );
515 if ( $document ) {
516 $elements = \Elementor\Plugin::instance()->documents->get( $page_id )->get_elements_data();
517 $widget_data = $this->find_element_recursive( $elements, $widget_id );
518 $widget = ! empty( $widget_data ) && is_array( $widget_data ) ? \Elementor\Plugin::instance()->elements_manager->create_element_instance( $widget_data ) : '';
519 if ( ! empty( $widget ) ) {
520 $settings = $widget->get_settings_for_display();
521 }
522 }
523 }
524
525 return $settings;
526 }
527
528 /**
529 * Find element recursive
530 *
531 * @since 1.0.0
532 */
533 public function find_element_recursive( $elements, $form_id ) {
534
535 foreach ( $elements as $element ) {
536 if ( $form_id === $element[ 'id' ] ) {
537 return $element;
538 }
539
540 if ( !empty( $element[ 'elements' ] ) ) {
541 $element = $this->find_element_recursive( $element[ 'elements' ], $form_id );
542
543 if ( $element ) {
544 return $element;
545 }
546 }
547 }
548
549 return false;
550 }
551
552 public function get_stripe_price_details( $price_id = '', $secret_key = '' ) {
553 if ( empty( $price_id ) || empty( $secret_key ) ) {
554 return [];
555 }
556
557 $api_url = 'https://api.stripe.com/v1/prices/' . $price_id;
558
559 $response = wp_remote_get( $api_url, [
560 'headers' => [
561 'Authorization' => 'Bearer ' . $secret_key,
562 ],
563 'timeout' => 20,
564 ] );
565
566 if ( is_wp_error( $response ) ) {
567 error_log( 'Stripe API error: ' . $response->get_error_message() );
568 return [];
569 }
570
571 $body = wp_remote_retrieve_body( $response );
572 $data = json_decode( $body, true );
573 // dd( $data );
574
575 if ( ! isset( $data ) || ! is_array( $data ) ) {
576 error_log( 'Stripe API response format error.' );
577 return [];
578 }
579
580 return $data;
581 }
582
583 /**
584 * Initialize widget usage
585 *
586 * @since 1.0.0
587 */
588 public function bp_init_widget_usage() {
589 // Run initial Elementor widget scan if not done yet
590 if (!get_option('bp_widget_usage_initial_scan_done', false)) {
591 $this->scan_existing_pages_for_widgets();
592 update_option('bp_widget_usage_initial_scan_done', true);
593 }
594
595 // Run initial Gutenberg block scan independently — separate flag so it
596 // still runs on sites where the widget scan already completed.
597 if (!get_option('bp_block_usage_initial_scan_done', false)) {
598 $this->scan_existing_pages_for_blocks();
599 update_option('bp_block_usage_initial_scan_done', true);
600 }
601 }
602
603 /**
604 * Track widget and block usage when a post is saved
605 *
606 * @since 1.0.0
607 * @param int $post_id
608 */
609 public function bp_widget_usage_on_save($post_id) {
610 // add capability check
611 if ( ! current_user_can( 'edit_post', $post_id ) ) {
612 return;
613 }
614
615 // Skip autosaves and revisions
616 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
617 return;
618 }
619
620 if (wp_is_post_revision($post_id)) {
621 return;
622 }
623
624 // Only track pages and posts
625 $post_type = get_post_type($post_id);
626 if (!in_array($post_type, ['page', 'post'])) {
627 return;
628 }
629
630 // Check Elementor widget usage
631 $elementor_data = get_post_meta($post_id, '_elementor_data', true);
632 if (!empty($elementor_data)) {
633 $this->update_widget_usage_flags($post_id, $elementor_data);
634 }
635
636 // Check Gutenberg block usage
637 $post = get_post($post_id);
638 if ($post && has_blocks($post->post_content)) {
639 if ($this->detect_better_payment_blocks(parse_blocks($post->post_content))) {
640 update_option('better_payment_any_block_used', true);
641 }
642 }
643 }
644
645 /**
646 * Scan all existing pages for Better Payment widgets
647 *
648 * @since 1.0.0
649 */
650 public function scan_existing_pages_for_widgets() {
651 global $wpdb;
652
653 // Get all posts/pages with Elementor data
654 $posts_with_elementor = $wpdb->get_results(
655 "SELECT post_id, meta_value FROM {$wpdb->postmeta}
656 WHERE meta_key = '_elementor_data'
657 AND meta_value != ''
658 AND meta_value != '[]'"
659 );
660
661 foreach ($posts_with_elementor as $post_data) {
662 $this->update_widget_usage_flags($post_data->post_id, $post_data->meta_value);
663 }
664 }
665
666 /**
667 * Update widget usage flags based on page content
668 *
669 * @since 1.0.0
670 * @param int $post_id
671 * @param string $elementor_data
672 */
673 public function update_widget_usage_flags($post_id, $elementor_data) {
674 // Parse Elementor data
675 $elements = json_decode($elementor_data, true);
676 if (!is_array($elements)) {
677 return;
678 }
679
680 // Check for Better Payment widgets
681 $widget_usage = $this->detect_better_payment_widgets($elements);
682
683 // Update overall usage flag
684 $any_widget_used = $widget_usage['better-payment'];
685
686 if ($any_widget_used) {
687 update_option('better_payment_any_widget_used', true);
688 } else {
689 delete_option('better_payment_any_widget_used');
690 }
691 }
692
693 /**
694 * Recursively detect Better Payment widgets in Elementor data
695 *
696 * @since 1.0.0
697 * @param array $elements
698 * @return array
699 */
700 public function detect_better_payment_widgets($elements) {
701 $widget_usage = [
702 'better-payment' => false,
703 ];
704
705 foreach ($elements as $element) {
706 // Check if this element is a Better Payment widget
707 if (isset($element['widgetType'])) {
708 $widget_type = $element['widgetType'];
709
710 if ($widget_type === 'better-payment') {
711 $widget_usage['better-payment'] = true;
712 } elseif ($widget_type === 'better-payment-user-dashboard') {
713 $widget_usage['better-payment'] = true;
714 } elseif ($widget_type === 'fundraising-campaign') {
715 $widget_usage['better-payment'] = true;
716 }
717 }
718
719 // Recursively check nested elements
720 if (!empty($element['elements']) && is_array($element['elements'])) {
721 $nested_usage = $this->detect_better_payment_widgets($element['elements']);
722
723 // Merge results (OR operation)
724 $widget_usage['better-payment'] = $widget_usage['better-payment'] || $nested_usage['better-payment'];
725 }
726 }
727
728 return $widget_usage;
729 }
730
731 /**
732 * Check if any Better Payment widget is being used
733 *
734 * @since 1.0.0
735 * @return bool
736 */
737 public function is_any_better_payment_widget_used() {
738 return get_option('better_payment_any_widget_used', false) ? '1' : '0';
739 }
740
741 /**
742 * Scan all existing published posts/pages for Better Payment Gutenberg blocks
743 *
744 * @since 2.0.0
745 */
746 public function scan_existing_pages_for_blocks() {
747 global $wpdb;
748
749 $block_found = $wpdb->get_var(
750 "SELECT ID FROM {$wpdb->posts}
751 WHERE post_status = 'publish'
752 AND post_content LIKE '%<!-- wp:better-payment/%'
753 LIMIT 1"
754 );
755
756 if ( $block_found ) {
757 update_option( 'better_payment_any_block_used', true );
758 }
759 }
760
761 /**
762 * Recursively detect Better Payment blocks in parsed Gutenberg block data
763 *
764 * @since 2.0.0
765 * @param array $blocks Parsed blocks from parse_blocks()
766 * @return bool
767 */
768 public function detect_better_payment_blocks( $blocks ) {
769 dd('ok');
770 $bp_block_names = [ 'better-payment/payment-form', 'better-payment/user-dashboard' ];
771
772 foreach ( $blocks as $block ) {
773 if ( in_array( $block['blockName'], $bp_block_names, true ) ) {
774 return true;
775 }
776
777 // Recursively check inner blocks
778 if ( ! empty( $block['innerBlocks'] ) && is_array( $block['innerBlocks'] ) ) {
779 if ( $this->detect_better_payment_blocks( $block['innerBlocks'] ) ) {
780 return true;
781 }
782 }
783 }
784
785 return false;
786 }
787
788 /**
789 * Check if any Better Payment Gutenberg block is being used
790 *
791 * @since 2.0.0
792 * @return string '1' or '0'
793 */
794 public function is_any_better_payment_block_used() {
795 return get_option( 'better_payment_any_block_used', false ) ? '1' : '0';
796 }
797
798 /**
799 * Check if dismissible section should be shown
800 *
801 * @since 1.4.2
802 * @return bool
803 */
804 public function bp_section_dismissed() {
805 $progress_bar_dismissed = get_option('better_payment_progress_bar_dismissed', false);
806 $plugin_installed_fresh = get_option('better_payment_plugin_installed_fresh', false);
807 $progress_bar_dismissed_expiry_date = get_option('better_payment_progress_bar_dismissed_expiry_date', 0);
808
809 if ($progress_bar_dismissed) {
810 return true;
811 }
812
813 return $plugin_installed_fresh === 'yes' && time() > $progress_bar_dismissed_expiry_date;
814 }
815
816 public function bp_calculate_progress_steps($settings) {
817 $steps = [];
818
819 // Step 1: Check if API keys are configured
820 // Check PayPal keys
821 $paypal_business_email = !empty($settings['better_payment_settings_payment_paypal_email']);
822
823 // Check Stripe keys
824 $is_stripe_live_mode = $settings['better_payment_settings_payment_stripe_live_mode'] === 'yes' ? true : false;
825 if ( $is_stripe_live_mode ) {
826 $stripe_public = !empty($settings['better_payment_settings_payment_stripe_live_public']);
827 $stripe_secret = !empty($settings['better_payment_settings_payment_stripe_live_secret']);
828 } else {
829 $stripe_public = !empty($settings['better_payment_settings_payment_stripe_test_public']);
830 $stripe_secret = !empty($settings['better_payment_settings_payment_stripe_test_secret']);
831 }
832
833 // Check Paystack keys
834 $is_paystack_live_mode = $settings['better_payment_settings_payment_paystack_live_mode'] === 'yes' ? true : false;
835 if ( $is_paystack_live_mode ) {
836 $paystack_public = !empty($settings['better_payment_settings_payment_paystack_live_public']);
837 $paystack_secret = !empty($settings['better_payment_settings_payment_paystack_live_secret']);
838 } else {
839 $paystack_public = !empty($settings['better_payment_settings_payment_paystack_test_public']);
840 $paystack_secret = !empty($settings['better_payment_settings_payment_paystack_test_secret']);
841 }
842
843 $api_keys_configured = ( isset($paypal_business_email) && $paypal_business_email ) || ( isset($stripe_public) && isset($stripe_secret) && $stripe_public && $stripe_secret ) || ( isset($paystack_public) && isset($paystack_secret) && $paystack_public && $paystack_secret );
844 $payment_settings_url = admin_url('admin.php?page=better-payment-admin&tab=settings&id=paypal');
845
846 $steps[] = [
847 'completed' => $api_keys_configured,
848 'text' => sprintf(__('Add your Stripe, PayPal, or Paystack API keys in <a href="%s">Payment Settings</a>', 'better-payment'), $payment_settings_url)
849 ];
850
851 // Step 2: Check if Elementor widget has been added
852 $widget_used = $this->is_any_better_payment_widget_used() === '1' ? true : false;
853 // Step 3: Check if any Better Payment Gutenberg block has been added
854 $block_used = $this->is_any_better_payment_block_used() === '1' ? true : false;
855
856 $steps[] = [
857 'completed' => $widget_used || $block_used,
858 'text' => __('Open your page in', 'better-payment') . ' <a target="_blank" href="//betterpayment.co/docs/how-to-style-payment-form-in-elementor/">' . __('Elementor', 'better-payment') . '</a>' . __( ' or ', 'better-payment' ) . '<a target="_blank" href="//betterpayment.co/docs/configure-payment-form-in-gutenberg/">' . __('Gutenberg', 'better-payment') . '</a>' . __( ' and insert the Better Payment widget/block.', 'better-payment' ),
859 ];
860
861 // Step 4: Check if widget has been customized
862 $widget_customized = $widget_used || $block_used;
863
864 $steps[] = [
865 'completed' => $widget_customized,
866 'text' => __('Customize the settings to fit your needs, then save and publish', 'better-payment')
867 ];
868
869 return $steps;
870 }
871 }
872