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 | square/helpers/FrmSquareLiteConnectHelper.php +38 -24 6.30 → trunk View file →
@@ -71,9 +71,9 @@
71 71 private static function render_settings_for_mode( $mode ) {
72 72 // phpcs:disable Generic.WhiteSpace.ScopeIndent
73 73 ?>
74 74 <div class="frm-card-item frm4">
75 - <div class="frm-flex-col">
75 + <div class="frm-flex-col" style="width: 100%;">
76 76 <div>
77 77 <span style="font-size: var(--text-lg); font-weight: 500; margin-right: 5px;">
78 78 <?php
79 79 echo $mode === 'test' ? esc_html__( 'Test', 'formidable' ) : esc_html__( 'Live', 'formidable' );
@@ -134,9 +134,9 @@
134 134 /**
135 135 * @return false|string
136 136 */
137 137 public static function get_oauth_redirect_url() {
138 - $mode = FrmAppHelper::get_post_param( 'mode', 'test', 'sanitize_text_field' );
138 + $mode = self::get_mode_value_from_post();
139 139
140 140 if ( self::get_merchant_id( $mode ) ) {
141 141 // Do not allow for initialize if there is already a configured account id.
142 142 return false;
@@ -181,12 +181,8 @@
181 181 $body = array_merge( $body, $additional_body );
182 182 $url = self::get_url_to_connect_server();
183 183 $headers = self::build_headers_for_post();
184 184
185 - if ( ! $headers ) {
186 - return 'Unable to build headers for post. Is your pro license configured properly?';
187 - }
188 -
189 185 // (Seconds) default timeout is 5. we want a bit more time to work with.
190 186 $timeout = 45;
191 187
192 188 self::try_to_extend_server_timeout( $timeout );
@@ -554,32 +550,52 @@
554 550 /**
555 551 * @return array
556 552 */
557 553 private static function get_standard_authenticated_body() {
558 - $mode = self::get_mode_value_from_post();
559 - return array(
560 - 'merchant_id' => get_option( self::get_merchant_id_option_name( $mode ) ),
561 - 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ),
562 - 'client_password' => get_option( self::get_client_side_token_option_name( $mode ) ),
563 - );
554 + return self::get_body_for_mode( FrmSquareLiteAppHelper::active_mode() );
564 555 }
565 556
566 557 /**
567 - * 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.
558 + * Check $_POST for live or test mode value as it can be updated in real time from Square Settings and can be configured before the update is saved.
559 + * The connect request sends a 'mode' string, and the disconnect request sends a 'testMode' flag, so check for both.
568 560 *
569 561 * @return string 'test' or 'live'
570 562 */
571 563 private static function get_mode_value_from_post() {
572 564 // phpcs:ignore WordPress.Security.NonceVerification.Missing
573 - if ( empty( $_POST ) || ! array_key_exists( 'testMode', $_POST ) ) {
574 - return FrmSquareLiteAppHelper::active_mode();
565 + if ( array_key_exists( 'mode', $_POST ) ) {
566 + $mode = FrmAppHelper::get_post_param( 'mode', '', 'sanitize_text_field' );
567 + return 'test' === $mode ? 'test' : 'live';
575 568 }
576 569
577 - $test_mode = FrmAppHelper::get_param( 'testMode', '', 'post', 'absint' );
578 - return $test_mode ? 'test' : 'live';
570 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
571 + if ( array_key_exists( 'testMode', $_POST ) ) {
572 + $test_mode = FrmAppHelper::get_post_param( 'testMode', '', 'absint' );
573 + return $test_mode ? 'test' : 'live';
574 + }
575 +
576 + return FrmSquareLiteAppHelper::active_mode();
579 577 }
580 578
581 579 /**
580 + * Get the standard body with account id, mode, and passwords to send to the connect server.
581 + *
582 + * @since 6.32.1
583 + *
584 + * @param string $mode 'live' or 'test'.
585 + *
586 + * @return array
587 + */
588 + private static function get_body_for_mode( $mode ) {
589 + return array(
590 + 'merchant_id' => get_option( self::get_merchant_id_option_name( $mode ) ),
591 + 'server_password' => get_option( self::get_server_side_token_option_name( $mode ) ),
592 + 'client_password' => get_option( self::get_client_side_token_option_name( $mode ) ),
593 + 'frm_square_api_mode' => $mode,
594 + );
595 + }
596 +
597 + /**
582 598 * @return string|null
583 599 */
584 600 public static function get_latest_error_from_square_api() {
585 601 return self::$latest_error_from_square_api;
@@ -621,10 +637,9 @@
621 637
622 638 $request_body = array();
623 639
624 640 if ( 'auto' !== $mode ) {
625 - $_POST['testMode'] = 'test' === $mode ? 1 : 0;
626 - $request_body['frm_square_api_mode'] = $mode;
641 + $request_body = self::get_body_for_mode( $mode );
627 642 }
628 643
629 644 $response = self::post_with_authenticated_body( 'get_location_id', $request_body );
630 645
@@ -710,8 +725,9 @@
710 725
711 726 public static function handle_disconnect() {
712 727 self::disconnect();
713 728 self::reset_square_api_integration();
729 + FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'square', self::get_mode_value_from_post() );
714 730 wp_send_json_success();
715 731 }
716 732
717 733 /**
@@ -717,11 +733,10 @@
717 733 /**
718 734 * @return false|object
719 735 */
720 736 private static function disconnect() {
721 - $additional_body = array(
722 - 'frm_square_api_mode' => self::get_mode_value_from_post(),
723 - );
737 + $mode = self::get_mode_value_from_post();
738 + $additional_body = self::get_body_for_mode( $mode );
724 739 return self::post_with_authenticated_body( 'disconnect', $additional_body );
725 740 }
726 741
727 742 /**
@@ -755,10 +770,9 @@
755 770
756 771 $request_body = array();
757 772
758 773 if ( 'auto' !== $mode ) {
759 - $_POST['testMode'] = 'test' === $mode ? 1 : 0;
760 - $request_body['frm_square_api_mode'] = $mode;
774 + $request_body = self::get_body_for_mode( $mode );
761 775 }
762 776
763 777 $response = self::post_with_authenticated_body( 'get_merchant_currency', $request_body );
764 778