PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | stripe/helpers/FrmStrpLiteConnectHelper.php +74 -91 6.26 → trunk View file →
@@ -33,13 +33,14 @@
33 33 private static function check_for_stripe_connect_ajax_actions() {
34 34 $action = FrmAppHelper::get_param( 'action', '', 'post', 'sanitize_text_field' );
35 35 $prefix = 'frm_stripe_connect_';
36 36
37 - if ( ! $action || 0 !== strpos( $action, $prefix ) ) {
37 + if ( ! $action || ! str_starts_with( $action, $prefix ) ) {
38 38 if ( 'frm_strp_connect_get_settings_button' === $action ) {
39 39 FrmAppHelper::permission_check( 'frm_change_settings' );
40 40 self::render_settings();
41 41 }
42 +
42 43 return;
43 44 }
44 45
45 46 FrmAppHelper::permission_check( 'frm_change_settings' );
@@ -114,13 +115,13 @@
114 115 return $data;
115 116 }
116 117
117 118 if ( ! empty( $data->password ) ) {
118 - update_option( self::get_server_side_token_option_name( $mode ), $data->password, 'no' );
119 + update_option( self::get_server_side_token_option_name( $mode ), $data->password, false );
119 120 }
120 121
121 122 if ( ! empty( $data->account_id ) ) {
122 - update_option( self::get_account_id_option_name( $mode ), $data->account_id, 'no' );
123 + update_option( self::get_account_id_option_name( $mode ), $data->account_id, false );
123 124 }
124 125
125 126 return $data;
126 127 }
@@ -133,9 +134,9 @@
133 134 * @return string the client password.
134 135 */
135 136 private static function generate_client_password( $mode ) {
136 137 $client_password = wp_generate_password();
137 - update_option( self::get_client_side_token_option_name( $mode ), $client_password, 'no' );
138 + update_option( self::get_client_side_token_option_name( $mode ), $client_password, false );
138 139 return $client_password;
139 140 }
140 141
141 142 /**
@@ -152,12 +153,8 @@
152 153 $body = array_merge( $body, $additional_body );
153 154 $url = self::get_url_to_connect_server();
154 155 $headers = self::build_headers_for_post();
155 156
156 - if ( ! $headers ) {
157 - return 'Unable to build headers for post. Is your pro license configured properly?';
158 - }
159 -
160 157 // (Seconds) default timeout is 5. we want a bit more time to work with.
161 158 $timeout = 45;
162 159
163 160 self::try_to_extend_server_timeout( $timeout );
@@ -174,8 +171,9 @@
174 171 if ( empty( $body->success ) ) {
175 172 if ( ! empty( $body->data ) && is_string( $body->data ) ) {
176 173 return $body->data;
177 174 }
175 +
178 176 return 'Response from server was not successful';
179 177 }
180 178
181 179 return $body->data ?? array();
@@ -264,9 +262,9 @@
264 262 */
265 263 private static function handle_disconnect() {
266 264 self::disconnect();
267 265 self::reset_stripe_connect_integration();
268 - self::maybe_unschedule_crons();
266 + FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'stripe', self::get_mode_value_from_post() );
269 267 wp_send_json_success();
270 268 }
271 269
272 270 /**
@@ -285,38 +283,16 @@
285 283 /**
286 284 * @return false|object
287 285 */
288 286 private static function disconnect() {
289 - $additional_body = array(
290 - 'frm_strp_connect_mode' => self::get_mode_value_from_post(),
291 - );
287 + $mode = self::get_mode_value_from_post();
288 + $additional_body = self::get_body_for_mode( $mode );
292 289 return self::post_with_authenticated_body( 'disconnect', $additional_body );
293 290 }
294 291
295 292 /**
296 - * Stop the payment cron once all Stripe connections have been disconnected.
297 - *
298 293 * @since 6.5
299 294 *
300 - * @return void
301 - */
302 - private static function maybe_unschedule_crons() {
303 - if ( self::at_least_one_mode_is_setup() ) {
304 - // Don't unschedule if a mode is still on.
305 - return;
306 - }
307 -
308 - $event = 'frm_payment_cron';
309 - $timestamp = wp_next_scheduled( $event );
310 -
311 - if ( false !== $timestamp ) {
312 - wp_unschedule_event( $timestamp, $event );
313 - }
314 - }
315 -
316 - /**
317 - * @since 6.5
318 - *
319 295 * @return bool
320 296 */
321 297 public static function at_least_one_mode_is_setup() {
322 298 return self::stripe_connect_is_setup( 'test' ) || self::stripe_connect_is_setup( 'live' );
@@ -325,18 +301,18 @@
325 301 /**
326 302 * @return void
327 303 */
328 304 private static function handle_reauth() {
329 - $additional_body = array(
330 - 'frm_strp_connect_mode' => self::get_mode_value_from_post(),
331 - );
305 + $mode = self::get_mode_value_from_post();
306 + $additional_body = self::get_body_for_mode( $mode );
332 307 $data = self::post_with_authenticated_body( 'reauth', $additional_body );
333 308
334 309 if ( false === $data ) {
335 310 // Check account status.
336 - if ( self::check_server_for_connected_account_status() ) {
311 + if ( self::check_server_for_connected_account_status( $mode ) ) {
337 312 wp_send_json_success();
338 313 }
314 +
339 315 wp_send_json_error();
340 316 }
341 317
342 318 $response_data = array(
@@ -348,13 +324,26 @@
348 324 /**
349 325 * @return array
350 326 */
351 327 private static function get_standard_authenticated_body() {
352 - $mode = self::get_mode_value_from_post();
328 + return self::get_body_for_mode( FrmStrpLiteAppHelper::active_mode() );
329 + }
330 +
331 + /**
332 + * Get the standard body with account id, mode, and passwords to send to the connect server.
333 + *
334 + * @since 6.32.1
335 + *
336 + * @param string $mode 'live' or 'test'.
337 + *
338 + * @return array
339 + */
340 + private static function get_body_for_mode( $mode ) {
353 341 return array(
354 - 'account_id' => get_option( self::get_account_id_option_name( $mode ) ),
355 - 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ),
356 - 'client_password' => get_option( self::get_client_side_token_option_name( $mode ) ),
342 + 'account_id' => get_option( self::get_account_id_option_name( $mode ) ),
343 + 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ),
344 + 'client_password' => get_option( self::get_client_side_token_option_name( $mode ) ),
345 + 'frm_strp_connect_mode' => $mode,
357 346 );
358 347 }
359 348
360 349 private static function redirect() {
@@ -391,9 +380,9 @@
391 380 );
392 381 $data = self::post_to_connect_server( 'oauth_account_status', $body );
393 382
394 383 if ( is_object( $data ) && ! empty( $data->account_id ) ) {
395 - update_option( self::get_account_id_option_name( $mode ), $data->account_id, 'no' );
384 + update_option( self::get_account_id_option_name( $mode ), $data->account_id, false );
396 385
397 386 if ( ! empty( $data->details_submitted ) ) {
398 387 self::set_stripe_details_as_submitted( $mode );
399 388 }
@@ -411,9 +400,9 @@
411 400 *
412 401 * @return void
413 402 */
414 403 private static function set_stripe_details_as_submitted( $mode ) {
415 - update_option( self::get_stripe_details_submitted_option_name( $mode ), true, 'no' );
404 + update_option( self::get_stripe_details_submitted_option_name( $mode ), true, false );
416 405 FrmTransLiteAppController::install();
417 406 }
418 407
419 408 /**
@@ -451,9 +440,9 @@
451 440 return false;
452 441 }
453 442
454 443 if ( ! empty( $data->password ) ) {
455 - update_option( self::get_server_side_token_option_name( $mode ), $data->password, 'no' );
444 + update_option( self::get_server_side_token_option_name( $mode ), $data->password, false );
456 445 }
457 446
458 447 if ( ! is_object( $data ) || empty( $data->redirect_url ) ) {
459 448 return false;
@@ -462,20 +451,26 @@
462 451 return $data->redirect_url;
463 452 }
464 453
465 454 /**
455 + * @param string $mode
456 + *
466 457 * @return bool true if our account is onboarded
467 458 */
468 - public static function check_server_for_connected_account_status() {
469 - $mode = FrmAppHelper::get_param( 'mode', '', 'get', 'sanitize_text_field' );
459 + public static function check_server_for_connected_account_status( $mode = 'check_get' ) {
460 + if ( 'check_get' === $mode ) {
461 + $mode = FrmAppHelper::get_param( 'mode', '', 'get', 'sanitize_text_field' );
470 462
471 - if ( 'live' !== $mode ) {
472 - $mode = 'test';
463 + if ( 'live' !== $mode ) {
464 + $mode = 'test';
465 + }
473 466 }
474 467
475 - $additional_body = array(
476 - 'frm_strp_connect_mode' => $mode,
477 - );
468 + if ( self::stripe_connect_is_setup( $mode ) ) {
469 + return false;
470 + }
471 +
472 + $additional_body = self::get_body_for_mode( $mode );
478 473 $data = self::post_with_authenticated_body( 'account_status', $additional_body );
479 474 $success = false !== $data && ! empty( $data->details_submitted );
480 475
481 476 if ( $success ) {
@@ -480,8 +475,9 @@
480 475
481 476 if ( $success ) {
482 477 self::set_stripe_details_as_submitted( $mode );
483 478 }
479 +
484 480 return $success;
485 481 }
486 482
487 483 /**
@@ -561,13 +557,9 @@
561 557 * @return string
562 558 */
563 559 private static function strip_lang_from_url( $url ) {
564 560 $split_on_language = explode( '/?lang=', $url );
565 -
566 - if ( 2 === count( $split_on_language ) ) {
567 - $url = $split_on_language[0];
568 - }
569 - return $url;
561 + return 2 === count( $split_on_language ) ? $split_on_language[0] : $url;
570 562 }
571 563
572 564 /**
573 565 * Get a Pro license when Pro is active.
@@ -582,8 +574,9 @@
582 574 if ( $pro_license ) {
583 575 $password = $pro_license;
584 576 }
585 577 }
578 +
586 579 return ! empty( $password ) ? $password : false;
587 580 }
588 581
589 582 /**
@@ -609,8 +602,9 @@
609 602 * @return void
610 603 */
611 604 public static function render_stripe_connect_settings_container() {
612 605 self::register_settings_scripts();
606 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
613 607 ?>
614 608 <tr>
615 609 <td>
616 610 <?php esc_html_e( 'Connection Status', 'formidable' ); ?>
@@ -619,8 +613,9 @@
619 613 <div id="frm_strp_settings_container"></div>
620 614 </td>
621 615 </tr>
622 616 <?php
617 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
623 618 }
624 619
625 620 /**
626 621 * @return void
@@ -636,10 +631,9 @@
636 631 $title = $test ? __( 'TEST', 'formidable' ) : __( 'LIVE', 'formidable' );
637 632
638 633 ob_start();
639 634 require FrmStrpLiteAppHelper::plugin_path() . '/views/settings/connect.php';
640 - $html .= ob_get_contents();
641 - ob_end_clean();
635 + $html .= ob_get_clean();
642 636 }
643 637
644 638 $response_data = array(
645 639 'html' => $html,
@@ -647,16 +641,16 @@
647 641 wp_send_json_success( $response_data );
648 642 }
649 643
650 644 /**
651 - * @todo I can probably remove this.
652 - *
653 645 * @return void
654 646 */
655 647 public static function stripe_icon() {
648 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
656 649 ?>
657 - <svg height="16" aria-hidden="true" style="vertical-align:text-bottom" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M155.3 154.6c0-22.3 18.6-30.9 48.4-30.9a320 320 0 01141.9 36.7V26.1A376.2 376.2 0 00203.8 0C88.1 0 11 60.4 11 161.4c0 157.9 216.8 132.3 216.8 200.4 0 26.4-22.9 34.9-54.7 34.9-47.2 0-108.2-19.5-156.1-45.5v128.5a396 396 0 00156 32.4c118.6 0 200.3-51 200.3-153.6 0-170.2-218-139.7-218-203.9z"/></svg>
650 + <svg height="16" aria-hidden="true" style="vertical-align:text-bottom" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M155.3 154.6c0-22.3 18.6-30.9 48.4-30.9a320 320 0 01141.9 36.7V26.1A376.2 376.2 0 00203.8 0C88.1 0 11 60.4 11 161.4c0 157.9 216.8 132.3 216.8 200.4 0 26.4-22.9 34.9-54.7 34.9-47.2 0-108.2-19.5-156.1-45.5v128.5a396 396 0 00156 32.4c118.6 0 200.3-51 200.3-153.6 0-170.2-218-139.7-218-203.9z"/></svg><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
658 651 <?php
652 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
659 653 }
660 654
661 655 /**
662 656 * Check $_POST for live or test mode value as it can be updated in real time from Stripe Settings and can be configured before the update is saved.
@@ -676,9 +670,9 @@
676 670 /**
677 671 * @return void
678 672 */
679 673 private static function register_settings_scripts() {
680 - wp_register_script( 'formidable_stripe_settings', FrmStrpLiteAppHelper::plugin_url() . '/js/connect_settings.js', array( 'formidable_dom' ), FrmAppHelper::plugin_version(), true );
674 + wp_register_script( 'formidable_stripe_settings', FrmStrpLiteAppHelper::plugin_url() . '/js/connect_settings.js', array( 'formidable_dom' ), FrmAppHelper::plugin_version(), true ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
681 675 wp_enqueue_script( 'formidable_stripe_settings' );
682 676 }
683 677
684 678 /**
@@ -699,15 +693,12 @@
699 693 $data = self::post_with_authenticated_body( 'get_customer', compact( 'options' ) );
700 694 $success = false !== $data;
701 695
702 696 if ( ! $success ) {
703 - return ! empty( self::$latest_error_from_stripe_connect ) ? self::$latest_error_from_stripe_connect : false;
697 + return self::$latest_error_from_stripe_connect ? self::$latest_error_from_stripe_connect : false;
704 698 }
705 699
706 - if ( empty( $data->customer_id ) ) {
707 - return false;
708 - }
709 - return $data->customer_id;
700 + return ! empty( $data->customer_id ) ? $data->customer_id : false;
710 701 }
711 702
712 703 /**
713 704 * @param string $customer_id
@@ -733,10 +724,10 @@
733 724 return $response;
734 725 }
735 726
736 727 if ( is_array( $response ) ) {
737 - // reformat empty arrays as empty objects
738 - // if the response is an array, it's because it's empty. Everything with data is already an object.
728 + // Reformat empty arrays as empty objects
729 + // If the response is an array, it's because it's empty. Everything with data is already an object.
739 730 return new stdClass();
740 731 }
741 732
742 733 if ( is_string( $response ) ) {
@@ -744,8 +735,9 @@
744 735 FrmTransLiteLog::log_message( 'Stripe Connect Error', $response );
745 736 } else {
746 737 self::$latest_error_from_stripe_connect = '';
747 738 }
739 +
748 740 return false;
749 741 }
750 742
751 743 /**
@@ -756,12 +748,9 @@
756 748 public static function create_intent( $new_charge ) {
757 749 $data = self::post_with_authenticated_body( 'create_intent', compact( 'new_charge' ) );
758 750 $success = false !== $data;
759 751
760 - if ( ! $success ) {
761 - return false;
762 - }
763 - return $data;
752 + return $success ? $data : false;
764 753 }
765 754
766 755 /**
767 756 * @param string $payment_id
@@ -768,11 +757,10 @@
768 757 *
769 758 * @return bool
770 759 */
771 760 public static function refund_payment( $payment_id ) {
772 - $data = self::post_with_authenticated_body( 'refund_payment', compact( 'payment_id' ) );
773 - $refunded = is_object( $data );
774 - return $refunded;
761 + $data = self::post_with_authenticated_body( 'refund_payment', compact( 'payment_id' ) );
762 + return is_object( $data );
775 763 }
776 764
777 765 /**
778 766 * @param array $new_charge
@@ -785,9 +773,9 @@
785 773 if ( is_object( $data ) ) {
786 774 return $data;
787 775 }
788 776
789 - if ( isset( self::$latest_error_from_stripe_connect ) && 0 === strpos( self::$latest_error_from_stripe_connect, 'No such plan: ' ) ) {
777 + if ( isset( self::$latest_error_from_stripe_connect ) && str_starts_with( self::$latest_error_from_stripe_connect, 'No such plan: ' ) ) {
790 778 return self::$latest_error_from_stripe_connect;
791 779 }
792 780
793 781 return false;
@@ -801,10 +789,9 @@
801 789 */
802 790 public static function cancel_subscription( $sub_id, $customer_id = false ) {
803 791 $cancel_at_period_end = FrmStrpLiteSubscriptionHelper::should_cancel_at_period_end();
804 792 $data = self::post_with_authenticated_body( 'cancel_subscription', compact( 'sub_id', 'customer_id', 'cancel_at_period_end' ) );
805 - $canceled = false !== $data;
806 - return $canceled;
793 + return false !== $data;
807 794 }
808 795
809 796 /**
810 797 * @param string $payment_id
@@ -818,18 +805,13 @@
818 805 /**
819 806 * @return false|object
820 807 */
821 808 public static function get_customer_subscriptions() {
822 - $user_id = get_current_user_id();
823 809 $meta_name = FrmStrpLiteAppHelper::get_customer_id_meta_name();
824 - $customer_id = get_user_meta( $user_id, $meta_name, true );
810 + $customer_id = get_user_meta( get_current_user_id(), $meta_name, true );
825 811 $data = self::post_with_authenticated_body( 'get_customer_subscriptions', compact( 'customer_id' ) );
826 812
827 - if ( false === $data ) {
828 - return false;
829 - }
830 -
831 - return $data->subscriptions;
813 + return false === $data ? false : $data->subscriptions;
832 814 }
833 815
834 816 /**
835 817 * @param string $event_id
@@ -872,8 +854,9 @@
872 854
873 855 if ( false === $data || empty( $data->plan_id ) ) {
874 856 return false;
875 857 }
858 +
876 859 return $data->plan_id;
877 860 }
878 861
879 862 /**
@@ -891,11 +874,10 @@
891 874 *
892 875 * @return bool
893 876 */
894 877 public static function update_intent( $intent_id, $data ) {
895 - $data = self::post_with_authenticated_body( 'update_intent', compact( 'intent_id', 'data' ) );
896 - $success = false !== $data;
897 - return $success;
878 + $data = self::post_with_authenticated_body( 'update_intent', compact( 'intent_id', 'data' ) );
879 + return false !== $data;
898 880 }
899 881
900 882 /**
901 883 * @return array
@@ -905,8 +887,9 @@
905 887
906 888 if ( false === $data || empty( $data->event_ids ) ) {
907 889 return array();
908 890 }
891 +
909 892 return $data->event_ids;
910 893 }
911 894
912 895 /**
@@ -959,14 +942,14 @@
959 942 }
960 943
961 944 $site_identifier = FrmAppHelper::get_post_param( 'site_identifier' );
962 945 $usage = new FrmUsage();
963 - $uuid = $usage->uuid();
964 946
965 947 update_option( $option_name, time() );
966 948
967 - if ( $site_identifier === $uuid ) {
949 + if ( $site_identifier === $usage->uuid() ) {
968 950 wp_send_json_success();
969 951 }
952 +
970 953 wp_send_json_error();
971 954 }
972 955 }