PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.2.2
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.2.2
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.2, at includes/Traits/Helper.php

870 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
574 if ( ! isset( $data ) || ! is_array( $data ) ) {
575 error_log( 'Stripe API response format error.' );
576 return [];
577 }
578
579 return $data;
580 }
581
582 /**
583 * Initialize widget usage
584 *
585 * @since 1.0.0
586 */
587 public function bp_init_widget_usage() {
588 // Run initial Elementor widget scan if not done yet
589 if (!get_option('bp_widget_usage_initial_scan_done', false)) {
590 $this->scan_existing_pages_for_widgets();
591 update_option('bp_widget_usage_initial_scan_done', true);
592 }
593
594 // Run initial Gutenberg block scan independently — separate flag so it
595 // still runs on sites where the widget scan already completed.
596 if (!get_option('bp_block_usage_initial_scan_done', false)) {
597 $this->scan_existing_pages_for_blocks();
598 update_option('bp_block_usage_initial_scan_done', true);
599 }
600 }
601
602 /**
603 * Track widget and block usage when a post is saved
604 *
605 * @since 1.0.0
606 * @param int $post_id
607 */
608 public function bp_widget_usage_on_save($post_id) {
609 // add capability check
610 if ( ! current_user_can( 'edit_post', $post_id ) ) {
611 return;
612 }
613
614 // Skip autosaves and revisions
615 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
616 return;
617 }
618
619 if (wp_is_post_revision($post_id)) {
620 return;
621 }
622
623 // Only track pages and posts
624 $post_type = get_post_type($post_id);
625 if (!in_array($post_type, ['page', 'post'])) {
626 return;
627 }
628
629 // Check Elementor widget usage
630 $elementor_data = get_post_meta($post_id, '_elementor_data', true);
631 if (!empty($elementor_data)) {
632 $this->update_widget_usage_flags($post_id, $elementor_data);
633 }
634
635 // Check Gutenberg block usage
636 $post = get_post($post_id);
637 if ($post && has_blocks($post->post_content)) {
638 if ($this->detect_better_payment_blocks(parse_blocks($post->post_content))) {
639 update_option('better_payment_any_block_used', true);
640 }
641 }
642 }
643
644 /**
645 * Scan all existing pages for Better Payment widgets
646 *
647 * @since 1.0.0
648 */
649 public function scan_existing_pages_for_widgets() {
650 global $wpdb;
651
652 // Get all posts/pages with Elementor data
653 $posts_with_elementor = $wpdb->get_results(
654 "SELECT post_id, meta_value FROM {$wpdb->postmeta}
655 WHERE meta_key = '_elementor_data'
656 AND meta_value != ''
657 AND meta_value != '[]'"
658 );
659
660 foreach ($posts_with_elementor as $post_data) {
661 $this->update_widget_usage_flags($post_data->post_id, $post_data->meta_value);
662 }
663 }
664
665 /**
666 * Update widget usage flags based on page content
667 *
668 * @since 1.0.0
669 * @param int $post_id
670 * @param string $elementor_data
671 */
672 public function update_widget_usage_flags($post_id, $elementor_data) {
673 // Parse Elementor data
674 $elements = json_decode($elementor_data, true);
675 if (!is_array($elements)) {
676 return;
677 }
678
679 // Check for Better Payment widgets
680 $widget_usage = $this->detect_better_payment_widgets($elements);
681
682 // Update overall usage flag
683 $any_widget_used = $widget_usage['better-payment'];
684
685 if ($any_widget_used) {
686 update_option('better_payment_any_widget_used', true);
687 } else {
688 delete_option('better_payment_any_widget_used');
689 }
690 }
691
692 /**
693 * Recursively detect Better Payment widgets in Elementor data
694 *
695 * @since 1.0.0
696 * @param array $elements
697 * @return array
698 */
699 public function detect_better_payment_widgets($elements) {
700 $widget_usage = [
701 'better-payment' => false,
702 ];
703
704 foreach ($elements as $element) {
705 // Check if this element is a Better Payment widget
706 if (isset($element['widgetType'])) {
707 $widget_type = $element['widgetType'];
708
709 if ($widget_type === 'better-payment') {
710 $widget_usage['better-payment'] = true;
711 } elseif ($widget_type === 'better-payment-user-dashboard') {
712 $widget_usage['better-payment'] = true;
713 } elseif ($widget_type === 'fundraising-campaign') {
714 $widget_usage['better-payment'] = true;
715 }
716 }
717
718 // Recursively check nested elements
719 if (!empty($element['elements']) && is_array($element['elements'])) {
720 $nested_usage = $this->detect_better_payment_widgets($element['elements']);
721
722 // Merge results (OR operation)
723 $widget_usage['better-payment'] = $widget_usage['better-payment'] || $nested_usage['better-payment'];
724 }
725 }
726
727 return $widget_usage;
728 }
729
730 /**
731 * Check if any Better Payment widget is being used
732 *
733 * @since 1.0.0
734 * @return bool
735 */
736 public function is_any_better_payment_widget_used() {
737 return get_option('better_payment_any_widget_used', false) ? '1' : '0';
738 }
739
740 /**
741 * Scan all existing published posts/pages for Better Payment Gutenberg blocks
742 *
743 * @since 2.0.0
744 */
745 public function scan_existing_pages_for_blocks() {
746 global $wpdb;
747
748 $block_found = $wpdb->get_var(
749 "SELECT ID FROM {$wpdb->posts}
750 WHERE post_status = 'publish'
751 AND post_content LIKE '%<!-- wp:better-payment/%'
752 LIMIT 1"
753 );
754
755 if ( $block_found ) {
756 update_option( 'better_payment_any_block_used', true );
757 }
758 }
759
760 /**
761 * Recursively detect Better Payment blocks in parsed Gutenberg block data
762 *
763 * @since 2.0.0
764 * @param array $blocks Parsed blocks from parse_blocks()
765 * @return bool
766 */
767 public function detect_better_payment_blocks( $blocks ) {
768 $bp_block_names = [ 'better-payment/payment-form', 'better-payment/user-dashboard' ];
769
770 foreach ( $blocks as $block ) {
771 if ( in_array( $block['blockName'], $bp_block_names, true ) ) {
772 return true;
773 }
774
775 // Recursively check inner blocks
776 if ( ! empty( $block['innerBlocks'] ) && is_array( $block['innerBlocks'] ) ) {
777 if ( $this->detect_better_payment_blocks( $block['innerBlocks'] ) ) {
778 return true;
779 }
780 }
781 }
782
783 return false;
784 }
785
786 /**
787 * Check if any Better Payment Gutenberg block is being used
788 *
789 * @since 2.0.0
790 * @return string '1' or '0'
791 */
792 public function is_any_better_payment_block_used() {
793 return get_option( 'better_payment_any_block_used', false ) ? '1' : '0';
794 }
795
796 /**
797 * Check if dismissible section should be shown
798 *
799 * @since 1.4.2
800 * @return bool
801 */
802 public function bp_section_dismissed() {
803 $progress_bar_dismissed = get_option('better_payment_progress_bar_dismissed', false);
804 $plugin_installed_fresh = get_option('better_payment_plugin_installed_fresh', false);
805 $progress_bar_dismissed_expiry_date = get_option('better_payment_progress_bar_dismissed_expiry_date', 0);
806
807 if ($progress_bar_dismissed) {
808 return true;
809 }
810
811 return $plugin_installed_fresh === 'yes' && time() > $progress_bar_dismissed_expiry_date;
812 }
813
814 public function bp_calculate_progress_steps($settings) {
815 $steps = [];
816
817 // Step 1: Check if API keys are configured
818 // Check PayPal keys
819 $paypal_business_email = !empty($settings['better_payment_settings_payment_paypal_email']);
820
821 // Check Stripe keys
822 $is_stripe_live_mode = $settings['better_payment_settings_payment_stripe_live_mode'] === 'yes' ? true : false;
823 if ( $is_stripe_live_mode ) {
824 $stripe_public = !empty($settings['better_payment_settings_payment_stripe_live_public']);
825 $stripe_secret = !empty($settings['better_payment_settings_payment_stripe_live_secret']);
826 } else {
827 $stripe_public = !empty($settings['better_payment_settings_payment_stripe_test_public']);
828 $stripe_secret = !empty($settings['better_payment_settings_payment_stripe_test_secret']);
829 }
830
831 // Check Paystack keys
832 $is_paystack_live_mode = $settings['better_payment_settings_payment_paystack_live_mode'] === 'yes' ? true : false;
833 if ( $is_paystack_live_mode ) {
834 $paystack_public = !empty($settings['better_payment_settings_payment_paystack_live_public']);
835 $paystack_secret = !empty($settings['better_payment_settings_payment_paystack_live_secret']);
836 } else {
837 $paystack_public = !empty($settings['better_payment_settings_payment_paystack_test_public']);
838 $paystack_secret = !empty($settings['better_payment_settings_payment_paystack_test_secret']);
839 }
840
841 $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 );
842 $payment_settings_url = admin_url('admin.php?page=better-payment-admin&tab=settings&id=paypal');
843
844 $steps[] = [
845 'completed' => $api_keys_configured,
846 'text' => sprintf(__('Add your Stripe, PayPal, or Paystack API keys in <a href="%s">Payment Settings</a>', 'better-payment'), $payment_settings_url)
847 ];
848
849 // Step 2: Check if Elementor widget has been added
850 $widget_used = $this->is_any_better_payment_widget_used() === '1' ? true : false;
851 // Step 3: Check if any Better Payment Gutenberg block has been added
852 $block_used = $this->is_any_better_payment_block_used() === '1' ? true : false;
853
854 $steps[] = [
855 'completed' => $widget_used || $block_used,
856 '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' ),
857 ];
858
859 // Step 4: Check if widget has been customized
860 $widget_customized = $widget_used || $block_used;
861
862 $steps[] = [
863 'completed' => $widget_customized,
864 'text' => __('Customize the settings to fit your needs, then save and publish', 'better-payment')
865 ];
866
867 return $steps;
868 }
869 }
870