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 +53 -64 6.27 → trunk View file →
@@ -115,13 +115,13 @@
115 115 return $data;
116 116 }
117 117
118 118 if ( ! empty( $data->password ) ) {
119 - 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 );
120 120 }
121 121
122 122 if ( ! empty( $data->account_id ) ) {
123 - 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 );
124 124 }
125 125
126 126 return $data;
127 127 }
@@ -134,9 +134,9 @@
134 134 * @return string the client password.
135 135 */
136 136 private static function generate_client_password( $mode ) {
137 137 $client_password = wp_generate_password();
138 - 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 );
139 139 return $client_password;
140 140 }
141 141
142 142 /**
@@ -153,12 +153,8 @@
153 153 $body = array_merge( $body, $additional_body );
154 154 $url = self::get_url_to_connect_server();
155 155 $headers = self::build_headers_for_post();
156 156
157 - if ( ! $headers ) {
158 - return 'Unable to build headers for post. Is your pro license configured properly?';
159 - }
160 -
161 157 // (Seconds) default timeout is 5. we want a bit more time to work with.
162 158 $timeout = 45;
163 159
164 160 self::try_to_extend_server_timeout( $timeout );
@@ -266,9 +262,9 @@
266 262 */
267 263 private static function handle_disconnect() {
268 264 self::disconnect();
269 265 self::reset_stripe_connect_integration();
270 - self::maybe_unschedule_crons();
266 + FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'stripe', self::get_mode_value_from_post() );
271 267 wp_send_json_success();
272 268 }
273 269
274 270 /**
@@ -287,38 +283,16 @@
287 283 /**
288 284 * @return false|object
289 285 */
290 286 private static function disconnect() {
291 - $additional_body = array(
292 - 'frm_strp_connect_mode' => self::get_mode_value_from_post(),
293 - );
287 + $mode = self::get_mode_value_from_post();
288 + $additional_body = self::get_body_for_mode( $mode );
294 289 return self::post_with_authenticated_body( 'disconnect', $additional_body );
295 290 }
296 291
297 292 /**
298 - * Stop the payment cron once all Stripe connections have been disconnected.
299 - *
300 293 * @since 6.5
301 294 *
302 - * @return void
303 - */
304 - private static function maybe_unschedule_crons() {
305 - if ( self::at_least_one_mode_is_setup() ) {
306 - // Don't unschedule if a mode is still on.
307 - return;
308 - }
309 -
310 - $event = 'frm_payment_cron';
311 - $timestamp = wp_next_scheduled( $event );
312 -
313 - if ( false !== $timestamp ) {
314 - wp_unschedule_event( $timestamp, $event );
315 - }
316 - }
317 -
318 - /**
319 - * @since 6.5
320 - *
321 295 * @return bool
322 296 */
323 297 public static function at_least_one_mode_is_setup() {
324 298 return self::stripe_connect_is_setup( 'test' ) || self::stripe_connect_is_setup( 'live' );
@@ -327,16 +301,15 @@
327 301 /**
328 302 * @return void
329 303 */
330 304 private static function handle_reauth() {
331 - $additional_body = array(
332 - 'frm_strp_connect_mode' => self::get_mode_value_from_post(),
333 - );
305 + $mode = self::get_mode_value_from_post();
306 + $additional_body = self::get_body_for_mode( $mode );
334 307 $data = self::post_with_authenticated_body( 'reauth', $additional_body );
335 308
336 309 if ( false === $data ) {
337 310 // Check account status.
338 - if ( self::check_server_for_connected_account_status() ) {
311 + if ( self::check_server_for_connected_account_status( $mode ) ) {
339 312 wp_send_json_success();
340 313 }
341 314
342 315 wp_send_json_error();
@@ -351,13 +324,26 @@
351 324 /**
352 325 * @return array
353 326 */
354 327 private static function get_standard_authenticated_body() {
355 - $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 ) {
356 341 return array(
357 - 'account_id' => get_option( self::get_account_id_option_name( $mode ) ),
358 - 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ),
359 - '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,
360 346 );
361 347 }
362 348
363 349 private static function redirect() {
@@ -394,9 +380,9 @@
394 380 );
395 381 $data = self::post_to_connect_server( 'oauth_account_status', $body );
396 382
397 383 if ( is_object( $data ) && ! empty( $data->account_id ) ) {
398 - 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 );
399 385
400 386 if ( ! empty( $data->details_submitted ) ) {
401 387 self::set_stripe_details_as_submitted( $mode );
402 388 }
@@ -414,9 +400,9 @@
414 400 *
415 401 * @return void
416 402 */
417 403 private static function set_stripe_details_as_submitted( $mode ) {
418 - 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 );
419 405 FrmTransLiteAppController::install();
420 406 }
421 407
422 408 /**
@@ -454,9 +440,9 @@
454 440 return false;
455 441 }
456 442
457 443 if ( ! empty( $data->password ) ) {
458 - 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 );
459 445 }
460 446
461 447 if ( ! is_object( $data ) || empty( $data->redirect_url ) ) {
462 448 return false;
@@ -465,20 +451,26 @@
465 451 return $data->redirect_url;
466 452 }
467 453
468 454 /**
455 + * @param string $mode
456 + *
469 457 * @return bool true if our account is onboarded
470 458 */
471 - public static function check_server_for_connected_account_status() {
472 - $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' );
473 462
474 - if ( 'live' !== $mode ) {
475 - $mode = 'test';
463 + if ( 'live' !== $mode ) {
464 + $mode = 'test';
465 + }
476 466 }
477 467
478 - $additional_body = array(
479 - 'frm_strp_connect_mode' => $mode,
480 - );
468 + if ( self::stripe_connect_is_setup( $mode ) ) {
469 + return false;
470 + }
471 +
472 + $additional_body = self::get_body_for_mode( $mode );
481 473 $data = self::post_with_authenticated_body( 'account_status', $additional_body );
482 474 $success = false !== $data && ! empty( $data->details_submitted );
483 475
484 476 if ( $success ) {
@@ -565,14 +557,9 @@
565 557 * @return string
566 558 */
567 559 private static function strip_lang_from_url( $url ) {
568 560 $split_on_language = explode( '/?lang=', $url );
569 -
570 - if ( 2 === count( $split_on_language ) ) {
571 - $url = $split_on_language[0];
572 - }
573 -
574 - return $url;
561 + return 2 === count( $split_on_language ) ? $split_on_language[0] : $url;
575 562 }
576 563
577 564 /**
578 565 * Get a Pro license when Pro is active.
@@ -615,8 +602,9 @@
615 602 * @return void
616 603 */
617 604 public static function render_stripe_connect_settings_container() {
618 605 self::register_settings_scripts();
606 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
619 607 ?>
620 608 <tr>
621 609 <td>
622 610 <?php esc_html_e( 'Connection Status', 'formidable' ); ?>
@@ -625,8 +613,9 @@
625 613 <div id="frm_strp_settings_container"></div>
626 614 </td>
627 615 </tr>
628 616 <?php
617 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
629 618 }
630 619
631 620 /**
632 621 * @return void
@@ -655,11 +644,13 @@
655 644 /**
656 645 * @return void
657 646 */
658 647 public static function stripe_icon() {
648 + // phpcs:disable Generic.WhiteSpace.ScopeIndent
659 649 ?>
660 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 ?>
661 651 <?php
652 + // phpcs:enable Generic.WhiteSpace.ScopeIndent
662 653 }
663 654
664 655 /**
665 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.
@@ -702,12 +693,12 @@
702 693 $data = self::post_with_authenticated_body( 'get_customer', compact( 'options' ) );
703 694 $success = false !== $data;
704 695
705 696 if ( ! $success ) {
706 - 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;
707 698 }
708 699
709 - return empty( $data->customer_id ) ? false : $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 ) ) {
@@ -814,11 +805,10 @@
814 805 /**
815 806 * @return false|object
816 807 */
817 808 public static function get_customer_subscriptions() {
818 - $user_id = get_current_user_id();
819 809 $meta_name = FrmStrpLiteAppHelper::get_customer_id_meta_name();
820 - $customer_id = get_user_meta( $user_id, $meta_name, true );
810 + $customer_id = get_user_meta( get_current_user_id(), $meta_name, true );
821 811 $data = self::post_with_authenticated_body( 'get_customer_subscriptions', compact( 'customer_id' ) );
822 812
823 813 return false === $data ? false : $data->subscriptions;
824 814 }
@@ -952,13 +942,12 @@
952 942 }
953 943
954 944 $site_identifier = FrmAppHelper::get_post_param( 'site_identifier' );
955 945 $usage = new FrmUsage();
956 - $uuid = $usage->uuid();
957 946
958 947 update_option( $option_name, time() );
959 948
960 - if ( $site_identifier === $uuid ) {
949 + if ( $site_identifier === $usage->uuid() ) {
961 950 wp_send_json_success();
962 951 }
963 952
964 953 wp_send_json_error();